Search in sources :

Example 21 with DefectiveMessageFactory

use of com.adaptris.core.stubs.DefectiveMessageFactory in project interlok by adaptris.

the class ZipAggregatorTest method testAggregate_BrokenOutput.

@Test(expected = CoreException.class)
public void testAggregate_BrokenOutput() throws Exception {
    ZipAggregator aggr = new ZipAggregator();
    AdaptrisMessage original = new DefectiveMessageFactory(WhenToBreak.OUTPUT).newMessage();
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage splitMsg1 = fac.newMessage("<document>hello</document>");
    splitMsg1.addMetadata(DEFAULT_FILENAME_METADATA, "xfile1.xml");
    AdaptrisMessage splitMsg2 = fac.newMessage("<document>world2</document>");
    splitMsg2.addMetadata(DEFAULT_FILENAME_METADATA, "file2.xml");
    AdaptrisMessage splitMsg3 = fac.newMessage("<document>world3</document>");
    splitMsg3.addMetadata(DEFAULT_FILENAME_METADATA, "xfile3.xml");
    AdaptrisMessage splitMsg4 = fac.newMessage("<document>world4</document>");
    splitMsg4.addMetadata(DEFAULT_FILENAME_METADATA, "file4.xml");
    AdaptrisMessage willBeIgnoredMsg = fac.newMessage("<document>world4</document>");
    aggr.joinMessage(original, Arrays.asList(splitMsg1, splitMsg2, splitMsg3, splitMsg4, willBeIgnoredMsg));
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 22 with DefectiveMessageFactory

use of com.adaptris.core.stubs.DefectiveMessageFactory in project interlok by adaptris.

the class AddValueToCacheTest method testDoService_WithError.

@Test
public void testDoService_WithError() throws Exception {
    AdaptrisMessage msg = new DefectiveMessageFactory(EnumSet.of(WhenToBreak.METADATA_GET)).newMessage("Hello World");
    msg.addMetadata("metadataKey", "value");
    Cache cache = createCacheInstanceForTests();
    AddValueToCache service = new AddValueToCache().withValueTranslator(new StringPayloadCacheTranslator()).withKey("%message{metadataKey}").withConnection(new CacheConnection().withCacheInstance(cache));
    try {
        start(service);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StringPayloadCacheTranslator(com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 23 with DefectiveMessageFactory

use of com.adaptris.core.stubs.DefectiveMessageFactory in project interlok by adaptris.

the class ReplaceFirstAggregatorTest method testAggregate_BrokenOutput.

@Test(expected = CoreException.class)
public void testAggregate_BrokenOutput() throws Exception {
    ReplaceWithFirstMessage aggr = createAggregatorForTests();
    aggr.setOverwriteMetadata(true);
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage original = new DefectiveMessageFactory(WhenToBreak.OUTPUT).newMessage("Goodbye");
    AdaptrisMessage splitMsg1 = fac.newMessage("short");
    AdaptrisMessage splitMsg2 = fac.newMessage("justShort");
    AdaptrisMessage splitMsg3 = fac.newMessage("ofSufficientLength");
    AdaptrisMessage splitMsg4 = fac.newMessage("tooSmall");
    aggr.joinMessage(original, Arrays.asList(splitMsg1, splitMsg2, splitMsg3, splitMsg4));
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 24 with DefectiveMessageFactory

use of com.adaptris.core.stubs.DefectiveMessageFactory in project interlok by adaptris.

the class BranchingHttpRequestServiceTest method testService_Error.

@Test
public void testService_Error() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    BranchingHttpRequestService service = new BranchingHttpRequestService(HttpHelper.createURL(c)).withContentType("text/complicated");
    AdaptrisMessage msg = new DefectiveMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        HttpHelper.stopChannelAndRelease(c);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Example 25 with DefectiveMessageFactory

use of com.adaptris.core.stubs.DefectiveMessageFactory in project interlok by adaptris.

the class InputOutputServiceTest method testService_BrokenOutput.

@Test
public void testService_BrokenOutput() throws Exception {
    AdaptrisMessage msg = new DefectiveMessageFactory(DefectiveMessageFactory.WhenToBreak.OUTPUT).newMessage("hello world");
    try {
        execute(new InputOutputService(), msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)26 Test (org.junit.Test)26 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)24 ServiceException (com.adaptris.core.ServiceException)13 CoreException (com.adaptris.core.CoreException)4 AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)2 Cache (com.adaptris.core.cache.Cache)2 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)2 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)2 InsertNode (com.adaptris.util.text.xml.InsertNode)2 JMSException (javax.jms.JMSException)2 Session (javax.jms.Session)2 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)2 Channel (com.adaptris.core.Channel)1 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)1 IgnoreOriginalMimeAggregator (com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator)1 ReplaceWithFirstMessage (com.adaptris.core.services.aggregator.ReplaceWithFirstMessage)1 CacheConnection (com.adaptris.core.services.cache.CacheConnection)1 StringPayloadCacheTranslator (com.adaptris.core.services.cache.translators.StringPayloadCacheTranslator)1 XpathMetadataServiceTest (com.adaptris.core.services.metadata.XpathMetadataServiceTest)1