Search in sources :

Example 6 with MetadataFileNameCreator

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

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

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

the class FsMessageProducerTest method testProduceWithMetadataFilenameCreator.

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

Example 9 with MetadataFileNameCreator

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

the class RelaxedFtpCase method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    if (areTestsEnabled()) {
        MockMessageListener listener = new MockMessageListener();
        RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
        ftpConsumer.setFtpEndpoint(getDestinationString());
        ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
        ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
        ftpConsumer.registerAdaptrisMessageListener(listener);
        ftpConsumer.setFilterExpression(".txt");
        ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
        StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
        start(sc);
        int count = 1;
        try {
            RelaxedFtpProducer 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);
            waitForMessages(listener, count);
            assertMessages(listener.getMessages(), count);
        } finally {
            stop(sc);
        }
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) GlobFilenameFilter(org.apache.oro.io.GlobFilenameFilter) SafeGuidGenerator(com.adaptris.util.SafeGuidGenerator) 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)

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