org.apache.camel.component.mock.MockEndpoint Java Examples

The following examples show how to use org.apache.camel.component.mock.MockEndpoint. 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: SplitterStopOnExceptionABCTest.java    From camelinaction with Apache License 2.0 7 votes vote down vote up
@Test
public void testSplitStopOnException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    // we expect 1 messages to be split since the 2nd message should fail
    split.expectedBodiesReceived("Camel rocks");

    // and no combined aggregated message since we stop on exception
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);

    // now send a message with an unknown letter (F) which forces an exception to occur
    try {
        template.sendBody("direct:start", "A,F,C");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
        assertEquals("Key not a known word F", iae.getMessage());
    }

    assertMockEndpointsSatisfied();
}
 
Example #2
Source File: SplitExceptionHandlingStopOnExceptionSpringTest.java    From camel-cookbook-examples with Apache License 2.0 7 votes vote down vote up
@Test
public void testNoElementsProcessedAfterException() throws Exception {
    String[] array = new String[]{"one", "two", "three"};

    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.expectedMessageCount(1);
    mockSplit.expectedBodiesReceived("one");

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(0);

    try {
        template.sendBody("direct:in", array);
        fail("Exception not thrown");
    } catch (CamelExecutionException ex) {
        assertTrue(ex.getCause() instanceof CamelExchangeException);
        log.info(ex.getMessage());
        assertMockEndpointsSatisfied();
    }
}
 
Example #3
Source File: SplitterStopOnExceptionABCTest.java    From camelinaction2 with Apache License 2.0 7 votes vote down vote up
@Test
public void testSplitStopOnException() throws Exception {
    MockEndpoint split = getMockEndpoint("mock:split");
    // we expect 1 messages to be split since the 2nd message should fail
    split.expectedBodiesReceived("Camel rocks");

    // and no combined aggregated message since we stop on exception
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(0);

    // now send a message with an unknown letter (F) which forces an exception to occur
    try {
        template.sendBody("direct:start", "A,F,C");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
        IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
        assertEquals("Key not a known word F", iae.getMessage());
    }

    assertMockEndpointsSatisfied();
}
 
Example #4
Source File: DatabaseTransactionTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactedExceptionThrown() throws InterruptedException {
    String message = "this message will explode";
    assertEquals(0, auditLogDao.getAuditCount(message));

    MockEndpoint mockCompleted = getMockEndpoint("mock:out");
    mockCompleted.setExpectedMessageCount(1);
    mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor());

    try {
        template.sendBody("direct:transacted", message);
        fail();
    } catch (CamelExecutionException cee) {
        assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage());
    }

    assertMockEndpointsSatisfied();
    assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
}
 
Example #5
Source File: RollbackMarkRollbackOnlySpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactedRollback() throws InterruptedException {
    AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
    String message = "this message will explode";
    assertEquals(0, auditLogDao.getAuditCount(message));

    // the message does not proceed further down the route after the rollback statement
    MockEndpoint mockCompleted = getMockEndpoint("mock:out");
    mockCompleted.setExpectedMessageCount(0);

    // no exception is thrown despite the transaction rolling back
    template.sendBody("direct:transacted", message);

    assertMockEndpointsSatisfied();
    assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
}
 
Example #6
Source File: SpringRouteScopeTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderActiveMQ() throws Exception {
    // we expect the file to be converted to csv and routed to the 2nd route
    MockEndpoint file = getMockEndpoint("mock:file");
    file.expectedMessageCount(1);

    // we do not expect the 2nd route to complete
    MockEndpoint mock = getMockEndpoint("mock:queue.order");
    mock.expectedMessageCount(0);

    template.sendBodyAndHeader("file://target/orders", "amount=1#name=ActiveMQ in Action", Exchange.FILE_NAME, "order.txt");

    // wait 10 seconds to let this test run
    Thread.sleep(10000);

    assertMockEndpointsSatisfied();
}
 
Example #7
Source File: SplitParallelProcessingTimeoutTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSplittingInParallel() throws InterruptedException {
    List<String> messageFragments = new ArrayList<String>();
    int fragmentCount = 50;
    for (int i = 0; i < fragmentCount; i++) {
        messageFragments.add("fragment" + i);
    }

    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.setExpectedMessageCount(fragmentCount - 1);

    ArrayList<String> expectedFragments = new ArrayList<String>(messageFragments);
    int indexDelayed = 20;
    expectedFragments.remove(indexDelayed);
    mockSplit.expectedBodiesReceivedInAnyOrder(expectedFragments);

    MockEndpoint mockDelayed = getMockEndpoint("mock:delayed");
    mockDelayed.setExpectedMessageCount(1);

    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(1);


    template.sendBody("direct:in", messageFragments);
    assertMockEndpointsSatisfied();
}
 
Example #8
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndSlashOnServiceUri() throws Exception {
    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                            .property(SERVICE_URI, defaultTestServer.servicePlainUri() + FORWARD_SLASH));

    Step odataStep = createODataStep(odataConnector, defaultTestServer.resourcePath());
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);

    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(defaultTestServer.getResultCount());

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, TEST_SERVER_DATA_1);
    testResult(result, 1, TEST_SERVER_DATA_2);
    testResult(result, 2, TEST_SERVER_DATA_3);

    Olingo4Endpoint olingo4Endpoint = context.getEndpoint(OLINGO4_READ_FROM_ENDPOINT, Olingo4Endpoint.class);
    assertNotNull(olingo4Endpoint);
    String endpointServiceURI = olingo4Endpoint.getConfiguration().getServiceUri();
    assertEquals(defaultTestServer.servicePlainUri(), endpointServiceURI);
}
 
Example #9
Source File: ReuseErrorHandlerTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderOk() throws Exception {
    // we do not expect any errors and therefore no messages in the dead letter queue
    getMockEndpoint("mock:dead").expectedMessageCount(0);

    // we expect the file to be converted to csv and routed to the 2nd route
    MockEndpoint file = getMockEndpoint("mock:file");
    file.expectedMessageCount(1);

    // we expect the 2nd route to complete
    MockEndpoint mock = getMockEndpoint("mock:queue.order");
    mock.expectedBodiesReceived("amount=1,name=Camel in Action,id=123,status=OK");

    template.sendBodyAndHeader("file://target/orders", "amount=1#name=Camel in Action", Exchange.FILE_NAME, "order.txt");

    assertMockEndpointsSatisfied();
}
 
Example #10
Source File: ODataReadRouteSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testReferenceODataRouteKeyPredicate() throws Exception {
    String resourcePath = "Airports";
    String keyPredicate = "KLAX";

    context = new SpringCamelContext(applicationContext);

    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, REF_SERVICE_URI)
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, resourcePath);
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();
    testResult(result, 0, REF_SERVER_AIRPORT_DATA_KLAX);
}
 
Example #11
Source File: PurchaseOrderCsvTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
   public void testCsv() throws Exception {
       MockEndpoint mock = getMockEndpoint("mock:queue.csv");
       mock.expectedMessageCount(2);

       assertMockEndpointsSatisfied();

       List line1 = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
       assertEquals("Camel in Action", line1.get(0));
       assertEquals("4995", line1.get(1));
       assertEquals("1", line1.get(2));

       List line2 = mock.getReceivedExchanges().get(1).getIn().getBody(List.class);
       assertEquals("Activemq in Action", line2.get(0));
       assertEquals("4495", line2.get(1));
       assertEquals("2", line2.get(2));
   }
 
Example #12
Source File: FilterTest.java    From funktion-connectors with Apache License 2.0 6 votes vote down vote up
@Test
public void testStep() throws Exception {
    List<String> allMessages = new ArrayList<>(matchingMessages);
    allMessages.addAll(notMatchingMessages);

    matchedEndpoint.expectedBodiesReceived(matchingMessages);
    allMessagesEndpoint.expectedBodiesReceived(allMessages);

    for (Object body : allMessages) {
        template.sendBody(START_URI, body);
    }

    MockEndpoint[] mockEndpoints = {
            matchedEndpoint, allMessagesEndpoint
    };
    MockEndpoint.assertIsSatisfied(mockEndpoints);
    logMessagesReceived(mockEndpoints);
}
 
Example #13
Source File: OutboundEndpointTest.java    From vertx-camel-bridge with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithMockWithASingleMessageHeadersNotCopied() throws Exception {
  MockEndpoint endpoint = (MockEndpoint) camel.getComponent("mock").createEndpoint("mock:foo");
  camel.addEndpoint("output", endpoint);

  bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel)
      .addOutboundMapping(fromVertx("test").toCamel("output").withoutHeadersCopy()));

  camel.start();
  BridgeHelper.startBlocking(bridge);

  vertx.eventBus().send("test", "hello", new DeliveryOptions().addHeader("key", "value"));

  await().atMost(DEFAULT_TIMEOUT).until(() -> !endpoint.getExchanges().isEmpty());
  endpoint.expectedBodiesReceived("hello");

  Exchange exchange = endpoint.getExchanges().get(0);
  assertThat(exchange.getIn().getBody()).isEqualTo("hello");
  assertThat(exchange.getIn().getHeaders()).doesNotContainKey("key");
}
 
Example #14
Source File: SignaturesSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessageModificationAfterSigning() throws InterruptedException {
    MockEndpoint mockSigned = getMockEndpoint("mock:signed");
    mockSigned.whenAnyExchangeReceived(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            Message in = exchange.getIn();
            in.setBody(in.getBody(String.class) + "modified");
        }
    });

    MockEndpoint mockVerified = getMockEndpoint("mock:verified");
    mockVerified.setExpectedMessageCount(0);

    try {
        template.sendBody("direct:sign", "foo");
        fail();
    } catch (CamelExecutionException cex) {
        assertTrue(ExceptionUtils.getRootCause(cex) instanceof SignatureException);
        assertEquals("SignatureException: Cannot verify signature of exchange",
            ExceptionUtils.getRootCauseMessage(cex));
    }

    assertMockEndpointsSatisfied();
}
 
Example #15
Source File: SplitSimpleExpressionSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleExpressionReferenceToList() throws Exception {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.expectedMessageCount(3);
    mockOut.expectedBodiesReceived("one", "two", "three");

    List<String> list = new LinkedList<String>();
    list.add("one");
    list.add("two");
    list.add("three");
    ListWrapper wrapper = new ListWrapper();
    wrapper.setWrapped(list);

    template.sendBody("direct:in", wrapper);

    assertMockEndpointsSatisfied();
}
 
Example #16
Source File: HipchatConsumerIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void sendInOnlyNoResponse() throws Exception {
    CamelContext camelctx = createCamelContext();

    MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(0);

    camelctx.start();
    try {
        ProducerTemplate template = camelctx.createProducerTemplate();
        HttpEntity mockHttpEntity = mock(HttpEntity.class);
        when(mockHttpEntity.getContent()).thenReturn(null);
        when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
        when(closeableHttpResponse.getStatusLine())
                .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));

        result.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example #17
Source File: HL7NettyIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testHl7NettyEncodeDecode() throws Exception {
    CamelContext camelctx = camelContextRegistry.getCamelContext("hl7-context");
    Assert.assertNotNull("Expected hl7-context to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());

    String body = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4\r";

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedBodiesReceived(body);

    ProducerTemplate template = camelctx.createProducerTemplate();
    template.sendBody("direct:start", body);

    mockEndpoint.assertIsSatisfied(5000);
}
 
Example #18
Source File: MicrometerCounterIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testOverrideUsingConstantValue() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:out", MockEndpoint.class);
        mockEndpoint.expectedMessageCount(1);

        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBodyAndHeader("direct:in-3", null, HEADER_COUNTER_DECREMENT, 7.0D);

        Assert.assertEquals(417.0D, metricsRegistry.find("C").counter().count(), 0.01D);
        mockEndpoint.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example #19
Source File: ODataReadRouteNoSplitResultsTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
/**
 * Despite split being set to false, the existence of a key predicate
 * forces the split since a predicate demands only 1 result which is
 * pointless putting into an array.
 */
@Test
public void testODataRouteWithKeyPredicate() throws Exception {
    String keyPredicate = "1";
    Connector odataConnector = createODataConnector(new PropertyBuilder<String>()
                                                        .property(SERVICE_URI, defaultTestServer.servicePlainUri())
                                                        .property(KEY_PREDICATE, keyPredicate));

    Step odataStep = createODataStep(odataConnector, defaultTestServer.resourcePath());
    Integration odataIntegration = createIntegration(odataStep, mockStep);

    RouteBuilder routes = newIntegrationRouteBuilder(odataIntegration);
    context.addRoutes(routes);
    MockEndpoint result = initMockEndpoint();
    result.setMinimumExpectedMessageCount(1);

    context.start();

    result.assertIsSatisfied();

    //
    // We expect the result object to be a single json object & not an array
    //
    testResult(result, 0, TEST_SERVER_DATA_1);
}
 
Example #20
Source File: ActivityLoggingWithSplitTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoggingWithSuccessStep() throws Exception {
    final MockEndpoint result = context.getEndpoint("mock:end", MockEndpoint.class);
    result.expectedBodiesReceived("Hello", "World");
    context.createProducerTemplate().sendBody("direct:start", new String[] {"Hello", "World"});
    result.assertIsSatisfied();

    // There should be 1 exchanges logged.
    assertEquals(1, findExchangesLogged().size());
    // There should be 1 "status":"begin"
    assertEquals(1, findActivityEvents(x -> "begin".equals(x.status)).size());
    // There should be 1 "status":"done"
    assertEquals(1, findActivityEvents(x -> "done".equals(x.status)).size());
    // There should be no failed flag on activity with "status":"done"
    assertEquals("false", findActivityEvent(x -> "done".equals(x.status)).failed);

    // There should be log activities
    assertEquals(2, findActivityEvents(x -> "log".equals(x.step) && ObjectHelper.isEmpty(x.duration)).size());
    assertEquals(2, findActivityEvents(x -> "log".equals(x.step) && ObjectHelper.isNotEmpty(x.duration)).size());
    assertEquals("hi", findActivityEvent(x -> "log".equals(x.step)).message);

    // There should be step activity tracking events
    assertEquals(6, findActivityEvents(x -> ObjectHelper.isNotEmpty(x.duration)).size());
}
 
Example #21
Source File: WordpressIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testPostSingleRequest() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            configureComponent(getContext());

            from("wordpress:post?id=114913").to("mock:resultSingle");

        }
    });

    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:resultSingle", MockEndpoint.class);
        mock.expectedMinimumMessageCount(1);
        mock.allMessages().body().isInstanceOf(Post.class);

        mock.assertIsSatisfied();
    } finally {
        camelctx.close();
    }
}
 
Example #22
Source File: DlcTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testDlqMultistepOriginal() throws Exception {
    final MockEndpoint mockResult = getMockEndpoint("mock:result");
    mockResult.expectedMessageCount(1);
    mockResult.expectedBodiesReceived("Foo");
    mockResult.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNull();
    mockResult.message(0).header("myHeader").isEqualTo("changed");

    final MockEndpoint mockError = getMockEndpoint("mock:error");
    mockError.expectedMessageCount(1);
    mockError.expectedBodiesReceived("KaBoom");
    mockError.message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isNotNull();
    mockError.message(0).exchangeProperty(Exchange.FAILURE_ROUTE_ID).isEqualTo("myFlakyRouteOriginal");
    mockError.message(0).header("myHeader").isEqualTo("multistep");

    template.sendBodyAndHeader("direct:multirouteOriginal", "Foo", "myHeader", "original");
    template.sendBodyAndHeader("direct:multirouteOriginal", "KaBoom", "myHeader", "original");

    assertMockEndpointsSatisfied();
}
 
Example #23
Source File: AggregateABCEagerTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testABCEND() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // we expect ABC in the published message
    // notice: Only 1 message is expected
    mock.expectedBodiesReceived("ABC");

    // send the first message
    template.sendBodyAndHeader("direct:start", "A", "myId", 1);
    // send the 2nd message with the same correlation key
    template.sendBodyAndHeader("direct:start", "B", "myId", 1);
    // the F message has another correlation key
    template.sendBodyAndHeader("direct:start", "F", "myId", 2);
    // now we have 3 messages with the same correlation key
    // and the Aggregator should publish the message
    template.sendBodyAndHeader("direct:start", "C", "myId", 1);
    // and now the END message to trigger completion
    template.sendBodyAndHeader("direct:start", "END", "myId", 1);

    assertMockEndpointsSatisfied();
}
 
Example #24
Source File: SpringAggregateABCInvalidTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testABCInvalid() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // we expect ABC in the published message
    // notice: Only 1 message is expected
    mock.expectedBodiesReceived("ABC");

    // send the first message
    template.sendBodyAndHeader("direct:start", "A", "myId", 1);
    // send the 2nd message with the same correlation key
    template.sendBodyAndHeader("direct:start", "B", "myId", 1);
    // the F message has another correlation key
    template.sendBodyAndHeader("direct:start", "F", "myId", 2);
    // this message has no correlation key so its ignored
    template.sendBody("direct:start", "C");
    // so we resend the message this time with a correlation key
    template.sendBodyAndHeader("direct:start", "C", "myId", 1);

    assertMockEndpointsSatisfied();
}
 
Example #25
Source File: TopicLoadBalancerTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadBalancer() throws Exception {
    // both mocks should get all the messages as its topic strategy
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedMessageCount(4);

    MockEndpoint b = getMockEndpoint("mock:b");
    b.expectedMessageCount(4);

    // send in 4 messages
    template.sendBody("direct:start", "Hello");
    template.sendBody("direct:start", "Camel rocks");
    template.sendBody("direct:start", "Cool");
    template.sendBody("direct:start", "Bye");

    assertMockEndpointsSatisfied();
}
 
Example #26
Source File: FailoverLoadBalancerTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadBalancer() throws Exception {
    // A should get the 1st, 3rd and 4th message
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedBodiesReceived("Hello", "Cool", "Bye");

    // B should get the 2nd
    MockEndpoint b = getMockEndpoint("mock:b");
    b.expectedBodiesReceived("Kaboom");

    // send in 4 messages
    template.sendBody("direct:start", "Hello");
    template.sendBody("direct:start", "Kaboom");
    template.sendBody("direct:start", "Cool");
    template.sendBody("direct:start", "Bye");

    assertMockEndpointsSatisfied();
}
 
Example #27
Source File: RouteScopeTest.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrderActiveMQ() throws Exception {
    // we expect the file to be converted to csv and routed to the 2nd route
    MockEndpoint file = getMockEndpoint("mock:file");
    file.expectedMessageCount(1);

    // we do not expect the 2nd route to complete
    MockEndpoint mock = getMockEndpoint("mock:queue.order");
    mock.expectedMessageCount(0);

    template.sendBodyAndHeader("file://target/orders", "amount=1#name=ActiveMQ in Action", Exchange.FILE_NAME, "order.txt");

    // wait 10 seconds to let this test run
    Thread.sleep(10000);

    assertMockEndpointsSatisfied();
}
 
Example #28
Source File: SpringTopicLoadBalancerTest.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadBalancer() throws Exception {
    // both mocks should get all the messages as its topic strategy
    MockEndpoint a = getMockEndpoint("mock:a");
    a.expectedMessageCount(4);

    MockEndpoint b = getMockEndpoint("mock:b");
    b.expectedMessageCount(4);

    // send in 4 messages
    template.sendBody("direct:start", "Hello");
    template.sendBody("direct:start", "Camel rocks");
    template.sendBody("direct:start", "Cool");
    template.sendBody("direct:start", "Bye");

    assertMockEndpointsSatisfied();
}
 
Example #29
Source File: DatabaseTransactionSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testTransactedExceptionThrown() throws InterruptedException {
    AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
    String message = "this message will explode";
    assertEquals(0, auditLogDao.getAuditCount(message));

    MockEndpoint mockCompleted = getMockEndpoint("mock:out");
    mockCompleted.setExpectedMessageCount(1);
    mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor());

    try {
        template.sendBody("direct:transacted", message);
        fail();
    } catch (CamelExecutionException cee) {
        assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage());
    }

    assertMockEndpointsSatisfied();
    assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
}
 
Example #30
Source File: CdiCustomNonDefaultNamedContextTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();
    camelContext.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("flowable:camelProcess");

            from("flowable:camelProcess:serviceTask1").setBody().exchangeProperty("var1").to("mock:service1").setProperty("var2").constant("var2").setBody()
                            .exchangeProperties();

            from("flowable:camelProcess:serviceTask2?copyVariablesToBodyAsMap=true").to("mock:service2");

            from("direct:receive").to("flowable:camelProcess:receive");
        }
    });

    service1 = (MockEndpoint) camelContext.getEndpoint("mock:service1");
    service1.reset();
    service2 = (MockEndpoint) camelContext.getEndpoint("mock:service2");
    service2.reset();
}