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());
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations