-/*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowjava.protocol.impl.core.connection;\r
-\r
-import java.net.InetAddress;\r
-import java.net.UnknownHostException;\r
-import java.util.concurrent.ExecutionException;\r
-import java.util.concurrent.TimeUnit;\r
-import java.util.concurrent.TimeoutException;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.mockito.Mock;\r
-import org.mockito.MockitoAnnotations;\r
-import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;\r
-import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;\r
-import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;\r
-import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;\r
-import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;\r
-\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class SwitchConnectionProviderImplTest {\r
-\r
- @Mock SwitchConnectionHandler handler;\r
-\r
- private static final int SWITCH_IDLE_TIMEOUT = 2000;\r
- private static final int WAIT_TIMEOUT = 2000;\r
- private InetAddress startupAddress;\r
- private TlsConfiguration tlsConfiguration;\r
- private SwitchConnectionProviderImpl provider;\r
- private ConnectionConfigurationImpl config;\r
-\r
- /**\r
- * Creates new {@link SwitchConnectionProvider} instance for each test\r
- * @param protocol communication protocol\r
- */\r
- public void startUp(TransportProtocol protocol) {\r
- MockitoAnnotations.initMocks(this);\r
- config = null;\r
- if (protocol != null) {\r
- createConfig(protocol);\r
- }\r
- provider = new SwitchConnectionProviderImpl();\r
- }\r
-\r
- private void createConfig(TransportProtocol protocol) {\r
- try {\r
- startupAddress = InetAddress.getLocalHost();\r
- } catch (UnknownHostException e) {\r
- e.printStackTrace();\r
- }\r
- tlsConfiguration = null;\r
- if (protocol.equals(TransportProtocol.TLS)) {\r
- tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,\r
- "/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,\r
- "/selfSignedController", PathType.CLASSPATH) ;\r
- }\r
- config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT);\r
- config.setTransferProtocol(protocol);\r
- }\r
-\r
- /**\r
- * Tests provider startup - without configuration and {@link SwitchConnectionHandler}\r
- */\r
- @Test\r
- public void testStartup1() {\r
- provider = new SwitchConnectionProviderImpl();\r
- ListenableFuture<Boolean> future = provider.startup();\r
- try {\r
- future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.assertEquals("Wrong state", "java.lang.NullPointerException", e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Tests provider startup - without configuration\r
- */\r
- @Test\r
- public void testStartup2() {\r
- startUp(null);\r
- provider.setSwitchConnectionHandler(handler);\r
- ListenableFuture<Boolean> future = provider.startup();\r
- try {\r
- future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.assertEquals("Wrong state", "java.lang.NullPointerException", e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Tests provider startup - without {@link SwitchConnectionHandler}\r
- */\r
- @Test\r
- public void testStartup3() {\r
- startUp(TransportProtocol.TCP);\r
- provider.setConfiguration(config);\r
- ListenableFuture<Boolean> future = provider.startup();\r
- try {\r
- future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.assertEquals("Wrong state", "java.lang.IllegalStateException:"\r
- + " SwitchConnectionHandler is not set", e.getMessage());\r
- }\r
- }\r
-\r
- /**\r
- * Tests correct provider startup - over TCP\r
- */\r
- @Test\r
- public void testStartup4() {\r
- startUp(TransportProtocol.TCP);\r
- provider.setConfiguration(config);\r
- provider.setSwitchConnectionHandler(handler);\r
- try {\r
- Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.fail();\r
- }\r
- }\r
-\r
- /**\r
- * Tests correct provider startup - over TLS\r
- */\r
- @Test\r
- public void testStartup5() {\r
- startUp(TransportProtocol.TLS);\r
- provider.setConfiguration(config);\r
- provider.setSwitchConnectionHandler(handler);\r
- try {\r
- Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.fail();\r
- }\r
- }\r
-\r
- /**\r
- * Tests correct provider startup - over UDP\r
- */\r
- @Test\r
- public void testStartup6() {\r
- startUp(TransportProtocol.UDP);\r
- provider.setConfiguration(config);\r
- provider.setSwitchConnectionHandler(handler);\r
- try {\r
- Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- Assert.fail();\r
- }\r
- }\r
-\r
- /**\r
- * Tests correct provider shutdown\r
- */\r
- @Test\r
- public void testShutdown() {\r
- startUp(TransportProtocol.TCP);\r
- provider.setConfiguration(config);\r
- provider.setSwitchConnectionHandler(handler);\r
- try {\r
- Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));\r
- Assert.assertTrue("Failed to stop", provider.shutdown().get(5 * WAIT_TIMEOUT, TimeUnit.MILLISECONDS));\r
- } catch (InterruptedException | ExecutionException | TimeoutException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.core.connection;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
+import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
+import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;
+import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl;
+import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+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 com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class SwitchConnectionProviderImplTest {
+
+ @Mock SwitchConnectionHandler handler;
+
+ private static final int SWITCH_IDLE_TIMEOUT = 2000;
+ private static final int WAIT_TIMEOUT = 2000;
+ private InetAddress startupAddress;
+ private TlsConfiguration tlsConfiguration;
+ private SwitchConnectionProviderImpl provider;
+ private ConnectionConfigurationImpl config;
+
+ /**
+ * Creates new {@link SwitchConnectionProvider} instance for each test
+ * @param protocol communication protocol
+ */
+ public void startUp(TransportProtocol protocol) {
+ MockitoAnnotations.initMocks(this);
+ config = null;
+ if (protocol != null) {
+ createConfig(protocol);
+ }
+ provider = new SwitchConnectionProviderImpl();
+ }
+
+ private void createConfig(TransportProtocol protocol) {
+ try {
+ startupAddress = InetAddress.getLocalHost();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ tlsConfiguration = null;
+ if (protocol.equals(TransportProtocol.TLS)) {
+ tlsConfiguration = new TlsConfigurationImpl(KeystoreType.JKS,
+ "/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,
+ "/selfSignedController", PathType.CLASSPATH) ;
+ }
+ config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT);
+ config.setTransferProtocol(protocol);
+ }
+
+ /**
+ * Tests provider startup - without configuration and {@link SwitchConnectionHandler}
+ */
+ @Test
+ public void testStartup1() {
+ provider = new SwitchConnectionProviderImpl();
+ ListenableFuture<Boolean> future = provider.startup();
+ try {
+ future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.assertEquals("Wrong state", "java.lang.NullPointerException", e.getMessage());
+ }
+ }
+
+ /**
+ * Tests provider startup - without configuration
+ */
+ @Test
+ public void testStartup2() {
+ startUp(null);
+ provider.setSwitchConnectionHandler(handler);
+ ListenableFuture<Boolean> future = provider.startup();
+ try {
+ future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.assertEquals("Wrong state", "java.lang.NullPointerException", e.getMessage());
+ }
+ }
+
+ /**
+ * Tests provider startup - without {@link SwitchConnectionHandler}
+ */
+ @Test
+ public void testStartup3() {
+ startUp(TransportProtocol.TCP);
+ provider.setConfiguration(config);
+ ListenableFuture<Boolean> future = provider.startup();
+ try {
+ future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.assertEquals("Wrong state", "java.lang.IllegalStateException:"
+ + " SwitchConnectionHandler is not set", e.getMessage());
+ }
+ }
+
+ /**
+ * Tests correct provider startup - over TCP
+ */
+ @Test
+ public void testStartup4() {
+ startUp(TransportProtocol.TCP);
+ provider.setConfiguration(config);
+ provider.setSwitchConnectionHandler(handler);
+ try {
+ Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.fail();
+ }
+ }
+
+ /**
+ * Tests correct provider startup - over TLS
+ */
+ @Test
+ public void testStartup5() {
+ startUp(TransportProtocol.TLS);
+ provider.setConfiguration(config);
+ provider.setSwitchConnectionHandler(handler);
+ try {
+ Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.fail();
+ }
+ }
+
+ /**
+ * Tests correct provider startup - over UDP
+ */
+ @Test
+ public void testStartup6() {
+ startUp(TransportProtocol.UDP);
+ provider.setConfiguration(config);
+ provider.setSwitchConnectionHandler(handler);
+ try {
+ Assert.assertTrue("Failed to start", provider.startup().get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS));
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ Assert.fail();
+ }
+ }
+
+ /**
+ * Tests correct provider shutdown
+ */
+ @Test
+ public void testShutdown() {
+ startUp(TransportProtocol.TCP);
+ provider.setConfiguration(config);
+ 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();
+ }
+ }
+