Search in sources :

Example 81 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class HttpRequestServiceTest 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(new Service[] { new PayloadFromTemplateService().withTemplate(TEXT), new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)) })));
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(c)).withMethod("GET");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("Hello World");
    try {
        start(c);
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        stop(c);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(TEXT, msg.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 82 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class MetadataRequestMethodProviderTest method testDefaultMethod.

@Test
public void testDefaultMethod() {
    MetadataRequestMethodProvider prov = new MetadataRequestMethodProvider("httpMethod");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    assertEquals(RequestMethod.POST, prov.getMethod(msg));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataRequestMethodProvider(com.adaptris.core.http.client.MetadataRequestMethodProvider) Test(org.junit.Test)

Example 83 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class MetadataRequestMethodProviderTest method testGetMethod_WithMetadata.

@Test
public void testGetMethod_WithMetadata() {
    MetadataRequestMethodProvider prov = new MetadataRequestMethodProvider("httpMethod");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    msg.addMetadata("httpMethod", "GET");
    assertEquals(RequestMethod.GET, prov.getMethod(msg));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataRequestMethodProvider(com.adaptris.core.http.client.MetadataRequestMethodProvider) Test(org.junit.Test)

Example 84 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class MetadataStatusProviderTest method testGetStatus_MissingMetadata_WithText.

@Test
public void testGetStatus_MissingMetadata_WithText() {
    MetadataStatusProvider prov = new MetadataStatusProvider("httpStatus", "httpStatusText");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    msg.addMetadata("httpStatusText", "Really Not OK");
    assertEquals(HttpURLConnection.HTTP_INTERNAL_ERROR, prov.getStatus(msg).getCode());
    assertNotSame("Internal Server Error", prov.getStatus(msg).getText());
    assertEquals("Really Not OK", prov.getStatus(msg).getText());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MetadataStatusProvider(com.adaptris.core.http.server.MetadataStatusProvider) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 85 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class MetadataStatusProviderTest method testGetStatus_WithMetadata.

@Test
public void testGetStatus_WithMetadata() {
    MetadataStatusProvider prov = new MetadataStatusProvider("httpStatus");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage("");
    msg.addMetadata("httpStatus", "200");
    assertEquals(HttpURLConnection.HTTP_OK, prov.getStatus(msg).getCode());
    assertEquals("OK", prov.getStatus(msg).getText());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MetadataStatusProvider(com.adaptris.core.http.server.MetadataStatusProvider) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)170 Test (org.junit.Test)163 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)158 Channel (com.adaptris.core.Channel)37 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 StandaloneProducer (com.adaptris.core.StandaloneProducer)27 ServiceException (com.adaptris.core.ServiceException)26 File (java.io.File)26 ServiceList (com.adaptris.core.ServiceList)18 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)18 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)18 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)18 GuidGenerator (com.adaptris.util.GuidGenerator)18 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)15 ValidationStage (com.adaptris.transform.validate.ValidationStage)15 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)12 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10