use of org.apache.camel.component.openstack.nova.producer.KeypairProducer in project camel by apache.
the class KeypairProducerTest method setUp.
@Before
public void setUp() {
producer = new KeypairProducer(endpoint, client);
dummyKeypair = createDummyKeypair();
when(keypairService.get(Matchers.anyString())).thenReturn(osTestKeypair);
when(keypairService.create(Matchers.anyString(), Matchers.anyString())).thenReturn(osTestKeypair);
List<org.openstack4j.model.compute.Keypair> getAllList = new ArrayList<>();
getAllList.add(osTestKeypair);
getAllList.add(osTestKeypair);
doReturn(getAllList).when(keypairService).list();
when(osTestKeypair.getName()).thenReturn(dummyKeypair.getName());
when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
}
use of org.apache.camel.component.openstack.nova.producer.KeypairProducer 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