X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fit%2FNetconfITTest.java;h=e5b9fa3ffcd63404d6ec25264da45fcef7da581a;hp=4526cafe26a281024aec21a8a2a818861d2581ad;hb=25ba6b145406b98f8521bcf510bb85bf0167ef72;hpb=d82b96055d2c0d471c85c2b2b3cb30e52fff1c69 diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java index 4526cafe26..e5b9fa3ffc 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java @@ -77,12 +77,12 @@ import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.xml.sax.SAXException; +import static java.util.Collections.emptyList; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.internal.util.Checks.checkNotNull; public class NetconfITTest extends AbstractConfigTest { @@ -90,7 +90,7 @@ public class NetconfITTest extends AbstractConfigTest { // private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 12023); - private static final InetSocketAddress sshAddress = new InetSocketAddress("127.0.0.1", 830); + private static final InetSocketAddress sshAddress = new InetSocketAddress("127.0.0.1", 10830); private static final String USERNAME = "netconf"; private static final String PASSWORD = "netconf"; @@ -166,10 +166,16 @@ public class NetconfITTest extends AbstractConfigTest { "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", "/META-INF/yang/ietf-inet-types.yang"); final Collection yangDependencies = new ArrayList<>(); + List failedToFind = new ArrayList<>(); for (String path : paths) { - final InputStream is = checkNotNull(NetconfITTest.class.getResourceAsStream(path), path + " not found"); - yangDependencies.add(is); + InputStream resourceAsStream = NetconfITTest.class.getResourceAsStream(path); + if (resourceAsStream == null) { + failedToFind.add(path); + } else { + yangDependencies.add(resourceAsStream); + } } + assertEquals("Some yang files were not found",emptyList(), failedToFind); return yangDependencies; } @@ -453,18 +459,9 @@ public class NetconfITTest extends AbstractConfigTest { return netconfClient; } - private class TestSSHServer implements Runnable { - public void run() { - try { - NetconfSSHServer.start(); - } catch (Exception e) { - logger.info(e.getMessage()); - } - } - } private void startSSHServer() throws Exception{ logger.info("Creating SSH server"); - Thread sshServerThread = new Thread(new TestSSHServer()); + Thread sshServerThread = new Thread(NetconfSSHServer.start(10830,tcpAddress)); sshServerThread.setDaemon(true); sshServerThread.start(); logger.info("SSH server on"); @@ -473,18 +470,34 @@ public class NetconfITTest extends AbstractConfigTest { @Test public void sshTest() throws Exception { startSSHServer(); + logger.info("creating connection"); Connection conn = new Connection(sshAddress.getHostName(),sshAddress.getPort()); Assert.assertNotNull(conn); - try { - conn.connect(); - boolean isAuthenticated = conn.authenticateWithPassword(USERNAME,PASSWORD); - assertTrue(isAuthenticated); - Session sess = conn.openSession(); - sess.startSubSystem("netconf"); -// sess.requestPTY(""); - } catch (IOException e) { - e.printStackTrace(); - } + logger.info("connection created"); + conn.connect(); + boolean isAuthenticated = conn.authenticateWithPassword(USERNAME,PASSWORD); + assertTrue(isAuthenticated); + logger.info("user authenticated"); + final Session sess = conn.openSession(); + sess.startSubSystem("netconf"); + logger.info("user authenticated"); + sess.getStdin().write(XmlUtil.toString(this.getConfig.getDocument()).getBytes()); + + new Thread(){ + public void run(){ + while (true){ + byte[] bytes = new byte[1024]; + int c = 0; + try { + c = sess.getStdout().read(bytes); + } catch (IOException e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + logger.info("got data:"+bytes); + if (c == 0) break; + } + } + }.join(); }