Search in sources :

Example 1 with MetadataFileNameCreator

use of com.adaptris.core.MetadataFileNameCreator 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 2 with MetadataFileNameCreator

use of com.adaptris.core.MetadataFileNameCreator 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)

Example 3 with MetadataFileNameCreator

use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.

the class FsMessageProducerTest method testProduceFileAlreadyExists_NioWorker.

@Test
public void testProduceFileAlreadyExists_NioWorker() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(true);
    fs.setFsWorker(new NioWorker());
    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) NioWorker(com.adaptris.fs.NioWorker) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) ProduceException(com.adaptris.core.ProduceException) Test(org.junit.Test)

Example 4 with MetadataFileNameCreator

use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.

the class FtpProducerTest method testSetFilenameCreator.

@Test
public void testSetFilenameCreator() throws Exception {
    FtpProducer ftpProducer = new FtpProducer();
    assertEquals(FormattedFilenameCreator.class, ftpProducer.filenameCreatorToUse().getClass());
    ftpProducer.setFilenameCreator(new MetadataFileNameCreator());
    assertEquals(MetadataFileNameCreator.class, ftpProducer.getFilenameCreator().getClass());
    assertEquals(MetadataFileNameCreator.class, ftpProducer.filenameCreatorToUse().getClass());
}
Also used : MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) Test(org.junit.Test)

Example 5 with MetadataFileNameCreator

use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.

the class RelaxedFtpProducerTest method testSetFilenameCreator.

@Test
public void testSetFilenameCreator() throws Exception {
    RelaxedFtpProducer ftpProducer = new RelaxedFtpProducer();
    assertEquals(FormattedFilenameCreator.class, ftpProducer.filenameCreator().getClass());
    ftpProducer.setFilenameCreator(new MetadataFileNameCreator());
    assertEquals(MetadataFileNameCreator.class, ftpProducer.getFilenameCreator().getClass());
    assertEquals(MetadataFileNameCreator.class, ftpProducer.filenameCreator().getClass());
}
Also used : MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) Test(org.junit.Test)

Aggregations

MetadataFileNameCreator (com.adaptris.core.MetadataFileNameCreator)9 Test (org.junit.Test)9 GuidGenerator (com.adaptris.util.GuidGenerator)7 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)5 File (java.io.File)5 ProduceException (com.adaptris.core.ProduceException)2 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)2 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)2 StandardWorker (com.adaptris.fs.StandardWorker)2 GlobFilenameFilter (org.apache.oro.io.GlobFilenameFilter)2 AppendingFsWorker (com.adaptris.fs.AppendingFsWorker)1 FsWorker (com.adaptris.fs.FsWorker)1 NioWorker (com.adaptris.fs.NioWorker)1 OverwriteIfExistsWorker (com.adaptris.fs.OverwriteIfExistsWorker)1 SafeGuidGenerator (com.adaptris.util.SafeGuidGenerator)1