use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class ResponseHeaderAsObjectMetadataTest method testAddMetadata.
@Test
public void testAddMetadata() {
List<String> allow = Arrays.asList("GET", "HEAD", "OPTIONS");
Map<String, List<String>> headers = new HashMap<>();
headers.put("Allow", allow);
headers.put("Content-Type", Arrays.asList("text/xml"));
ResponseHeadersAsObjectMetadata handler = new ResponseHeadersAsObjectMetadata("");
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
handler.addMetadata(headers, msg);
assertNotNull(msg.getObjectHeaders().get("Allow"));
assertNotNull(((URLConnectionHeaderField) msg.getObjectHeaders().get("Allow")).getKey());
assertEquals("Allow", ((URLConnectionHeaderField) msg.getObjectHeaders().get("Allow")).getKey());
assertTrue(((URLConnectionHeaderField) msg.getObjectHeaders().get("Allow")).getValues().contains("HEAD"));
}
use of com.adaptris.core.AdaptrisMessage 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.AdaptrisMessage 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.AdaptrisMessage in project interlok by adaptris.
the class JettyRouteConditionTest method testEvaluate_NoMetadata.
@Test
public void testEvaluate_NoMetadata() throws Exception {
JettyRouteCondition condition = LifecycleHelper.initAndStart(new JettyRouteCondition().withMethod("POST").withUrlPattern(ALT_REGEX_WITHOUT_GROUP));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata(JettyConstants.JETTY_URI, URI);
msg.addMetadata(CoreConstants.HTTP_METHOD, "POST");
assertTrue(condition.evaluate(msg));
}
use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.
the class JettyRouteConditionTest method testEvaluate_NoMatch_METHOD.
@Test
public void testEvaluate_NoMatch_METHOD() throws Exception {
JettyRouteCondition condition = LifecycleHelper.initAndStart(new JettyRouteCondition().withMetadataKeys(RECORD_ID).withMethod("GET").withUrlPattern(REGEX_WITH_GROUP));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata(JettyConstants.JETTY_URI, URI);
msg.addMetadata(CoreConstants.HTTP_METHOD, "POST");
assertFalse(condition.evaluate(msg));
}
Aggregations