use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpConsumerTest method testPoolingWorkflow_WithInterceptor.
@Test
public void testPoolingWorkflow_WithInterceptor() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
consumer.setWarnAfter(new TimeInterval(10L, TimeUnit.MILLISECONDS));
PoolingWorkflow workflow = new PoolingWorkflow();
StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
workflow.setConsumer(consumer);
workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
workflow.getServiceCollection().add(new StandaloneProducer(responder));
workflow.addInterceptor(new JettyPoolingWorkflowInterceptor());
Channel channel = JettyHelper.createChannel(connection, workflow);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
} finally {
stop(httpProducer);
channel.requestClose();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpConsumerTest method testConsumeWorkflow_PreserveParams_WithPrefix.
@Test
public void testConsumeWorkflow_PreserveParams_WithPrefix() throws Exception {
HttpConnection connection = createConnection(null);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer("/*", getName());
consumer.setHeaderHandler(new MetadataHeaderHandler("Http_Header_"));
consumer.setParameterHandler(new MetadataParameterHandler("Http_Param_"));
Channel channel = JettyHelper.createChannel(connection, consumer, mockProducer);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
String dest = createProduceDestinationUrl(connection.getPort());
dest += "?queryParam1=1&queryParam2=2&queryParam3=3";
httpProducer.setUrl(dest);
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
AdaptrisMessage receivedMsg = doAssertions(mockProducer);
assertTrue(receivedMsg.containsKey(JettyConstants.JETTY_QUERY_STRING));
assertEquals("queryParam1=1&queryParam2=2&queryParam3=3", receivedMsg.getMetadataValue(JettyConstants.JETTY_QUERY_STRING));
assertFalse(receivedMsg.containsKey("Http_Header_queryParam1"));
assertFalse(receivedMsg.containsKey("Http_Header_queryParam2"));
assertFalse(receivedMsg.containsKey("Http_Header_queryParam3"));
assertEquals("1", receivedMsg.getMetadataValue("Http_Param_queryParam1"));
assertEquals("2", receivedMsg.getMetadataValue("Http_Param_queryParam2"));
assertEquals("3", receivedMsg.getMetadataValue("Http_Param_queryParam3"));
} finally {
stop(httpProducer);
channel.requestClose();
PortManager.release(connection.getPort());
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testProduce_WithUsernamePassword.
@Test
public void testProduce_WithUsernamePassword() throws Exception {
String threadName = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
csh.setLoginService(hsl);
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setMustAuthenticate(true);
securityConstraint.setRoles("user");
csh.setSecurityConstraints(Arrays.asList(securityConstraint));
HttpConnection jc = HttpHelper.createConnection();
jc.setSecurityHandler(csh);
MockMessageProducer mockProducer = new MockMessageProducer();
JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
HttpAuthenticator auth = buildAuthenticator(getName(), getName());
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(channel)).withAuthenticator(auth).withMethod("POST");
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
try {
start(channel);
execute(service, msg);
waitForMessages(mockProducer, 1);
assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
} finally {
HttpHelper.stopChannelAndRelease(channel);
Thread.currentThread().setName(threadName);
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class HttpRequestServiceTest method testService_WithMetadataMethod.
@Test
public void testService_WithMetadataMethod() 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("%message{httpMethod}");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
msg.addMetadata("httpMethod", "get");
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 HttpRequestServiceTest method testRequest_GetMethod_NonZeroBytes_WithErrorResponse.
@Test
public void testRequest_GetMethod_NonZeroBytes_WithErrorResponse() 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.UNAUTHORIZED_401)) })));
HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
start(c);
execute(service, msg);
fail();
} catch (ServiceException expect) {
} finally {
stop(c);
}
}
Aggregations