use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class JettyAsyncWorkflowInterceptorTest method testAcrossMultipleWorkflows_WithCacheKey.
@Test
public void testAcrossMultipleWorkflows_WithCacheKey() throws Exception {
HttpConnection connection = createConnection(Integer.parseInt(PROPERTIES.getProperty(JETTY_HTTP_PORT)));
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO, getName());
PoolingWorkflow receivingWF = new PoolingWorkflow();
// It's a bit lame, but we have to use something that is populated *before entry into the workflow*
String cacheKey = "%message{" + JettyConstants.JETTY_URI + "}";
receivingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.REQUEST).withCacheKey(cacheKey));
receivingWF.setShutdownWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
receivingWF.setConsumer(consumer);
StandardWorkflow respondingWF = new StandardWorkflow();
// Mainly to keep track of the msgID. we use a standard workflow so new objects aren't created.
MockMessageProducer producer = new MockMessageProducer();
respondingWF.addInterceptor(new JettyAsyncWorkflowInterceptor().withMode(JettyAsyncWorkflowInterceptor.Mode.RESPONSE).withCacheKey(cacheKey));
respondingWF.getServiceCollection().add(new PayloadFromTemplateService().withTemplate("hello world"));
respondingWF.getServiceCollection().add(new JettyResponseService(200, "text/plain"));
respondingWF.getServiceCollection().add(new StandaloneProducer(producer));
receivingWF.setProducer(new WorkflowProducer(respondingWF));
Channel channel = JettyHelper.createChannel(connection, receivingWF, respondingWF);
HttpRequestService httpService = createRequestor(connection.getPort());
try {
start(channel);
LifecycleHelper.initAndStart(httpService);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
ExampleServiceCase.execute(httpService, msg);
assertEquals("hello world", msg.getContent());
waitForMessages(producer, 1);
// Grab the message that the standardWorkflow handled; and check the msgId.
// Should be removed from the static cache.
assertFalse(JettyAsyncWorkflowInterceptor.cacheContains(producer.getMessages().get(0).getUniqueId()));
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testStart_WithWait.
@Test
public void testStart_WithWait() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
EmbeddedConnection connection = new EmbeddedConnection();
connection.setMaxStartupWait(new TimeInterval(100L, TimeUnit.MILLISECONDS));
Channel channel = JettyHelper.createChannel(connection, JettyHelper.createConsumer(URL_TO_POST_TO), new MockMessageProducer());
try {
new Thread(() -> {
startQuietly(channel);
}).start();
LifecycleHelper.waitQuietly(250L);
helper.startServer();
LifecycleHelper.waitQuietly(600L);
assertEquals(StartedState.getInstance(), channel.retrieveComponentState());
} finally {
LifecycleHelper.stopAndClose(channel);
helper.stopServer();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.
@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
helper.startServer();
MockMessageProducer mockProducer = new StaticMockMessageProducer();
mockProducer.getMessages().clear();
JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
PoolingWorkflow workflow = new PoolingWorkflow();
workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
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));
Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), workflow);
try {
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(helper.createProduceDestination());
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
// Because of redmineID #4715 it should just "return immediatel" which flushes the stream so there's no content.
assertEquals("Reply Payloads", "", reply.getContent());
} finally {
stop(httpProducer);
channel.requestClose();
helper.stopServer();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testBasicConsumeWorkflow_ConsumeDestinationContainsURL.
@Test
public void testBasicConsumeWorkflow_ConsumeDestinationContainsURL() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
helper.startServer();
MockMessageProducer mockProducer = new MockMessageProducer();
Channel channel = JettyHelper.createChannel(new EmbeddedConnection(), JettyHelper.createConsumer("http://localhost:8080" + URL_TO_POST_TO), mockProducer);
try {
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(channel);
channel.requestStart();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setUrl(helper.createProduceDestination());
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
} finally {
stop(httpProducer);
channel.requestClose();
helper.stopServer();
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class EmbeddedHttpConsumerTest method testBasicConsumeWorkflow_WithACL.
@Test
public void testBasicConsumeWorkflow_WithACL() throws Exception {
EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
helper.startServer();
MockMessageProducer mockProducer = new MockMessageProducer();
EmbeddedConnection embedded = new EmbeddedConnection();
ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
csh.setLoginService(hsl);
csh.setAuthenticator(new BasicAuthenticatorFactory());
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setMustAuthenticate(true);
securityConstraint.setRoles("user");
securityConstraint.setPaths(Arrays.asList("/"));
securityConstraint.setConstraintName(Constraint.__BASIC_AUTH);
csh.setSecurityConstraints(Arrays.asList(securityConstraint));
embedded.setSecurityHandler(csh);
Channel channel = JettyHelper.createChannel(embedded, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
try {
start(channel);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
httpProducer.setAuthenticator(new ConfiguredUsernamePassword("user", "password"));
httpProducer.setUrl(helper.createProduceDestination());
start(httpProducer);
AdaptrisMessage reply = httpProducer.request(msg);
assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
doAssertions(mockProducer);
} finally {
stop(httpProducer);
stop(channel);
helper.stopServer();
}
}
Aggregations