use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_WithEncoder.
@Test
public void testProduce_WithEncoder() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
stdHttp.setEncoder(new UrlConnectionEncoder());
StandaloneProducer producer = new StandaloneProducer(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
c.requestStart();
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals(TEXT, m2.getContent());
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class StandardHttpProducerTest method testProduce_MetadataRequestHeaders.
@Test
public void testProduce_MetadataRequestHeaders() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
stdHttp.setRequestHeaderProvider(new MetadataRequestHeaders(new RegexMetadataFilter()));
StandaloneProducer producer = new StandaloneProducer(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata(getName(), getName());
try {
c.requestStart();
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(producer);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertTrue(m2.headersContainsKey(getName()));
assertEquals(getName(), m2.getMetadataValue(getName()));
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_DeleteMethod_AlwaysSendPayload.
@Test
public void testRequest_DeleteMethod_AlwaysSendPayload() 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()));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.DELETE));
stdHttp.setRequestBody(new PayloadStreamInputParameter());
stdHttp.setAlwaysSendPayload(true);
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
stop(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("DELETE", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(ALT_TEXT, m2.getContent());
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class StandardHttpProducerTest method testProduceWithAuthorizationHeader.
@Test
public void testProduceWithAuthorizationHeader() throws Exception {
MockMessageProducer mock = new MockMessageProducer();
Channel c = HttpHelper.createAndStartChannel(mock);
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
ConfiguredAuthorizationHeader authenticator = new ConfiguredAuthorizationHeader();
authenticator.setHeaderValue("some value");
stdHttp.setAuthenticator(authenticator);
StandaloneProducer producer = new StandaloneProducer(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
try {
c.requestStart();
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
HttpHelper.stopChannelAndRelease(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertTrue(m2.headersContainsKey(HttpConstants.AUTHORIZATION));
assertEquals("some value", m2.getMetadataValue(HttpConstants.AUTHORIZATION));
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class StandardHttpProducerTest method testRequest_GetMethod_NonZeroBytes.
@Test
public void testRequest_GetMethod_NonZeroBytes() 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()));
StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
;
stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
try {
start(c);
start(producer);
producer.doService(msg);
waitForMessages(mock, 1);
} finally {
stop(c);
stop(producer);
}
assertEquals(1, mock.messageCount());
AdaptrisMessage m2 = mock.getMessages().get(0);
assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
assertEquals(0, m2.getSize());
}
Aggregations