Search in sources :

Example 16 with DefaultMessageFactory

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

the class HttpRequestServiceTest method testRequest_GetMethod_ZeroBytes.

@Test
public void testRequest_GetMethod_ZeroBytes() 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();
    try {
        start(c);
        execute(service, msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(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 17 with DefaultMessageFactory

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

the class FilesystemRetryStoreTest method testWrite_Exception.

@Test(expected = InterlokException.class)
public void testWrite_Exception() throws Exception {
    FilesystemRetryStore store = new FilesystemRetryStore().withBaseUrl(INVALID_URL);
    try {
        LifecycleHelper.initAndStart(store);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
        store.write(msg);
    } finally {
        LifecycleHelper.stopAndClose(store);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 18 with DefaultMessageFactory

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

the class FilesystemRetryStoreTest method testWrite_PayloadMetadataException.

@Test
public void testWrite_PayloadMetadataException() throws Exception {
    FilesystemRetryStore store = new FilesystemRetryStore().withBaseUrl(BaseCase.getConfiguration(TEST_BASE_URL));
    try {
        LifecycleHelper.initAndStart(store);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
        msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception());
        store.write(msg);
        File retryDir = FsHelper.toFile(BaseCase.getConfiguration(TEST_BASE_URL));
        File msgDir = new File(retryDir, msg.getUniqueId());
        assertTrue(retryDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY).length >= 1);
        assertTrue(msgDir.exists());
        assertEquals(3, msgDir.listFiles().length);
    } finally {
        LifecycleHelper.stopAndClose(store);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DirectoryFileFilter(org.apache.commons.io.filefilter.DirectoryFileFilter) FileFilter(java.io.FileFilter) File(java.io.File) InterlokException(com.adaptris.interlok.InterlokException) Test(org.junit.Test)

Example 19 with DefaultMessageFactory

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

the class FilesystemRetryStoreTest method testReport.

@Test
public void testReport() throws Exception {
    FilesystemRetryStore store = new FilesystemRetryStore().withBaseUrl(BaseCase.getConfiguration(TEST_BASE_URL));
    try {
        LifecycleHelper.initAndStart(store);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
        store.write(msg);
        assertTrue(store.report().iterator().hasNext());
    } finally {
        LifecycleHelper.stopAndClose(store);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 20 with DefaultMessageFactory

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

the class FilesystemRetryStoreTest method testGetMetadata.

@Test
public void testGetMetadata() throws Exception {
    FilesystemRetryStore store = new FilesystemRetryStore().withBaseUrl(BaseCase.getConfiguration(TEST_BASE_URL));
    try {
        LifecycleHelper.initAndStart(store);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage("hello");
        store.write(msg);
        Map<String, String> metadata = store.getMetadata(msg.getUniqueId());
        assertEquals(msg.getMessageHeaders(), metadata);
    } finally {
        LifecycleHelper.stopAndClose(store);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) 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