Search in sources :

Example 1 with DefectiveMessageFactory

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

the class BytesMessageTranslatorTest method testBytesMessageToAdaptrisMessage_StreamFailure.

@Test
public void testBytesMessageToAdaptrisMessage_StreamFailure() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        BytesMessage jmsMsg = createMessage(session);
        jmsMsg.writeBytes(TEXT.getBytes());
        start(trans, session);
        trans.registerMessageFactory(new DefectiveMessageFactory());
        jmsMsg.reset();
        try {
            trans.translate(jmsMsg);
            fail();
        } catch (JMSException expected) {
        }
    } finally {
        stop(trans);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with DefectiveMessageFactory

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

the class BytesMessageTranslatorTest method testAdaptrisMessageToBytesMessage_StreamFailure.

@Test
public void testAdaptrisMessageToBytesMessage_StreamFailure() throws Exception {
    BytesMessageTranslator trans = new BytesMessageTranslator() {

        @Override
        long streamThreshold() {
            return TEXT.length() - 1;
        }
    };
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);
        AdaptrisMessage msg = new DefectiveMessageFactory().newMessage(TEXT);
        addMetadata(msg);
        try {
            trans.translate(msg);
            fail();
        } catch (JMSException expected) {
        }
    } finally {
        stop(trans);
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with DefectiveMessageFactory

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

the class GzipServiceTest method testZipServiceFailure.

@Test
public void testZipServiceFailure() throws Exception {
    AdaptrisMessage msg = new DefectiveMessageFactory().newMessage(LINE, "UTF-8");
    try {
        execute(new GzipService(), 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)

Example 4 with DefectiveMessageFactory

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

the class InputOutputServiceTest method testService_BrokenInput.

@Test
public void testService_BrokenInput() throws Exception {
    AdaptrisMessage msg = new DefectiveMessageFactory(DefectiveMessageFactory.WhenToBreak.INPUT).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)

Example 5 with DefectiveMessageFactory

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

the class RemoveKeyFromCacheTest 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();
    RemoveKeyFromCache service = new RemoveKeyFromCache().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) Cache(com.adaptris.core.cache.Cache) 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