Merge "MD-SAL StatisticsManager- Stopping statistics thread until i fix all the relev...
[controller.git] / opendaylight / netconf / netconf-ssh / src / test / java / org / opendaylight / controller / netconf / ssh / SSHServerTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.netconf.ssh;
9
10 import ch.ethz.ssh2.Connection;
11 import ch.ethz.ssh2.Session;
12 import java.io.IOException;
13 import java.net.InetSocketAddress;
14 import junit.framework.Assert;
15 import org.apache.commons.io.IOUtils;
16 import org.junit.Test;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20
21 public class SSHServerTest {
22
23     private static final String USER = "netconf";
24     private static final String PASSWORD  = "netconf";
25     private static final String HOST = "127.0.0.1";
26     private static final int PORT = 1830;
27     private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
28     private static final Logger logger =  LoggerFactory.getLogger(SSHServerTest.class);
29
30 //    @Before
31     public void startSSHServer() throws Exception{
32             logger.info("Creating SSH server");
33             NetconfSSHServer server = NetconfSSHServer.start(PORT,tcpAddress);
34             Thread sshServerThread = new Thread(server);
35             sshServerThread.setDaemon(true);
36             sshServerThread.start();
37             logger.info("SSH server on");
38     }
39
40     @Test
41     public void connect(){
42         Connection conn = new Connection(HOST,PORT);
43         Assert.assertNotNull(conn);
44         try {
45             logger.info("connecting to SSH server");
46             conn.connect();
47             logger.info("authenticating ...");
48             boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
49             Assert.assertTrue(isAuthenticated);
50             logger.info("opening session");
51             Session sess = conn.openSession();
52             logger.info("subsystem netconf");
53             sess.startSubSystem("netconf");
54             sess.getStdin().write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><capabilities><capability>urn:ietf:params:netconf:base:1.1</capability></capabilities></hello>]]>]]>".getBytes());
55             IOUtils.copy(sess.getStdout(), System.out);
56         } catch (IOException e) {
57             e.printStackTrace();
58         }
59     }
60
61 }