Search in sources :

Example 86 with GuidGenerator

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);
    }
}
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 87 with GuidGenerator

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));
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 88 with GuidGenerator

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));
    }
}
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 89 with GuidGenerator

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));
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 90 with GuidGenerator

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));
    }
}
Also used : Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) CoreException(com.adaptris.core.CoreException) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Aggregations

GuidGenerator (com.adaptris.util.GuidGenerator)134 Test (org.junit.Test)120 File (java.io.File)91 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)61 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)30 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)27 TimeInterval (com.adaptris.util.TimeInterval)25 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)23 FilenameFilter (java.io.FilenameFilter)21 ArrayList (java.util.ArrayList)20 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)18 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 Properties (java.util.Properties)15 Adapter (com.adaptris.core.Adapter)14 CoreException (com.adaptris.core.CoreException)11 AdaptrisMarshaller (com.adaptris.core.AdaptrisMarshaller)9 ServiceException (com.adaptris.core.ServiceException)8 IOException (java.io.IOException)8