use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testHandleChannelUnavailable.
@Test
public void testHandleChannelUnavailable() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
final MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setChannelUnavailableWaitInterval(new TimeInterval(1200L, TimeUnit.MILLISECONDS));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
channel.prepare();
start(channel);
channel.toggleAvailability(false);
Timer t = new Timer(true);
t.schedule(new TimerTask() {
@Override
public void run() {
channel.toggleAvailability(true);
}
}, 500);
workflow.onAdaptrisMessage(msg);
assertEquals("Make sure all produced", 1, producer.getMessages().size());
for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ThreadContextWorkflowTest method testRuntimeException.
@Test
public void testRuntimeException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new RuntimeException();
}
};
MockMessageProducer meh = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_1, m.getContent());
assertFalse("Does not contains correct metadata key", m.headersContainsKey(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class XStreamMarshallerTest method adapterInstanceFieldChecks.
// redmineID 2457 - ensures that marshalling/unmarshalling the given files results in no loss of data
public static void adapterInstanceFieldChecks(Adapter fromXML) {
assertNotNull(fromXML);
assertEquals("SimpleAdapterTest", fromXML.getUniqueId());
assertTrue(fromXML.getEventHandler() instanceof DefaultEventHandler);
assertTrue(((DefaultEventHandler) fromXML.getEventHandler()).getConnection() instanceof NullConnection);
assertTrue(((DefaultEventHandler) fromXML.getEventHandler()).getProducer() instanceof NullMessageProducer);
// ShutdownWaitSeconds is now null.
assertNull(((DefaultEventHandler) fromXML.getEventHandler()).getShutdownWaitSeconds());
assertTrue(fromXML.getMessageErrorHandler() instanceof NullProcessingExceptionHandler);
Channel channel = fromXML.getChannelList().get(0);
assertTrue(channel.getConsumeConnection() instanceof NullConnection);
assertTrue(channel.getProduceConnection() instanceof NullConnection);
// Check workflow
WorkflowList workflowList = channel.getWorkflowList();
assertNotNull(workflowList);
assertEquals(1, workflowList.size());
// test workflow
StandardWorkflow standardWorkflow = (StandardWorkflow) workflowList.get(0);
assertNotNull(standardWorkflow);
assertEquals("workflow1", standardWorkflow.getUniqueId());
// test workflow consumer
NullMessageConsumer consumer = (NullMessageConsumer) standardWorkflow.getConsumer();
assertNotNull(consumer);
// test services
ServiceCollection serviceCollection = standardWorkflow.getServiceCollection();
assertNotNull(serviceCollection);
assertEquals("serviceListID1", serviceCollection.getUniqueId());
assertEquals(3, serviceCollection.size());
assertTrue(serviceCollection instanceof ServiceList);
// test service 1
Service service1 = serviceCollection.get(0);
assertEquals("serviceID1", service1.getUniqueId());
assertTrue(service1 instanceof AddMetadataService);
Set<MetadataElement> metadataElements = ((AddMetadataService) service1).getMetadataElements();
assertEquals(1, metadataElements.size());
for (Iterator<MetadataElement> iterator = metadataElements.iterator(); iterator.hasNext(); ) {
MetadataElement metadataElement = iterator.next();
assertEquals("key1", metadataElement.getKey());
assertEquals("val1", metadataElement.getValue());
break;
}
// test service 2
Service service2 = serviceCollection.get(1);
assertEquals("serviceID2", service2.getUniqueId());
assertTrue(service2 instanceof XpathMetadataService);
List<XpathQuery> xpathQueries = ((XpathMetadataService) service2).getXpathQueries();
assertEquals(1, xpathQueries.size());
assertEquals(ConfiguredXpathQuery.class, xpathQueries.get(0).getClass());
assertEquals("/a/b/c", ((ConfiguredXpathQuery) xpathQueries.get(0)).getXpathQuery());
// Test service3
Service service3 = serviceCollection.get(2);
assertEquals("serviceID3", service3.getUniqueId());
assertTrue(service3 instanceof LogMessageService);
assertTrue(StringUtils.isBlank(((LogMessageService) service3).getLogPrefix()));
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class ServiceListTest method testBreakOutOfServiceList.
@Test
public void testBreakOutOfServiceList() throws CoreException {
ServiceList services = createServiceList(false);
services.addService(new MockStopProcessingService());
services.addService(new AddMetadataService(Arrays.asList(new MetadataElement(KEY3, VAL3))));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(services, msg);
assertTrue(msg.getMetadataValue(KEY1).equals(VAL1));
assertTrue(msg.getMetadataValue(KEY2).equals(VAL2));
// test break out metadata has been set...
assertTrue(msg.getMetadataValue(CoreConstants.STOP_PROCESSING_KEY).equals(CoreConstants.STOP_PROCESSING_VALUE));
// ...and that fourth service has not been applied
assertTrue(msg.getMetadataValue(KEY3) == null);
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_CompositeResponseHeaders.
@Test
public void testResponse_CompositeResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setSendPayload(false);
CompositeResponseHeaderProvider provider = new CompositeResponseHeaderProvider(new MetadataResponseHeaderProvider(new RegexMetadataFilter()), new ConfiguredResponseHeaderProvider(new KeyValuePair("Hello", "World")));
responder.setResponseHeaderProvider(provider);
AddMetadataService meta = new AddMetadataService();
meta.addMetadataElement(getName(), getName());
ServiceList sl = new ServiceList(new Service[] { meta, new StandaloneProducer(responder) });
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), sl));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertNotSame(TEXT, msg.getContent());
assertTrue(msg.containsKey(getName()));
assertTrue(msg.containsKey("Hello"));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
Aggregations