use of com.adaptris.core.services.metadata.AddMetadataService 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.services.metadata.AddMetadataService in project interlok by adaptris.
the class LargeMessageWorkflowTest method testServiceException.
@Override
@Test
public void testServiceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
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), new ThrowExceptionService(new ConfiguredException("Fail")) }));
try {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) 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 (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class LargeMessageWorkflowTest method testProduceException.
@Override
@Test
public void testProduceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
};
;
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 {
LargeMessageWorkflow workflow = (LargeMessageWorkflow) 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 (AdaptrisMessage m : meh.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(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 AdapterComponentCheckerTest method createConnectedServices.
private String createConnectedServices(String sharedName) throws Exception {
ServiceList nestedList = new ServiceList();
nestedList.add(new StandaloneProducer(new MockAllowsRetriesConnection(6), new NullMessageProducer()));
if (!StringUtils.isEmpty(sharedName)) {
nestedList.add(new StatelessServiceWrapper(new StandaloneProducer(new SharedConnection(sharedName), new NullMessageProducer())));
} else {
nestedList.add(new StatelessServiceWrapper(new StandaloneProducer()));
}
nestedList.add(new AddMetadataService(new ArrayList(Arrays.asList(new MetadataElement[] { new MetadataElement("key", "value") }))));
ServiceList list = new ServiceList();
list.add(nestedList);
list.add(new JdbcServiceList());
return DefaultMarshaller.getDefaultMarshaller().marshal(list);
}
use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class WorkflowManagerTest method testProcess.
@Test
public void testProcess() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
Channel channel = createChannel("c1");
ChannelManager channelManager = new ChannelManager(channel, adapterManager);
StandardWorkflow workflow = createWorkflow("w1");
workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
adapterManager.createObjectName();
ObjectName workflowObj = realWorkflowManager.createObjectName();
channelManager.createObjectName();
List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
mBeans.add(adapterManager);
mBeans.addAll(adapterManager.getAllDescendants());
String msgUniqueId = new GuidGenerator().getUUID();
SerializableMessage msg = createSM(msgUniqueId);
try {
register(mBeans);
MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
adapterManager.requestStart();
SerializableMessage reply = workflowManagerProxy.process(msg);
assertEquals(msgUniqueId, reply.getUniqueId());
assertEquals(PAYLOAD, reply.getContent());
assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
Map<String, String> headers = reply.getMessageHeaders();
assertTrue(headers.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, headers.get(METADATA_KEY));
assertTrue(headers.containsKey(getName()));
assertEquals(getName(), headers.get(getName()));
assertEquals("", reply.getNextServiceId());
} finally {
adapter.requestClose();
}
}
Aggregations