Search in sources :

Example 1 with OverwriteIfExistsWorker

use of com.adaptris.fs.OverwriteIfExistsWorker in project interlok by adaptris.

the class FsMessageProducerTest method testSetFsWorker.

@Test
public void testSetFsWorker() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer producer = createProducer(subdir);
    assertEquals(NioWorker.class, producer.getFsWorker().getClass());
    OverwriteIfExistsWorker worker = new OverwriteIfExistsWorker();
    producer.setFsWorker(worker);
    assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
    assertEquals(worker, producer.getFsWorker());
    try {
        producer.setFsWorker(null);
        fail();
    } catch (IllegalArgumentException | NullPointerException expected) {
    }
    assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
    assertEquals(worker, producer.getFsWorker());
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) OverwriteIfExistsWorker(com.adaptris.fs.OverwriteIfExistsWorker) Test(org.junit.Test)

Example 2 with OverwriteIfExistsWorker

use of com.adaptris.fs.OverwriteIfExistsWorker in project interlok by adaptris.

the class FsMessageProducerTest method testProduceFileAlreadyExists_OverwriteIfExists.

@Test
public void testProduceFileAlreadyExists_OverwriteIfExists() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(true);
    fs.setFsWorker(new OverwriteIfExistsWorker());
    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);
        assertEquals(1, dir.listFiles().length);
        assertEquals(OverwriteIfExistsWorker.class, fs.getFsWorker().getClass());
    } 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) OverwriteIfExistsWorker(com.adaptris.fs.OverwriteIfExistsWorker) File(java.io.File) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) Test(org.junit.Test)

Aggregations

OverwriteIfExistsWorker (com.adaptris.fs.OverwriteIfExistsWorker)2 GuidGenerator (com.adaptris.util.GuidGenerator)2 Test (org.junit.Test)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)1 MetadataFileNameCreator (com.adaptris.core.MetadataFileNameCreator)1 File (java.io.File)1