@Test public void testLoad() throws UnknownHostException { final CloudStackApi client = createMock(CloudStackApi.class); SSHKeyPairApi keyClient = createMock(SSHKeyPairApi.class); SshKeyPair pair = createMock(SshKeyPair.class); expect(client.getSSHKeyPairApi()).andReturn(keyClient); expect(keyClient.createSSHKeyPair("group-1")).andReturn(pair); replay(client, keyClient); CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(new TypeLiteral<Supplier<String>>() { }).toInstance(Suppliers.ofInstance("1")); bind(CloudStackApi.class).toInstance(client); } }).getInstance(CreateUniqueKeyPair.class); assertEquals(parser.load("group-1"), pair); verify(client, keyClient); }
@Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
CreateUniqueKeyPair extends CacheLoader<String, SshKeyPair> { @Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; } }
CreateUniqueKeyPair extends CacheLoader<String, SshKeyPair> { @Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; } @Inject  CreateUniqueKeyPair(CloudStackApi client); }
CreateUniqueKeyPair extends CacheLoader<String, SshKeyPair> { @Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; } @Inject  CreateUniqueKeyPair(CloudStackApi client); @Override SshKeyPair load(String input); }
CreateUniqueKeyPair extends CacheLoader<String, SshKeyPair> { @Override public SshKeyPair load(String input) { SshKeyPair keyPair = null; while (keyPair == null) { try { keyPair = client.getSSHKeyPairApi().createSSHKeyPair(input); logger.debug(">> creating SSH key pair with name %s", input); } catch (IllegalStateException e) { logger.error(e, "<< error creating SSH key pair with name %s: ", Throwables.getRootCause(e).getMessage()); throw Throwables.propagate(e); } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; } @Inject  CreateUniqueKeyPair(CloudStackApi client); @Override SshKeyPair load(String input);  }