Search in sources :

Example 1 with StandardWorker

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

the class FsHelperTest method testRenameFile_AlreadyExists.

@Test
public void testRenameFile_AlreadyExists() throws Exception {
    File src = TempFileUtils.createTrackedFile(this);
    src.createNewFile();
    File wipFile = new File(src.getCanonicalPath() + ".wip");
    wipFile.createNewFile();
    TempFileUtils.trackFile(wipFile, this);
    File renamed = renameFile(src, ".wip", new StandardWorker());
    // Should have a timestamp addition.
    assertNotEquals(wipFile, renamed);
    assertFalse(src.exists());
    assertTrue(wipFile.exists());
    assertTrue(renamed.exists());
}
Also used : File(java.io.File) StandardWorker(com.adaptris.fs.StandardWorker) Test(org.junit.Test)

Example 2 with StandardWorker

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

the class FsHelperTest method testRenameFile.

@Test
public void testRenameFile() throws Exception {
    FsWorker worker = new StandardWorker();
    File src = TempFileUtils.createTrackedFile(this);
    src.createNewFile();
    File renamed = renameFile(src, ".wip", new StandardWorker());
    assertTrue(renamed.exists());
    assertFalse(src.exists());
}
Also used : FsWorker(com.adaptris.fs.FsWorker) StandardWorker(com.adaptris.fs.StandardWorker) File(java.io.File) Test(org.junit.Test)

Example 3 with StandardWorker

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

the class FsMessageProducerTest method testProduceFileAlreadyExists_AppendingFsWorker.

@Test
public void testProduceFileAlreadyExists_AppendingFsWorker() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(true);
    fs.setFsWorker(new AppendingFsWorker());
    fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
    FsWorker fsWorker = new StandardWorker();
    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"));
        fsWorker.put(TEXT.getBytes(), targetFile);
        fs.produce(msg);
        assertEquals(1, dir.listFiles().length);
        assertEquals(AppendingFsWorker.class, fs.getFsWorker().getClass());
        assertEquals(TEXT + TEXT, new String(fsWorker.get(targetFile)));
    } 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) FsWorker(com.adaptris.fs.FsWorker) AppendingFsWorker(com.adaptris.fs.AppendingFsWorker) StandardWorker(com.adaptris.fs.StandardWorker) File(java.io.File) AppendingFsWorker(com.adaptris.fs.AppendingFsWorker) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) Test(org.junit.Test)

Example 4 with StandardWorker

use of com.adaptris.fs.StandardWorker 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)

Aggregations

StandardWorker (com.adaptris.fs.StandardWorker)4 File (java.io.File)4 Test (org.junit.Test)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)2 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 MetadataFileNameCreator (com.adaptris.core.MetadataFileNameCreator)2 FsWorker (com.adaptris.fs.FsWorker)2 GuidGenerator (com.adaptris.util.GuidGenerator)2 ProduceException (com.adaptris.core.ProduceException)1 AppendingFsWorker (com.adaptris.fs.AppendingFsWorker)1