use of com.adaptris.util.GuidGenerator 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.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithOverride.
@Test
public void testProduceWithOverride() throws Exception {
String subdir = new GuidGenerator().safeUUID();
String override = new GuidGenerator().safeUUID();
FsProducer producer = createProducer(subdir);
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
producer.setBaseDirectoryUrl(PROPERTIES.getProperty(BASE_KEY) + "/" + override);
start(producer);
producer.produce(new DefaultMessageFactory().newMessage(TEXT));
assertNull(new File(parentDir, subdir).listFiles());
assertEquals(1, new File(parentDir, override).listFiles().length);
} finally {
stop(producer);
FileUtils.deleteQuietly(new File(parentDir, subdir));
FileUtils.deleteQuietly(new File(parentDir, override));
}
}
use of com.adaptris.util.GuidGenerator 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.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testProduce.
@Test
public void testProduce() throws Exception {
String subdir = new GuidGenerator().safeUUID();
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
StandaloneProducer sp = new StandaloneProducer(createProducer(subdir));
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(sp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
ServiceCase.execute(sp, msg);
assertEquals(1, dir.listFiles().length);
assertTrue(msg.containsKey(CoreConstants.FS_PRODUCE_DIRECTORY));
assertTrue(msg.containsKey(CoreConstants.PRODUCED_NAME_KEY));
assertEquals(dir.getCanonicalPath(), msg.getMetadataValue(CoreConstants.FS_PRODUCE_DIRECTORY));
assertEquals(msg.getUniqueId(), msg.getMetadataValue(CoreConstants.PRODUCED_NAME_KEY));
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
}
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class FsConsumerCase method testSetFileFilterImp.
@Test
public void testSetFileFilterImp() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsConsumerImpl consumer = createConsumer(subdir);
consumer.setFilterExpression(".*");
assertNull(consumer.getFileFilterImp());
assertEquals(org.apache.commons.io.filefilter.RegexFileFilter.class.getCanonicalName(), consumer.fileFilterImp());
try {
try {
LifecycleHelper.init(consumer);
} catch (CoreException e) {
fail("Exception calling init with valid FileFilter " + e);
}
// test creation of file filter imp...
consumer.setFileFilterImp(Perl5FilenameFilter.class.getName());
assertEquals(Perl5FilenameFilter.class.getName(), consumer.getFileFilterImp());
assertEquals(Perl5FilenameFilter.class.getName(), consumer.fileFilterImp());
try {
LifecycleHelper.init(consumer);
} catch (CoreException e) {
fail("Exception calling init with valid FileFilter " + e);
} finally {
LifecycleHelper.close(consumer);
}
// test creation of invalid FF Imp
consumer.setFileFilterImp("com.class.does.not.exist.FileFilter");
assertEquals("com.class.does.not.exist.FileFilter", consumer.getFileFilterImp());
assertEquals("com.class.does.not.exist.FileFilter", consumer.fileFilterImp());
try {
LifecycleHelper.init(consumer);
fail("Calling init with invalid FileFilter ");
} catch (CoreException e) {
} finally {
LifecycleHelper.close(consumer);
}
} finally {
FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
}
}
Aggregations