PageRenderTime 5162ms CodeModel.GetById 104ms RepoModel.GetById 8ms app.codeStats 0ms

/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java

https://github.com/jraghu/jclouds
Java | 54 lines | 24 code | 7 blank | 23 comment | 2 complexity | f4446a5be8b3a3a14af2dc12509947b7 MD5 | raw file
  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. import static org.testng.Assert.assertEquals;
  21. import java.net.UnknownHostException;
  22. import java.util.Map;
  23. import org.jclouds.net.IPSocket;
  24. import org.jclouds.ssh.SshClient;
  25. import org.jclouds.ssh.jsch.JschSshClient;
  26. import org.testng.annotations.Test;
  27. import com.google.inject.Guice;
  28. import com.google.inject.Injector;
  29. /**
  30. * Tests the ability to configure a {@link JschSshClient}
  31. *
  32. * @author Adrian Cole
  33. */
  34. @Test
  35. public class JschSshClientModuleTest {
  36. public void testConfigureBindsClient() throws UnknownHostException {
  37. Injector i = Guice.createInjector(new JschSshClientModule());
  38. SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
  39. SshClient connection = factory.create(new IPSocket("localhost", 22), "username", "password");
  40. assert connection instanceof JschSshClient;
  41. Map<String, String> keyPair = factory.generateRSAKeyPair("comment", "hola");
  42. assertEquals(keyPair.get("comment"), "comment");
  43. assertEquals(keyPair.get("passphrase"), "hola");
  44. assert keyPair.get("private").indexOf("-----BEGIN RSA PRIVATE KEY-----") == 0 : keyPair;
  45. assert keyPair.get("public").indexOf("ssh-rsa ") == 0 : keyPair;
  46. }
  47. }