Search in sources :

Example 1 with StaticMockMessageProducer

use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.

the class HttpConsumerTest method testPoolingWorkflow_TimeoutAction_TimeoutExceeded.

@Test
public void testPoolingWorkflow_TimeoutAction_TimeoutExceeded() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    consumer.setAdditionalDebug(false);
    consumer.setTimeoutAction(new TimeoutAction(new TimeInterval(100L, TimeUnit.MILLISECONDS)));
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(5L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals(Integer.valueOf(HttpStatus.ACCEPTED_202.getStatusCode()), Integer.valueOf(reply.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE)));
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 2 with StaticMockMessageProducer

use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.

the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.

@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
    EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
    helper.startServer();
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(helper.createProduceDestination());
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        // Because of redmineID #4715 it should just "return immediatel" which flushes the stream so there's no content.
        assertEquals("Reply Payloads", "", reply.getContent());
    } finally {
        stop(httpProducer);
        channel.requestClose();
        helper.stopServer();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 3 with StaticMockMessageProducer

use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.

the class HttpConsumerTest method testPoolingWorkflow_WithInterceptor.

@Test
public void testPoolingWorkflow_WithInterceptor() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    consumer.setWarnAfter(new TimeInterval(10L, TimeUnit.MILLISECONDS));
    PoolingWorkflow workflow = new PoolingWorkflow();
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 4 with StaticMockMessageProducer

use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method createMockProducer.

protected StaticMockMessageProducer createMockProducer() {
    StaticMockMessageProducer p = new StaticMockMessageProducer();
    p.getMessages().clear();
    return p;
}
Also used : StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer)

Example 5 with StaticMockMessageProducer

use of com.adaptris.core.stubs.StaticMockMessageProducer in project interlok by adaptris.

the class PoolingWorkflowTest method testOnMessage_SkipProducer.

@Test
public void testOnMessage_SkipProducer() throws Exception {
    StaticMockMessageProducer serviceProducer = new StaticMockMessageProducer();
    serviceProducer.getMessages().clear();
    MockChannel channel = createAndPrepareChannel(Arrays.asList(new Service[] { createService(), new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
    try {
        PoolingWorkflow workflow = (PoolingWorkflow) channel.getWorkflowList().get(0);
        MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
        start(channel);
        submitMessages(workflow, 10);
        waitForMessages(serviceProducer, 10);
        // assertEquals(10, serviceProducer.messageCount());
        assertEquals(0, workflowProducer.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) WaitService(com.adaptris.core.services.WaitService) XmlRoundTripService(com.adaptris.core.stubs.XmlRoundTripService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Test(org.junit.Test)

Aggregations

StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)9 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)8 Test (org.junit.Test)8 WaitService (com.adaptris.core.services.WaitService)7 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 Channel (com.adaptris.core.Channel)6 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)6 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 TimeInterval (com.adaptris.util.TimeInterval)6 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)2 MockChannel (com.adaptris.core.stubs.MockChannel)2 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)2 HttpRequestService (com.adaptris.core.http.client.net.HttpRequestService)1 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)1 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)1 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)1 MockWorkflowInterceptor (com.adaptris.core.stubs.MockWorkflowInterceptor)1 XmlRoundTripService (com.adaptris.core.stubs.XmlRoundTripService)1