Java Code Examples for org.apache.camel.component.mock.MockEndpoint#setResultWaitTime()

The following examples show how to use org.apache.camel.component.mock.MockEndpoint#setResultWaitTime() . 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: ThreadsDslInOutTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testParallelConsumption() throws InterruptedException, ExecutionException {
    final int messageCount = 10;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        Future<Object> future = template.asyncRequestBody("direct:in", "Message[" + i + "]");
        // here we ask the Future to return to us the response set by the thread assigned by the
        // threads() DSL
        String response = (String) future.get();
        assertEquals("Processed", response);
    }

    assertMockEndpointsSatisfied();
}
 
Example 2
Source File: CustomThreadPoolInlineTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 3
Source File: CustomThreadPoolSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 4
Source File: CustomThreadPoolRefRouteBuilderSpringTest.java    From camel-cookbook-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    List<Exchange> receivedExchanges = mockOut.getReceivedExchanges();
    for (Exchange exchange : receivedExchanges) {
        assertTrue(exchange.getIn().getBody(String.class).endsWith("CustomThreadPool"));
    }
}
 
Example 5
Source File: EndpointConsumersSedaSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelConsumption() throws InterruptedException {
    final int messageCount = 100;
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBody("seda:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 6
Source File: AsyncProcessorSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncProcessing() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBody("direct:sync", ExchangePattern.InOnly, "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 7
Source File: SometimesAsyncProcessorTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncProcessing() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBodyAndHeader("seda:in", "Message[" + i + "]", "processAsync", false);
    }

    assertMockEndpointsSatisfied();
    Message message = mockOut.getExchanges().get(0).getIn();
    assertEquals(message.getHeader("initiatingThread"), message.getHeader("completingThread"));
}
 
Example 8
Source File: SometimesAsyncProcessorTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncProcessing() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBodyAndHeader("seda:in", "Message[" + i + "]", "processAsync", true);
    }

    assertMockEndpointsSatisfied();
    Message message = mockOut.getExchanges().get(0).getIn();
    assertNotEquals(message.getHeader("initiatingThread"), message.getHeader("completingThread"));
}
 
Example 9
Source File: AsyncProcessorTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncProcessing() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBody("direct:sync", ExchangePattern.InOnly, "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 10
Source File: AsyncProcessorTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncProcessing() throws InterruptedException {
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBody("seda:in", ExchangePattern.InOnly, "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 11
Source File: EndpointConsumersSedaTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelConsumption() throws InterruptedException {
    final int messageCount = 100;
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.sendBody("seda:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 12
Source File: CronTest.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@MethodSource("parameters")
public void testCronTimerActivation(String routes, String cronOverride) throws Exception {
    ApplicationRuntime runtime = new ApplicationRuntime();
    runtime.setProperties(
        "loader.interceptor.cron.overridable-components", cronOverride
    );
    runtime.addListener(RoutesConfigurer.forRoutes(routes));

    // To check auto-termination of Camel context
    CountDownLatch termination = new CountDownLatch(1);
    runtime.getCamelContext().addLifecycleStrategy(new LifecycleStrategySupport() {
        @Override
        public void onContextStop(CamelContext context) {
            termination.countDown();
        }
    });

    MockEndpoint mock = runtime.getCamelContext().getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.setResultWaitTime(10000);

    runtime.run();
    mock.assertIsSatisfied();

    termination.await(10, TimeUnit.SECONDS);
    assertThat(termination.getCount()).isEqualTo(0);
}
 
Example 13
Source File: CustomThreadPoolProfileTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessedByCustomThreadPool() throws InterruptedException {
    final int messageCount = 50;
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    // no way to check programatically whether the profile was actually engaged, as Camel uses the
    // default naming strategy for threads
}
 
Example 14
Source File: CustomThreadPoolProfilesSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessedByCustomThreadPoolProfile() throws InterruptedException {
    final int messageCount = 50;
    MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(6000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
    // no way to check programatically whether the profile was actually engaged, as Camel uses the
    // default naming strategy for threads
}
 
Example 15
Source File: ThreadsDslTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelConsumption() throws InterruptedException {
    final int messageCount = 50;

    final MockEndpoint mockOut = getMockEndpoint("mock:out");
    mockOut.setExpectedMessageCount(messageCount);
    mockOut.setResultWaitTime(5000);

    for (int i = 0; i < messageCount; i++) {
        template.asyncSendBody("direct:in", "Message[" + i + "]");
    }

    assertMockEndpointsSatisfied();
}
 
Example 16
Source File: StompIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageConsumerRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            fromF("stomp:%s?login=%s&passcode=%s&brokerURL=%s", QUEUE_NAME, USERNAME, PASSWORD, BROKER_URL)
            .transform(body().prepend("Hello "))
            .to("mock:result");
        }
    });

    camelctx.start();

    MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    mockEndpoint.expectedBodiesReceived("Hello Kermit");
    mockEndpoint.setResultWaitTime(30000);

    Stomp stomp = new Stomp(BROKER_URL);
    stomp.setLogin(USERNAME);
    stomp.setPasscode(PASSWORD);

    final BlockingConnection producerConnection = stomp.connectBlocking();
    try {
        StompFrame outFrame = new StompFrame(SEND);
        outFrame.addHeader(DESTINATION, StompFrame.encodeHeader(QUEUE_NAME));
        outFrame.addHeader(MESSAGE_ID, StompFrame
            .encodeHeader("StompIntegrationTest.testMessageConsumerRoute" + UUID.randomUUID().toString()));
        outFrame.content(utf8("Kermit"));
        producerConnection.send(outFrame);

        mockEndpoint.assertIsSatisfied();
    } finally {
        if (producerConnection != null) {
            producerConnection.close();
        }
        camelctx.close();
    }
}
 
Example 17
Source File: SlowlyTransformingRouteLoadTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testPayloadsTransformedInExpectedTime() throws InterruptedException {
    // A DataSetEndpoint is a sub-class of MockEndpoint that sets up expectations based on
    // the messages created, and the size property on the object.
    // All that is needed for us to test this route is to assert that the endpoint was satisfied.
    MockEndpoint expectedOutput = getMockEndpoint("dataset:expectedOutput");
    expectedOutput.setResultWaitTime(10000);
    expectedOutput.assertIsSatisfied();
}
 
Example 18
Source File: AbstractODataTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
protected MockEndpoint initMockEndpoint() {
    MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
    result.setResultWaitTime(MOCK_TIMEOUT_MILLISECONDS);
    return result;
}
 
Example 19
Source File: RouteUtils.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public static MockEndpoint initMockEndpoint(CamelContext context) {
    MockEndpoint result = context.getEndpoint("mock:result", MockEndpoint.class);
    result.setResultWaitTime(MOCK_TIMEOUT_MILLISECONDS);
    return result;
}
 
Example 20
Source File: EMailReadRouteTest.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Test
public void testImapEMailRouteUnseenMailsOnly() throws Exception {
    server = imapServer();
    int emailCount = server.getEmailCount();
    int unseenCount = 2;

    //
    // Read all emails except unseenCount
    //
    int readCount = emailCount - unseenCount;
    server.readEmails(readCount);

    Connector mailConnector = RouteUtils.createEMailConnector(server,
                                                   new PropertyBuilder<String>()
                                                           .property(PROTOCOL, Protocol.IMAP.id())
                                                           .property(HOST, server.getHost())
                                                           .property(PORT, Integer.toString(server.getPort()))
                                                           .property(USER, TEST_ADDRESS)
                                                           .property(PASSWORD, TEST_PASSWORD));

    PropertyBuilder<String> configuredProperties = new PropertyBuilder<>();
    configuredProperties.property(UNSEEN_ONLY, Boolean.toString(true));
    Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction, configuredProperties.build());
    Integration mailIntegration = RouteUtils.createIntegrationWithMock(mailStep);

    RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration);
    context.addRoutes(routes);

    MockEndpoint result = RouteUtils.initMockEndpoint(context);
    result.setResultWaitTime(10000L);
    result.setExpectedMessageCount(unseenCount);

    context.start();

    RouteUtils.assertSatisfied(result);

    assertEquals(unseenCount, result.getExchanges().size());
    for (int i = readCount; i < emailCount; ++i) {
        RouteUtils.testResult(result, (i - readCount), server.getEmails().get(i));
    }
}