Search in sources :

Example 96 with GuidGenerator

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

the class TraversingFsConsumerTest method testConsume_WithFilter.

@Test
public void testConsume_WithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setFilterExpression(".*xml");
    fs.setReacquireLockBetweenMessages(true);
    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);
        start(sc);
        createFiles(baseDir, ".xml", count);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count);
    } finally {
        stop(sc);
        File baseDir = new File(parentDir, subDir);
    }
}
Also used : 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) File(java.io.File) Test(org.junit.Test)

Example 97 with GuidGenerator

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

the class TraversingFsConsumerTest method testConsume.

@Test
public void testConsume() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    FsConsumer fs = createConsumer(subDir);
    fs.setReacquireLockBetweenMessages(true);
    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);
        start(sc);
        createFiles(baseDir, ".xml", count);
        waitForMessages(stub, count);
        assertMessages(stub.getMessages(), count);
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : 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) File(java.io.File) Test(org.junit.Test)

Example 98 with GuidGenerator

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

the class TraversingFsConsumerTest method createDirectoryTree.

private File createDirectoryTree(File baseDir) {
    File result = baseDir;
    int i = new Random().nextInt(20);
    switch(i % 3) {
        case 0:
            result = createDirectoryTree(new File(baseDir, new GuidGenerator().safeUUID()));
            break;
        case 1:
            result = new File(baseDir, new GuidGenerator().safeUUID());
            break;
        default:
            result = baseDir;
            break;
    }
    return result;
}
Also used : Random(java.util.Random) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File)

Example 99 with GuidGenerator

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

the class AggregatingFsConsumeServiceTest method testService_MultipleMessages.

@Test
public void testService_MultipleMessages() throws Exception {
    GuidGenerator o = new GuidGenerator();
    File tempDir = TempFileUtils.createTrackedDir(o);
    String url = "file://localhost/" + tempDir.getCanonicalPath().replaceAll("\\\\", "/");
    AggregatingFsConsumer afc = createConsumer(url, ".*", new IgnoreOriginalMimeAggregator());
    AggregatingFsConsumeService service = createAggregatingService(afc);
    try {
        writeDataMessage(tempDir, o.safeUUID());
        writeDataMessage(tempDir, o.safeUUID());
        start(service);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
        service.doService(msg);
        BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
        assertEquals(2, input.size());
    } finally {
        stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) IgnoreOriginalMimeAggregator(com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 100 with GuidGenerator

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

the class DynamicServiceExecutorTest method createMimeMessage.

public static AdaptrisMessage createMimeMessage(Service s, String encoding) throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String xml = DefaultMarshaller.getDefaultMarshaller().marshal(s);
    MultiPartOutput output = new MultiPartOutput(new GuidGenerator().getUUID());
    output.getMimeHeader().addHeader("Subject", "This is the Subject");
    output.addPart(xml, encoding, "Service");
    output.addPart("pack my jug with a dozen liquor jugs", encoding, "part2");
    try (OutputStream out = msg.getOutputStream()) {
        output.writeTo(out);
    }
    return msg;
}
Also used : MultiPartOutput(com.adaptris.util.text.mime.MultiPartOutput) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) OutputStream(java.io.OutputStream) GuidGenerator(com.adaptris.util.GuidGenerator)

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