Search in sources :

Example 1 with KeypairProducer

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());
}
Also used : Keypair(org.openstack4j.model.compute.Keypair) NovaKeypair(org.openstack4j.openstack.compute.domain.NovaKeypair) ArrayList(java.util.ArrayList) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Before(org.junit.Before)

Example 2 with KeypairProducer

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());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultMessage(org.apache.camel.impl.DefaultMessage) Exchange(org.apache.camel.Exchange) NovaEndpoint(org.apache.camel.component.openstack.nova.NovaEndpoint) NovaKeypair(org.openstack4j.openstack.compute.domain.NovaKeypair) Keypair(org.openstack4j.model.compute.Keypair) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) VolumeProducer(org.apache.camel.component.openstack.cinder.producer.VolumeProducer) ProjectProducer(org.apache.camel.component.openstack.keystone.producer.ProjectProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) GlanceProducer(org.apache.camel.component.openstack.glance.GlanceProducer) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Producer(org.apache.camel.Producer) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) DefaultHeadersMapFactory(org.apache.camel.impl.DefaultHeadersMapFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Test(org.junit.Test)

Aggregations

KeypairProducer (org.apache.camel.component.openstack.nova.producer.KeypairProducer)2 Keypair (org.openstack4j.model.compute.Keypair)2 NovaKeypair (org.openstack4j.openstack.compute.domain.NovaKeypair)2 ArrayList (java.util.ArrayList)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 Producer (org.apache.camel.Producer)1 VolumeProducer (org.apache.camel.component.openstack.cinder.producer.VolumeProducer)1 GlanceProducer (org.apache.camel.component.openstack.glance.GlanceProducer)1 ProjectProducer (org.apache.camel.component.openstack.keystone.producer.ProjectProducer)1 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)1 NovaEndpoint (org.apache.camel.component.openstack.nova.NovaEndpoint)1 ContainerProducer (org.apache.camel.component.openstack.swift.producer.ContainerProducer)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultHeadersMapFactory (org.apache.camel.impl.DefaultHeadersMapFactory)1 DefaultMessage (org.apache.camel.impl.DefaultMessage)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1