Search in sources :

Example 16 with ProduceException

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

the class FsMessageProducerTest method testProduceFileAlreadyExists_StandardWorker.

@Test
public void testProduceFileAlreadyExists_StandardWorker() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(true);
    fs.setFsWorker(new StandardWorker());
    fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File dir = new File(parentDir, subdir);
        start(fs);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
        msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
        dir.mkdirs();
        File targetFile = new File(dir, msg.getMetadataValue("targetFilename"));
        targetFile.createNewFile();
        fs.produce(msg);
        fail();
    } catch (ProduceException expected) {
    } finally {
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        stop(fs);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) StandardWorker(com.adaptris.fs.StandardWorker) File(java.io.File) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Example 17 with ProduceException

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

the class FsMessageProducerTest method testProduceWithNoCreateDirAndTempDir.

@Test
public void testProduceWithNoCreateDirAndTempDir() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    String tmpDir = new GuidGenerator().safeUUID();
    String tempDir = PROPERTIES.getProperty(BASE_TEMP_DIR) + "/" + tmpDir;
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(false);
    fs.setTempDirectory(tempDir);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    File tmpParentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_TEMP_DIR), true));
    try {
        start(fs);
        fs.produce(new DefaultMessageFactory().newMessage(TEXT));
        fail();
    } catch (ProduceException expected) {
    } finally {
        stop(fs);
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        FileUtils.deleteQuietly(new File(tmpParentDir, tmpDir));
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Example 18 with ProduceException

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

the class OnMessageHandlerTest method testOnMessageHandlerSuccessTransactedRollback.

@Test
public void testOnMessageHandlerSuccessTransactedRollback() throws Exception {
    when(mockSession.getTransacted()).thenReturn(true);
    doThrow(new ProduceException("Expected")).when(mockProducer).produce(any());
    when(mockProducer.createName()).thenReturn("name");
    when(mockProducer.createQualifier()).thenReturn("Qualifier");
    when(mockProducer.isTrackingEndpoint()).thenReturn(false);
    JmsTransactedWorkflow jmsTransactedWorkflow = new JmsTransactedWorkflow();
    jmsTransactedWorkflow.setConsumer(new NullMessageConsumer());
    jmsTransactedWorkflow.setProducer(mockProducer);
    jmsTransactedWorkflow.registerChannel(mockChannel);
    config.setCorrelationIdSource(mockCorrelationSourceId);
    config.setMessageTranslator(mockTranslator);
    config.registerAdaptrisMessageListener(jmsTransactedWorkflow);
    handler = new OnMessageHandler(config);
    handler.onMessage(jmsMessage);
    verify(mockSession).rollback();
}
Also used : ProduceException(com.adaptris.core.ProduceException) NullMessageConsumer(com.adaptris.core.NullMessageConsumer) Test(org.junit.Test)

Example 19 with ProduceException

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

the class JmsAsyncProducerTest method testExceptionThrown.

@Test
public void testExceptionThrown() throws Exception {
    doThrow(new JMSException("expected")).when(mockMessageProducer).send(any(), any(), any());
    try {
        producer.setPerMessageProperties(false);
        producer.produce(adaptrisMessage, mockJmsDestination);
        fail("Should throw produce exception");
    } catch (ProduceException ex) {
    // expected
    }
}
Also used : JMSException(javax.jms.JMSException) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Example 20 with ProduceException

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

the class ExceptionHelperTest method testRethrowProduceExceptionThrowable.

@Test
public void testRethrowProduceExceptionThrowable() {
    Exception c1 = new Exception();
    try {
        rethrowProduceException(c1);
        fail();
    } catch (ProduceException e) {
        assertEquals(c1, e.getCause());
    }
    ProduceException c2 = new ProduceException();
    try {
        rethrowProduceException(c2);
        fail();
    } catch (ProduceException e) {
        assertEquals(c2, e);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) ProduceException(com.adaptris.core.ProduceException) ServiceException(com.adaptris.core.ServiceException) InterlokException(com.adaptris.interlok.InterlokException) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Aggregations

ProduceException (com.adaptris.core.ProduceException)29 Test (org.junit.Test)17 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)13 CoreException (com.adaptris.core.CoreException)9 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)7 Channel (com.adaptris.core.Channel)6 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 IOException (java.io.IOException)6 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)5 File (java.io.File)5 GuidGenerator (com.adaptris.util.GuidGenerator)4 JMSException (javax.jms.JMSException)4 PtpProducer (com.adaptris.core.jms.PtpProducer)3 MockChannel (com.adaptris.core.stubs.MockChannel)3 InputStream (java.io.InputStream)3 Destination (javax.jms.Destination)3 FileNameCreator (com.adaptris.core.FileNameCreator)2 MetadataElement (com.adaptris.core.MetadataElement)2 MetadataFileNameCreator (com.adaptris.core.MetadataFileNameCreator)2 ServiceException (com.adaptris.core.ServiceException)2