Java Code Examples for org.apache.camel.Producer#process()

The following examples show how to use org.apache.camel.Producer#process() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createSwiftContainer() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    when(containerService.create(anyString(), nullable(CreateUpdateContainerOptions.class))).thenReturn(actionResponse);
    when(actionResponse.isSuccess()).thenReturn(true);

    SwiftEndpoint endpoint = Mockito.mock(SwiftEndpoint.class);
    Producer producer = new ContainerProducer(endpoint, client);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);

    producer.process(exchange);

    ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class);

    verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture());
    assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
    assertNull(optionsCaptor.getValue());
}
 
Example 2
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createNeutronNetwork() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName());
    msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType());
    msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId());

    NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class);
    Producer producer = new NetworkProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class);
    verify(networkService).create(captor.capture());

    assertEqualsNetwork(dummyNetwork, captor.getValue());
    assertNotNull(msg.getBody(Network.class).getId());
}
 
Example 3
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createKeystoneProject() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyProject.getName());
    msg.setHeader(KeystoneConstants.DESCRIPTION, dummyProject.getDescription());
    msg.setHeader(KeystoneConstants.DOMAIN_ID, dummyProject.getDomainId());
    msg.setHeader(KeystoneConstants.PARENT_ID, dummyProject.getParentId());

    KeystoneEndpoint endpoint = Mockito.mock(KeystoneEndpoint.class);
    Producer producer = new ProjectProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Project> captor = ArgumentCaptor.forClass(Project.class);
    verify(projectService).create(captor.capture());

    assertEqualsProject(dummyProject, captor.getValue());
}
 
Example 4
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void reserveGlanceImage() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    GlanceEndpoint endpoint = Mockito.mock(GlanceEndpoint.class);
    when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);

    Message msg = new DefaultMessage(camelContext);
    msg.setBody(dummyImage);

    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    Producer producer = new GlanceProducer(endpoint, client);
    producer.process(exchange);
    ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class);
    verify(imageService).reserve(captor.capture());
    assertEquals(dummyImage, captor.getValue());

    Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
 
Example 5
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createCinderVolume() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    CinderEndpoint endpoint = Mockito.mock(CinderEndpoint.class);
    when(endpoint.getOperation()).thenReturn(OpenstackConstants.CREATE);
    msg.setBody(dummyVolume);

    Producer producer = new VolumeProducer(endpoint, client);
    producer.process(exchange);
    assertEqualVolumes(dummyVolume, msg.getBody(Volume.class));
}
 
Example 6
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@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");

    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.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());
}
 
Example 7
Source File: QuickfixIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Test
 public void sendMessage() throws Exception {

     final CountDownLatch logonLatch = new CountDownLatch(2);
     final CountDownLatch receivedMessageLatch = new CountDownLatch(1);

     CamelContext camelctx = new DefaultCamelContext();
     camelctx.addRoutes(new RouteBuilder() {
         @Override
         public void configure() throws Exception {
             // Release latch when session logon events are received
             // We expect two events, one for the trader session and one for the market session
             from("quickfix:quickfix/inprocess.cfg").
                 filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
                 bean(new CountDownLatchDecrementer("logon", logonLatch));

             // For all received messages, print the JSON-formatted message to stdout
             from("quickfix:quickfix/inprocess.cfg").
                 filter(PredicateBuilder.or(
                         header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived),
                         header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).
                 bean(new QuickfixjMessageJsonPrinter());

             // If the market session receives an email then release the latch
             from("quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
                 filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).
                 bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
         }
     });

     camelctx.start();
     try {
         Assert.assertTrue("Logon succeed", logonLatch.await(5L, TimeUnit.SECONDS));

         String marketUri = "quickfix:quickfix/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
         Endpoint endpoint = camelctx.getEndpoint(marketUri);
Producer producer = endpoint.createProducer();

         Email email = createEmailMessage("Example");
         Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly);
         exchange.getIn().setBody(email);
         producer.process(exchange);

         Assert.assertTrue("Message reached market", receivedMessageLatch.await(5L, TimeUnit.SECONDS));
     } finally {
         camelctx.close();
     }
 }