Search in sources :

Example 1 with RangeMatch

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

the class BranchingHttpRequestServiceTest method testService_RangeMatch.

@Test
public void testService_RangeMatch() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    BranchingHttpRequestService service = new BranchingHttpRequestService(HttpHelper.createProduceDestination(c)).withDefaultServiceId("DefaultServiceId").withStatusMatches(new RangeMatch(100, 199, "1XX Informational"), new RangeMatch(300, 399, "3XX Moved"), new RangeMatch(200, 299, "2XX OK")).withContentType("text/complicated");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
    assertEquals(1, mock.messageCount());
    assertEquals("2XX OK", msg.getNextServiceId());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) RangeMatch(com.adaptris.core.http.client.RangeMatch) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 2 with RangeMatch

use of com.adaptris.core.http.client.RangeMatch 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)

Example 3 with RangeMatch

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

the class StatusMatchTest method testRangeMatch.

@Test
public void testRangeMatch() throws Exception {
    RangeMatch match = new RangeMatch(200, 299, "200 OK");
    assertEquals(200, match.getLower());
    assertEquals(299, match.getUpper());
    assertEquals("200 OK", match.getServiceId());
    assertEquals("200 OK", match.serviceId());
    assertTrue(match.matches(200));
    assertTrue(match.matches(201));
    assertFalse(match.matches(400));
    assertFalse(match.matches(300));
}
Also used : RangeMatch(com.adaptris.core.http.client.RangeMatch) Test(org.junit.Test)

Aggregations

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