Search in sources :

Example 61 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testSetCreateDirs.

@Test
public void testSetCreateDirs() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    try {
        FsConsumerImpl fs = createConsumer(subdir);
        fs.setCreateDirs(null);
        assertNull(fs.getCreateDirs());
        assertFalse(fs.shouldCreateDirs());
        fs.setCreateDirs(Boolean.TRUE);
        assertNotNull(fs.getCreateDirs());
        assertEquals(Boolean.TRUE, fs.getCreateDirs());
        assertTrue(fs.shouldCreateDirs());
    } finally {
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 62 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testFileSorter.

@Test
public void testFileSorter() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsConsumerImpl consumer = createConsumer(subdir);
    assertEquals(NoSorting.class, consumer.getFileSorter().getClass());
    consumer.setFileSorter(new LastModifiedAscending());
    assertEquals(LastModifiedAscending.class, consumer.getFileSorter().getClass());
    try {
        consumer.setFileSorter(null);
        fail();
    } catch (Exception expected) {
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) CoreException(com.adaptris.core.CoreException) LastModifiedAscending(com.adaptris.core.fs.enhanced.LastModifiedAscending) Test(org.junit.Test)

Example 63 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FsConsumerCase method testSetLogAllExceptions.

@Test
public void testSetLogAllExceptions() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    try {
        FsConsumerImpl fs = createConsumer(subdir);
        fs.setLogAllExceptions(null);
        assertNull(fs.getLogAllExceptions());
        assertTrue(fs.logAllExceptions());
        fs.setLogAllExceptions(Boolean.FALSE);
        assertNotNull(fs.getLogAllExceptions());
        assertEquals(Boolean.FALSE, fs.getLogAllExceptions());
        assertFalse(fs.logAllExceptions());
    } finally {
        FileUtils.deleteQuietly(new File(PROPERTIES.getProperty(BASE_KEY), subdir));
    }
}
Also used : GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 64 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class FtpCase method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.setWorkDirectory(DEFAULT_WORK_DIR);
    ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
    ftpConsumer.setFilterExpression(".txt");
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
    start(sc);
    int count = 1;
    try {
        FtpProducer ftpProducer = createFtpProducer();
        MetadataFileNameCreator mfc = new MetadataFileNameCreator();
        mfc.setDefaultName(new GuidGenerator().getUUID() + ".txt");
        mfc.setMetadataKey(new GuidGenerator().getUUID());
        ftpProducer.setFilenameCreator(mfc);
        produce(new StandaloneProducer(createConnection(), ftpProducer), count);
        Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> listener.getMessages().size() >= count);
        assertMessages(listener.getMessages(), count);
    } finally {
        stop(sc);
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) GlobFilenameFilter(org.apache.oro.io.GlobFilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 65 with GuidGenerator

use of com.adaptris.util.GuidGenerator in project interlok by adaptris.

the class NonDeletingFsConsumerTest method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithFilter");
    fs.setFilterExpression(".*\\.xml");
    fs.setFileFilterImp(Perl5FilenameFilter.class.getName());
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        createFiles(baseDir, ".tmp", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.tmp");
        assertEquals("TMP Files remain", count, baseDir.listFiles((FilenameFilter) wip).length);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) 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