use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testRequest_ObjectMetadataResponseHeaders.
@Test
public void testRequest_ObjectMetadataResponseHeaders() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withContentType("%message{" + HttpHelper.CONTENT_TYPE + "}").withResponseHeaderHandler(new ResponseHeadersAsObjectMetadata());
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata(HttpHelper.CONTENT_TYPE, "text/complicated");
assertFalse(msg.headersContainsKey("Server"));
try {
c.requestStart();
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
assertFalse(msg.headersContainsKey("Server"));
assertTrue(msg.getObjectHeaders().containsKey("Server"));
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testRequest_GetMethod_ZeroBytes.
@Test
public void testRequest_GetMethod_ZeroBytes() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
HttpConnection jc = HttpHelper.createConnection();
JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)) })));
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
try {
start(c);
execute(service, msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(TEXT, msg.getContent());
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class JettyResponseServiceTest method testDoService.
@Test
public void testDoService() throws Exception {
JettyResponseService responder = new JettyResponseService(200, "text/plain");
HttpConnection httpConnection = createConnection();
ServiceList list = new ServiceList(responder);
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), list));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertEquals(TEXT, msg.getContent());
assertFalse(msg.containsKey(CUSTOM_HEADER1));
assertFalse(msg.containsKey(CUSTOM_HEADER2));
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class JettyResponseServiceTest method testResponseWithError.
@Test
public void testResponseWithError() throws Exception {
JettyResponseService responder = new JettyResponseService().withHttpStatus("500").withContentType("text/plain").withResponseHeaderProvider(new NoOpResponseHeaderProvider());
HttpConnection httpConnection = createConnection();
ServiceList list = new ServiceList(responder);
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), list));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
fail("StandaloneRequestor.doService() success even though we should have got a 500 error back");
} catch (ServiceException expected) {
;
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class StandardResponseProducerTest method testResponse_NoOpResponseHeaders.
@Test
public void testResponse_NoOpResponseHeaders() throws Exception {
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
responder.setResponseHeaderProvider(new NoOpResponseHeaderProvider());
HttpConnection httpConnection = createConnection();
Channel c = createChannel(httpConnection, createWorkflow(createConsumer(URL_TO_POST_TO), new MockMessageProducer(), new ServiceList(new Service[] { new StandaloneProducer(responder) })));
StandaloneRequestor requestor = createRequestor(httpConnection.getPort());
AdaptrisMessage msg = createMessage();
try {
c.requestStart();
start(requestor);
requestor.doService(msg);
assertEquals(TEXT, msg.getContent());
} finally {
c.requestClose();
stop(requestor);
PortManager.release(httpConnection.getPort());
}
}
Aggregations