Search in sources :

Example 6 with StaticMockMessageProducer

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

the class ThreadContextWorkflowTest method testOnMessage_SkipProducer.

@Test
public void testOnMessage_SkipProducer() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    StaticMockMessageProducer serviceProducer = new StaticMockMessageProducer();
    serviceProducer.getMessages().clear();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals(1, serviceProducer.messageCount());
        assertEquals(0, producer.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) Test(org.junit.Test)

Example 7 with StaticMockMessageProducer

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

the class ShortCutJettyResponseTest method testService.

@Test
public void testService() throws Exception {
    HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
    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.getServiceCollection().add(new ShortCutJettyResponse());
    // Workflow won't get to this before we get the response.
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(10L, TimeUnit.SECONDS)));
    workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
    Channel channel = JettyHelper.createChannel(connection, workflow);
    HttpRequestService service = JettyHelper.createService(connection.getPort());
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(HttpConsumerTest.CONTENT_TYPE_METADATA_KEY, "text/xml");
        long start = System.currentTimeMillis();
        ExampleServiceCase.execute(service, msg);
        ;
        long end = System.currentTimeMillis();
        assertTrue(end - start < TimeUnit.SECONDS.toMillis(10));
    } finally {
        stop(channel);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) HttpRequestService(com.adaptris.core.http.client.net.HttpRequestService) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 8 with StaticMockMessageProducer

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

the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithInterceptor.

@Test
public void testPoolingWorkflow_WithInterceptor() 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();
    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(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);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } 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 9 with StaticMockMessageProducer

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

the class HttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.

@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.addInterceptor(new MockWorkflowInterceptor());
    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(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);
        // 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();
    }
}
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) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) 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