X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fit%2FNetconfITSecureTest.java;h=4dc4b707d4708253579e8135ddd1b6c1e95af1c9;hb=87e068952fe9207ccccbcebdaac2de09743e2403;hp=44d8420ba471f6f1a36bfbb966e7b3466ce58ffe;hpb=99d2c8a0e2a8ea4a819ee31d658be6e01dfcd1df;p=controller.git diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java index 44d8420ba4..4dc4b707d4 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java @@ -34,7 +34,10 @@ import org.opendaylight.controller.config.manager.impl.factoriesresolver.Hardcod import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; -import org.opendaylight.controller.netconf.client.NetconfSshClientDispatcher; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; @@ -50,9 +53,11 @@ import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.controller.sal.authorization.AuthResultEnum; import org.opendaylight.controller.usermanager.IUserManager; +import org.opendaylight.protocol.framework.NeverReconnectStrategy; import ch.ethz.ssh2.Connection; import io.netty.channel.ChannelFuture; +import io.netty.util.concurrent.GlobalEventExecutor; public class NetconfITSecureTest extends AbstractNetconfConfigTest { @@ -60,7 +65,6 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 12023); private DefaultCommitNotificationProducer commitNot; - private NetconfServerDispatcher dispatchS; private NetconfSSHServer sshServer; private NetconfMessage getConfig; @@ -77,7 +81,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer()); - dispatchS = createDispatcher(factoriesListener); + final NetconfServerDispatcher dispatchS = createDispatcher(factoriesListener); ChannelFuture s = dispatchS.createServer(tcpAddress); s.await(); @@ -108,14 +112,34 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { @Test public void testSecure() throws Exception { - NetconfClientDispatcher dispatch = new NetconfSshClientDispatcher(getAuthHandler(), nettyThreadgroup, nettyThreadgroup, 5000); - try (TestingNetconfClient netconfClient = new TestingNetconfClient("tls-client", tlsAddress, 4000, dispatch)) { + NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); + try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration())) { NetconfMessage response = netconfClient.sendMessage(getConfig); Assert.assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), NetconfMessageUtil.isErrorMessage(response)); + + NetconfMessage gs = new NetconfMessage(XmlUtil.readXmlToDocument("\n" + + " \n" + + " config\n" + + " \n" + + "\n")); + + response = netconfClient.sendMessage(gs); + Assert.assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), + NetconfMessageUtil.isErrorMessage(response)); } + } - dispatch.close(); + public NetconfClientConfiguration getClientConfiguration() throws IOException { + final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create(); + b.withAddress(tlsAddress); + b.withSessionListener(new SimpleNetconfClientSessionListener()); + b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)); + b.withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH); + b.withConnectionTimeoutMillis(5000); + b.withAuthHandler(getAuthHandler()); + return b.build(); } public AuthProvider getAuthProvider() throws Exception { @@ -138,6 +162,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest { return null; } }).when(authHandler).authenticate(any(Connection.class)); + doReturn("auth handler").when(authHandler).toString(); return authHandler; } }