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);
}
}
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));
}
}
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();
}
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
}
}
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);
}
}
Aggregations