BGPCEP-758: Use random ip for Pcc mock tests
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / PCCMockTest.java
index 1c4093cb24cbd8d8f75c13f3ca6acd33e24c0843..02884424199f3e8ac3cbf0a685a095a976e2c6d3 100644 (file)
@@ -9,19 +9,19 @@
 package org.opendaylight.protocol.pcep.pcc.mock;
 
 import io.netty.channel.Channel;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.net.InetSocketAddress;
 import java.util.Collections;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.PCEPCapability;
-import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
 import org.opendaylight.protocol.util.InetSocketAddressUtil;
 
 public final class PCCMockTest extends PCCMockCommon {
-    private final String[] mainInput = new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
-        InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
+    private final String localAddress2 = "127.0.0.2";
+    private final String localIpAddress = "127.0.0.1";
+    private final String[] mainInput = new String[]{"--local-address", localIpAddress,
+        "--remote-address", InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1",
+        "--lsp", "3", "--log-level", "DEBUG", "-ka", "10", "-d", "40", "--reconnect", "-1",
         "--redelegation-timeout", "0", "--state-timeout", "-1"};
 
     @Test
@@ -32,14 +32,14 @@ public final class PCCMockTest extends PCCMockCommon {
         Thread.sleep(1000);
         //3 reported LSPs + syc
         final int numMessages = 4;
-        final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
+        final TestingSessionListener sessionListener = checkSessionListener(numMessages, channel, factory,
+                this.localIpAddress);
         checkSession(sessionListener.getSession(), 40, 10);
     }
 
 
     @Test
     public void testMockPCCToManyPCE() throws Exception {
-        final String localAddress2 = "127.0.0.2";
         final InetSocketAddress serverAddress2 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final InetSocketAddress serverAddress3 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
         final InetSocketAddress serverAddress4 = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
@@ -51,33 +51,21 @@ public final class PCCMockTest extends PCCMockCommon {
         final Channel channel2 = createServer(factory2, serverAddress3);
         final Channel channel3 = createServer(factory3, serverAddress4);
 
-        Main.main(new String[] {"--local-address", this.localAddress.getHostString(), "--remote-address",
-                InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + "," +
-                InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + "," +
-                InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(),
-            "--pcc", "2"});
+        Main.main(new String[]{"--local-address", this.localIpAddress, "--remote-address",
+                InetSocketAddressUtil.toHostAndPort(serverAddress2).toString() + ","
+                        + InetSocketAddressUtil.toHostAndPort(serverAddress3).toString() + ","
+                        + InetSocketAddressUtil.toHostAndPort(serverAddress4).toString(), "--pcc", "2"});
         Thread.sleep(1000);
         //PCE1
         final int numMessages = 2;
-        checkSessionListener(numMessages, channel, factory, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel, factory, localAddress2);
+        checkSessionListener(numMessages, channel, factory, this.localIpAddress);
+        checkSessionListener(numMessages, channel, factory, this.localAddress2);
         //PCE2
-        checkSessionListener(numMessages, channel2, factory2, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel2, factory2, localAddress2);
+        checkSessionListener(numMessages, channel2, factory2, this.localIpAddress);
+        checkSessionListener(numMessages, channel2, factory2, this.localAddress2);
         //PCE3
-        checkSessionListener(numMessages, channel3, factory3, this.localAddress.getHostString());
-        checkSessionListener(numMessages, channel3, factory3, localAddress2);
-    }
-
-    @Test(expected = UnsupportedOperationException.class)
-    public void testPrivateConstructor() throws Throwable {
-        final Constructor<MsgBuilderUtil> c = MsgBuilderUtil.class.getDeclaredConstructor();
-        c.setAccessible(true);
-        try {
-            c.newInstance();
-        } catch (final InvocationTargetException e) {
-            throw e.getCause();
-        }
+        checkSessionListener(numMessages, channel3, factory3, this.localIpAddress);
+        checkSessionListener(numMessages, channel3, factory3, this.localAddress2);
     }
 
     @Override