- introduced netconf ssh wrapper bundle
[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 junit.framework.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19
20 public class SSHServerTest {
21
22     private static final String USER = "netconf";
23     private static final String PASSWORD  = "netconf";
24     private static final String HOST = "127.0.0.1";
25     private static final int PORT = 830;
26     private static final Logger logger =  LoggerFactory.getLogger(SSHServerTest.class);
27
28     private class TestSSHServer implements Runnable {
29         public void run()  {
30             try {
31                 NetconfSSHServer.start();
32             } catch (Exception e) {
33                 logger.info(e.getMessage());
34             }
35         }
36      }
37     @Before
38     public void startSSHServer() throws Exception{
39             logger.info("Creating SSH server");
40             Thread sshServerThread = new Thread(new TestSSHServer());
41             sshServerThread.setDaemon(true);
42             sshServerThread.start();
43             logger.info("SSH server on");
44     }
45
46     @Test
47     public void connect(){
48         Connection conn = new Connection(HOST,PORT);
49         Assert.assertNotNull(conn);
50         try {
51             logger.info("connecting to SSH server");
52             conn.connect();
53             logger.info("authenticating ...");
54             boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
55             Assert.assertTrue(isAuthenticated);
56             logger.info("opening session");
57             Session sess = conn.openSession();
58             logger.info("subsystem netconf");
59             sess.startSubSystem("netconf");
60 //            sess.requestPTY("");
61         } catch (IOException e) {
62             e.printStackTrace();
63         }
64     }
65
66 }