Merge "OPNFLWPLUG-1062 Include additional LLDP fields in liblldp"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / connection / SwitchConnectionProviderImplTest.java
index 7a8add5072e8c44ea7652760784fe3d0347ad9be..ca6bc3e50e329d44deb95132c17a5fa176d969a7 100644 (file)
@@ -19,6 +19,7 @@ import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.opendaylight.openflowjava.protocol.api.connection.OpenflowDiagStatusProvider;
 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
 import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;
@@ -27,41 +28,42 @@ import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionPro
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
+import org.slf4j.LoggerFactory;
 
 /**
- * @author michal.polkorab
+ * Unit tests for SwitchConnectionProviderImpl.
  *
+ * @author michal.polkorab
  */
 public class SwitchConnectionProviderImplTest {
 
     @Mock SwitchConnectionHandler handler;
+    @Mock OpenflowDiagStatusProvider openflowPluginDiagStatusProvider;
 
     private static final int SWITCH_IDLE_TIMEOUT = 2000;
     private static final int WAIT_TIMEOUT = 2000;
-    private InetAddress startupAddress;
+    private static final int CHANNEL_OUTBOUND_QUEUE_SIZE = 1024;
     private TlsConfiguration tlsConfiguration;
     private SwitchConnectionProviderImpl provider;
     private ConnectionConfigurationImpl config;
 
     /**
-     * Creates new {@link SwitchConnectionProvider} instance for each test
+     * Creates new {@link SwitchConnectionProvider} instance for each test.
      * @param protocol communication protocol
      */
-    public void startUp(final TransportProtocol protocol) {
+
+    public void startUp(final TransportProtocol protocol) throws UnknownHostException {
         MockitoAnnotations.initMocks(this);
         config = null;
         if (protocol != null) {
             createConfig(protocol);
         }
-        provider = new SwitchConnectionProviderImpl(config);
+        provider = new SwitchConnectionProviderImpl(config, openflowPluginDiagStatusProvider);
     }
 
-    private void createConfig(final TransportProtocol protocol) {
-        try {
-            startupAddress = InetAddress.getLocalHost();
-        } catch (final UnknownHostException e) {
-            e.printStackTrace();
-        }
+    private void createConfig(final TransportProtocol protocol) throws UnknownHostException {
+        InetAddress startupAddress = InetAddress.getLocalHost();
+
         tlsConfiguration = null;
         if (protocol.equals(TransportProtocol.TLS)) {
             tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,
@@ -69,16 +71,17 @@ public class SwitchConnectionProviderImplTest {
                     "/selfSignedController", PathType.CLASSPATH,
                     Lists.newArrayList("TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA256")) ;
         }
-        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
+        config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true,
+                false, CHANNEL_OUTBOUND_QUEUE_SIZE);
         config.setTransferProtocol(protocol);
     }
 
     /**
-     * Tests provider startup - without configuration and {@link SwitchConnectionHandler}
+     * Tests provider startup - without configuration and {@link SwitchConnectionHandler}.
      */
     @Test
-    public void testStartup1() {
-        provider = new SwitchConnectionProviderImpl(config);
+    public void testStartup1() throws UnknownHostException {
+        startUp(null);
         final ListenableFuture<Boolean> future = provider.startup();
         try {
             future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
@@ -88,10 +91,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests provider startup - without configuration
+     * Tests provider startup - without configuration.
      */
     @Test
-    public void testStartup2() {
+    public void testStartup2() throws UnknownHostException {
         startUp(null);
         provider.setSwitchConnectionHandler(handler);
         final ListenableFuture<Boolean> future = provider.startup();
@@ -103,10 +106,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests provider startup - without {@link SwitchConnectionHandler}
+     * Tests provider startup - without {@link SwitchConnectionHandler}.
      */
     @Test
-    public void testStartup3() {
+    public void testStartup3() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         final ListenableFuture<Boolean> future = provider.startup();
         try {
@@ -118,10 +121,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over TCP
+     * Tests correct provider startup - over TCP.
      */
     @Test
-    public void testStartup4() {
+    public void testStartup4() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -132,10 +135,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over TLS
+     * Tests correct provider startup - over TLS.
      */
     @Test
-    public void testStartup5() {
+    public void testStartup5() throws UnknownHostException {
         startUp(TransportProtocol.TLS);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -146,10 +149,10 @@ public class SwitchConnectionProviderImplTest {
     }
 
     /**
-     * Tests correct provider startup - over UDP
+     * Tests correct provider startup - over UDP.
      */
     @Test
-    public void testStartup6() {
+    public void testStartup6() throws UnknownHostException {
         startUp(TransportProtocol.UDP);
         provider.setSwitchConnectionHandler(handler);
         try {
@@ -157,21 +160,21 @@ public class SwitchConnectionProviderImplTest {
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             Assert.fail();
         }
-        }
+    }
 
     /**
-     * Tests correct provider shutdown
+     * Tests correct provider shutdown.
      */
     @Test
-    public void testShutdown() {
+    public void testShutdown() throws UnknownHostException {
         startUp(TransportProtocol.TCP);
         provider.setSwitchConnectionHandler(handler);
         try {
             Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
             Assert.assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
-            e.printStackTrace();
+            LoggerFactory.getLogger(SwitchConnectionProviderImplTest.class).error("Unexpected error", e);
         }
     }
 
-}
\ No newline at end of file
+}