Search in sources :

Example 71 with GuidGenerator

use of com.adaptris.util.GuidGenerator 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 72 with GuidGenerator

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

the class FsMessageProducerTest method testProduceWithNoCreateDir.

@Test
public void testProduceWithNoCreateDir() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    FsProducer fs = createProducer(subdir);
    fs.setCreateDirs(false);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        start(fs);
        fs.produce(new DefaultMessageFactory().newMessage(TEXT));
        fail();
    } catch (ProduceException expected) {
    } finally {
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        stop(fs);
    }
}
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 73 with GuidGenerator

use of com.adaptris.util.GuidGenerator 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 74 with GuidGenerator

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

the class MovingDeletingFsConsumerTest method testConsume.

@Test
public void testConsume() throws Exception {
    final File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    final String subDir = new GuidGenerator().safeUUID();
    final File baseDir = new File(parentDir, subDir);
    final File procDir = new File(parentDir, "proc");
    final MockMessageListener stub = new MockMessageListener(10);
    final MovingNonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    fs.setProcessedPath(procDir.getAbsolutePath());
    final StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    final int count = 10;
    List<File> files = null;
    try {
        LifecycleHelper.init(sc);
        files = createFiles(baseDir, ".xml", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } catch (final Exception e) {
        log.warn(e.getMessage(), e);
        fail();
    } finally {
        stop(sc);
        if (files != null) {
            for (final File f : files) {
                boolean found = false;
                for (final String n : procDir.list()) {
                    if (f.getName().equals(n)) {
                        found = true;
                    }
                }
                if (!found) {
                    fail("Couldn't find file " + f.getName() + " in processed directory");
                }
            }
        }
        FileUtils.deleteQuietly(baseDir);
        FileUtils.deleteQuietly(procDir);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) IOException(java.io.IOException) FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 75 with GuidGenerator

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

the class MultiPayloadMessageSplitterTest method testNonCloneableMessage.

@Test
@SuppressWarnings("serial")
public void testNonCloneableMessage() {
    List<AdaptrisMessage> response = (List<AdaptrisMessage>) splitter.splitMessage(new MultiPayloadAdaptrisMessageImp("bacon", new GuidGenerator(), DefaultMessageFactory.getDefaultInstance(), PAYLOAD_1.getBytes()) {

        @Override
        public MessageLifecycleEvent getMessageLifecycleEvent() {
            return new MessageLifecycleEvent() {

                @Override
                public List<MleMarker> getMleMarkers() {
                    List<MleMarker> list = new ArrayList<>();
                    list.add(new MleMarker() {

                        @Override
                        public Object clone() throws CloneNotSupportedException {
                            throw new CloneNotSupportedException();
                        }
                    });
                    return list;
                }
            };
        }
    });
    assertEquals(0, response.size());
}
Also used : MultiPayloadAdaptrisMessageImp(com.adaptris.core.MultiPayloadAdaptrisMessageImp) MessageLifecycleEvent(com.adaptris.core.MessageLifecycleEvent) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GuidGenerator(com.adaptris.util.GuidGenerator) MleMarker(com.adaptris.core.MleMarker) 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