use of org.openstack4j.model.compute.Keypair in project camel by apache.
the class KeypairProducer method doCreate.
private void doCreate(Exchange exchange) {
final Message msg = exchange.getIn();
final String name = msg.getHeader(OpenstackConstants.NAME, String.class);
ObjectHelper.notEmpty(name, "Keypair name");
final String body = msg.getBody(String.class);
final Keypair kp = os.compute().keypairs().create(name, body);
msg.setBody(kp);
}
use of org.openstack4j.model.compute.Keypair in project camel by apache.
the class KeypairProducer method doGet.
private void doGet(Exchange exchange) {
final Message msg = exchange.getIn();
final String keypairName = msg.getHeader(OpenstackConstants.NAME, String.class);
ObjectHelper.notEmpty(keypairName, "Keypair name");
final Keypair kp = os.compute().keypairs().get(keypairName);
msg.setBody(kp);
}
use of org.openstack4j.model.compute.Keypair in project camel by apache.
the class KeypairProducerTest method createKeypair.
@Test
public void createKeypair() throws Exception {
final String fingerPrint = "fp";
final String privatecKey = "prk";
when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME);
when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
when(osTestKeypair.getFingerprint()).thenReturn(fingerPrint);
when(osTestKeypair.getPrivateKey()).thenReturn(privatecKey);
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
producer.process(exchange);
ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
assertNull(keypairCaptor.getValue());
Keypair result = msg.getBody(Keypair.class);
assertEquals(fingerPrint, result.getFingerprint());
assertEquals(privatecKey, result.getPrivateKey());
assertEquals(dummyKeypair.getName(), result.getName());
assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey());
}
use of org.openstack4j.model.compute.Keypair in project camel by apache.
the class KeypairProducerTest method createKeypairFromExisting.
@Test
public void createKeypairFromExisting() throws Exception {
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
String key = "existing public key string";
when(osTestKeypair.getPublicKey()).thenReturn(key);
msg.setBody(key);
producer.process(exchange);
ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
assertEquals(key, keypairCaptor.getValue());
Keypair result = msg.getBody(Keypair.class);
assertEquals(dummyKeypair.getName(), result.getName());
assertEquals(dummyKeypair.getFingerprint(), result.getFingerprint());
assertEquals(dummyKeypair.getPrivateKey(), result.getPrivateKey());
assertEquals(key, result.getPublicKey());
}
use of org.openstack4j.model.compute.Keypair in project wildfly-camel by wildfly-extras.
the class OpenstackIntegrationTest method testNovaKeypair.
@Test
public void testNovaKeypair() throws Exception {
when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME);
when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
when(osTestKeypair.getFingerprint()).thenReturn("fp");
when(osTestKeypair.getPrivateKey()).thenReturn("prk");
CamelContext camelContext = Mockito.mock(CamelContext.class);
when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());
Message msg = new DefaultMessage(camelContext);
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);
Exchange exchange = Mockito.mock(Exchange.class);
when(exchange.getIn()).thenReturn(msg);
NovaEndpoint endpoint = Mockito.mock(NovaEndpoint.class);
Producer producer = new KeypairProducer(endpoint, client);
producer.process(exchange);
ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());
assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
assertNull(keypairCaptor.getValue());
Keypair result = msg.getBody(Keypair.class);
assertEquals("fp", result.getFingerprint());
assertEquals("prk", result.getPrivateKey());
assertEquals(dummyKeypair.getName(), result.getName());
assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey());
}
Aggregations