use of com.adaptris.core.services.metadata.AddMetadataService in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_MetadataResponseHeaders.
@Test
public void testResponse_MetadataResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
RegexMetadataFilter filter = new RegexMetadataFilter();
filter.addIncludePattern(METADATA_REGEXP);
responder.setResponseHeaderProvider(new MetadataResponseHeaderProvider(filter));
AddMetadataService addMetadata = new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(CUSTOM_HEADER1, CUSTOM_VALUE1), new MetadataElement(CUSTOM_HEADER2, CUSTOM_VALUE2) }));
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(CUSTOM_HEADER1));
assertTrue(msg.containsKey(CUSTOM_HEADER2));
assertEquals(CUSTOM_VALUE1, msg.getMetadataValue(CUSTOM_HEADER1));
assertEquals(CUSTOM_VALUE2, msg.getMetadataValue(CUSTOM_HEADER2));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
Aggregations