Statistics
| Branch: | Revision:

root / extensions / ssh / jsch / src / test / java / org / jclouds / ssh / jsch / config / JschSshClientModuleTest.java @ 35e7942d

History | View | Annotate | Download (2 kB)

1
/**
2
 *
3
 * Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
4
 *
5
 * ====================================================================
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 * ====================================================================
18
 */
19
package org.jclouds.ssh.jsch.config;
20

    
21
import java.net.InetAddress;
22
import java.net.InetSocketAddress;
23
import java.net.UnknownHostException;
24
import java.util.Map;
25

    
26
import org.jclouds.ssh.SshClient;
27
import org.jclouds.ssh.jsch.JschSshClient;
28
import org.testng.annotations.Test;
29

    
30
import com.google.inject.Guice;
31
import com.google.inject.Injector;
32
import static org.testng.Assert.assertEquals;
33

    
34
/**
35
 * Tests the ability to configure a {@link JschSshClient}
36
 * 
37
 * @author Adrian Cole
38
 */
39
@Test
40
public class JschSshClientModuleTest {
41

    
42
   public void testConfigureBindsClient() throws UnknownHostException {
43

    
44
      Injector i = Guice.createInjector(new JschSshClientModule());
45
      SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
46
      SshClient connection = factory.create(new InetSocketAddress(InetAddress.getLocalHost(), 22),
47
               "username", "password");
48
      assert connection instanceof JschSshClient;
49
      Map<String, String> keyPair = factory.generateRSAKeyPair("comment", "hola");
50
      assertEquals(keyPair.get("comment"), "comment");
51
      assertEquals(keyPair.get("passphrase"), "hola");
52
      assert keyPair.get("private").indexOf("-----BEGIN RSA PRIVATE KEY-----") == 0 : keyPair;
53
      assert keyPair.get("public").indexOf("ssh-rsa ") == 0 : keyPair;
54
   }
55
}