Search in sources :

Example 46 with AdaptrisMessage

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"));
}
Also used : HashMap(java.util.HashMap) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) List(java.util.List) Test(org.junit.Test)

Example 47 with AdaptrisMessage

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());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 48 with AdaptrisMessage

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());
    }
}
Also used : StandaloneRequestor(com.adaptris.core.StandaloneRequestor) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 49 with AdaptrisMessage

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));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 50 with AdaptrisMessage

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));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40