Search in sources :

Example 41 with MockMessageProducer

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

the class StandardResponseProducerTest method testResponse_MetadataContentType.

@Test
public void testResponse_MetadataContentType() throws Exception {
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    responder.setContentTypeProvider(new MetadataContentTypeProvider("MyContentType"));
    AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("MyContentType", "text/xml") }));
    HttpConnection httpConnection = createConnection();
    Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { addMetadata, new StandaloneProducer(responder) })));
    StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
    AdaptrisMessage msg = createMessage();
    try {
        c.requestStart();
        start(requestor);
        requestor.doService(msg);
        assertEquals(TEXT, msg.getContent());
        assertTrue(msg.containsKey("Content-Type"));
        assertTrue(msg.getMetadataValue("Content-Type").startsWith("text/xml"));
    } finally {
        c.requestClose();
        stop(requestor);
        PortManager.release(httpConnection.getPort());
    }
}
Also used : MetadataContentTypeProvider(com.adaptris.core.http.MetadataContentTypeProvider) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 42 with MockMessageProducer

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

the class RetryFromJettyTest method testRetry_WrongMethod.

@Test
public void testRetry_WrongMethod() throws Exception {
    RetryFromJetty retrier = create();
    StandardWorkflow workflow = createWorkflow();
    try {
        MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
        retrier.addWorkflow(workflow);
        retrier.addWorkflow(createWorkflow());
        start(workflow, retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        baseMsg.addMetadata(Workflow.WORKFLOW_ID_KEY, workflow.obtainWorkflowId());
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        // This should result in a route condition that doesn't match POST + the msgId so 400 is
        // expected
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        http.setIgnoreServerResponseCode(true);
        http.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_BAD, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
    } finally {
        stop(retrier, workflow);
    }
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) Test(org.junit.Test)

Example 43 with MockMessageProducer

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

the class RetryFromJettyTest method testRetry.

@Test
public void testRetry() throws Exception {
    RetryFromJetty retrier = create();
    StandardWorkflow workflow = createWorkflow();
    try {
        MockMessageProducer workflowProducer = (MockMessageProducer) workflow.getProducer();
        retrier.addWorkflow(workflow);
        retrier.addWorkflow(createWorkflow());
        start(workflow, retrier);
        AdaptrisMessage baseMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        baseMsg.addMetadata(Workflow.WORKFLOW_ID_KEY, workflow.obtainWorkflowId());
        retryStore.write(baseMsg);
        assertNotNull(retryStore.getMetadata(baseMsg.getUniqueId()));
        String url = jettyHelper.buildUrl(RetryFromJetty.DEFAULT_ENDPOINT_PREFIX + baseMsg.getUniqueId());
        StandardHttpProducer http = buildProducer(url);
        AdaptrisMessage triggerMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        ExampleServiceCase.execute(new StandaloneRequestor(http), triggerMsg);
        assertEquals(RetryFromJetty.HTTP_ACCEPTED, triggerMsg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
        // This should trigger the workflow, so we should wait for the message
        await().atMost(Duration.ofSeconds(1)).with().pollInterval(Duration.ofMillis(100)).until(workflowProducer::messageCount, greaterThanOrEqualTo(1));
        assertEquals(1, workflowProducer.messageCount());
    } finally {
        stop(retrier, workflow);
    }
}
Also used : StandardHttpProducer(com.adaptris.core.http.client.net.StandardHttpProducer) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 44 with MockMessageProducer

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

the class InFlightWorkflowInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws Exception {
    InFlightWorkflowInterceptor interceptor = new InFlightWorkflowInterceptor("testInterceptor");
    final PoolingWorkflow wf = createPoolingWorkflow("workflow", interceptor);
    wf.setPoolSize(1);
    wf.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
    MockChannel c = new MockChannel();
    c.getWorkflowList().add(wf);
    try {
        LifecycleHelper.initAndStart(c);
        wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(0, interceptor.messagesPendingCount());
        new Thread(new Runnable() {

            @Override
            public void run() {
                wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            }
        }).start();
        LifecycleHelper.waitQuietly(100);
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(1, interceptor.messagesPendingCount());
        ExampleServiceCase.waitForMessages(prod, 2, 10000);
    } finally {
        LifecycleHelper.stopAndClose(c);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 45 with MockMessageProducer

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

the class LoggingContextInterceptorTest method testInterceptor_Defaults_NotAsObjectMetadata.

@Test
public void testInterceptor_Defaults_NotAsObjectMetadata() throws Exception {
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
        assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)321 Test (org.junit.Test)306 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)156 MockChannel (com.adaptris.core.stubs.MockChannel)126 Channel (com.adaptris.core.Channel)125 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)73 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)69 StandaloneProducer (com.adaptris.core.StandaloneProducer)68 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)65 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)56 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)52 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 StandardWorkflow (com.adaptris.core.StandardWorkflow)40 TimeInterval (com.adaptris.util.TimeInterval)40 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 ServiceList (com.adaptris.core.ServiceList)33 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)33 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)27