Search in sources :

Example 1 with ExactMatch

use of com.adaptris.core.http.client.ExactMatch in project interlok by adaptris.

the class StatusMatchTest method testExactMatch.

@Test
public void testExactMatch() throws Exception {
    ExactMatch match = new ExactMatch(200, "200 OK");
    assertEquals(200, match.getStatusCode());
    assertEquals("200 OK", match.getServiceId());
    assertEquals("200 OK", match.serviceId());
    assertTrue(match.matches(200));
    assertFalse(match.matches(201));
}
Also used : ExactMatch(com.adaptris.core.http.client.ExactMatch) Test(org.junit.Test)

Example 2 with ExactMatch

use of com.adaptris.core.http.client.ExactMatch in project interlok by adaptris.

the class BranchingHttpRequestServiceTest method testService_ExactMatch_WithError.

@Test
public void testService_ExactMatch_WithError() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock, "This is the reply body", HttpStatus.INTERNAL_ERROR_500);
    BranchingHttpRequestService service = new BranchingHttpRequestService(HttpHelper.createProduceDestination(c)).withDefaultServiceId("DefaultServiceId").withStatusMatches(new ExactMatch(500, "500 Server Error"), new ExactMatch(200, "200 OK")).withContentType("text/complicated");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        execute(service, msg);
        waitForMessages(mock, 1);
        assertEquals("This is the reply body", msg.getContent());
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertEquals(1, mock.messageCount());
    assertEquals("500 Server Error", msg.getNextServiceId());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ExactMatch(com.adaptris.core.http.client.ExactMatch) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 3 with ExactMatch

use of com.adaptris.core.http.client.ExactMatch in project interlok by adaptris.

the class BranchingHttpRequestServiceTest method testService_ExactMatch.

@Test
public void testService_ExactMatch() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock, getName());
    BranchingHttpRequestService service = new BranchingHttpRequestService(HttpHelper.createProduceDestination(c)).withDefaultServiceId("DefaultServiceId").withStatusMatches(new ExactMatch(500, "500 Server Error"), new ExactMatch(200, "200 OK")).withContentType("text/complicated");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        execute(service, msg);
        waitForMessages(mock, 1);
        assertEquals(getName(), msg.getContent());
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertEquals(1, mock.messageCount());
    assertEquals("200 OK", msg.getNextServiceId());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) ExactMatch(com.adaptris.core.http.client.ExactMatch) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 4 with ExactMatch

use of com.adaptris.core.http.client.ExactMatch in project interlok by adaptris.

the class BranchingHttpRequestServiceTest method createForExamples.

private BranchingHttpRequestService createForExamples() {
    BranchingHttpRequestService service = new BranchingHttpRequestService("http://myhost.com/url/to/get/data/from/or/post/data/to");
    service.setContentType("text/complicated");
    service.setDefaultServiceId("DefaultServiceId");
    service.setUniqueId("GetData");
    service.setMethod("GET");
    service.getStatusMatches().add(new RangeMatch(500, 599, "5XX Server Error"));
    service.getStatusMatches().add(new RangeMatch(200, 299, "2XX OK"));
    service.getStatusMatches().add(new ExactMatch(404, "Not Found"));
    service.getStatusMatches().add(new RangeMatch(400, 499, "4XX Client Error"));
    service.setAuthenticator(HttpRequestServiceTest.buildAuthenticator("username", "password"));
    return service;
}
Also used : ExactMatch(com.adaptris.core.http.client.ExactMatch) RangeMatch(com.adaptris.core.http.client.RangeMatch)

Aggregations

ExactMatch (com.adaptris.core.http.client.ExactMatch)4 Test (org.junit.Test)3 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)2 Channel (com.adaptris.core.Channel)2 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)2 RangeMatch (com.adaptris.core.http.client.RangeMatch)1