Search in sources :

Example 21 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_DestinationIsFile.

@Test
public void testService_DestinationIsFile() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_DIR), true));
    String propsFilename = parentDir.getCanonicalPath() + "/" + subDir + "/" + msg.getUniqueId();
    Properties p = createProperties();
    writeProperties(p, new File(propsFilename), false);
    ReadMetadataFromFilesystem service = createService(subDir + "/" + msg.getUniqueId());
    execute(service, msg);
    assertTrue(msg.headersContainsKey("key5"));
    assertEquals("v5", msg.getMetadataValue("key5"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 22 with GuidGenerator

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

the class SimpleSequenceNumberTest method testDoService_NumberFormatting.

@Test
public void testDoService_NumberFormatting() throws Exception {
    SimpleSequenceNumberService service = new SimpleSequenceNumberService();
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    String filename = new File(PROPERTIES.getProperty(KEY_BASEDIR), new GuidGenerator().getUUID()).getCanonicalPath();
    service.setSequenceNumberFile(filename);
    service.setNumberFormat(DEFAULT_NUMBER_FORMAT);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    execute(service, msg);
    assertEquals(2, getSequenceNumber(filename));
    assertTrue(msg.containsKey(DEFAULT_METADATA_KEY));
    assertEquals("000000001", msg.getMetadataValue(DEFAULT_METADATA_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 23 with GuidGenerator

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

the class SimpleSequenceNumberTest method testDoService_FileIsDirectory.

@Test
public void testDoService_FileIsDirectory() throws Exception {
    SimpleSequenceNumberService service = new SimpleSequenceNumberService();
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    File dir = new File(PROPERTIES.getProperty(KEY_BASEDIR), new GuidGenerator().getUUID());
    dir.mkdirs();
    service.setSequenceNumberFile(dir.getCanonicalPath());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 24 with GuidGenerator

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

the class SimpleSequenceNumberTest method testDoService_MetadataExistsOverwrite.

@Test
public void testDoService_MetadataExistsOverwrite() throws Exception {
    SimpleSequenceNumberService service = new SimpleSequenceNumberService();
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    String filename = new File(PROPERTIES.getProperty(KEY_BASEDIR), new GuidGenerator().getUUID()).getCanonicalPath();
    service.setSequenceNumberFile(filename);
    service.setAlwaysReplaceMetadata(Boolean.TRUE);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(DEFAULT_METADATA_KEY, "testDoService_MetadataExistsNoOverwrite");
    execute(service, msg);
    assertEquals(2, getSequenceNumber(filename));
    assertTrue(msg.containsKey(DEFAULT_METADATA_KEY));
    assertEquals("1", msg.getMetadataValue(DEFAULT_METADATA_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 25 with GuidGenerator

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

the class SimpleSequenceNumberTest method testDoService_FileExists.

@Test
public void testDoService_FileExists() throws Exception {
    SimpleSequenceNumberService service = new SimpleSequenceNumberService();
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    String filename = new File(PROPERTIES.getProperty(KEY_BASEDIR), new GuidGenerator().getUUID()).getCanonicalPath();
    createPropertyFile(filename, 5);
    service.setSequenceNumberFile(filename);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    execute(service, msg);
    assertEquals(6, getSequenceNumber(filename));
    assertTrue(msg.containsKey(DEFAULT_METADATA_KEY));
    assertEquals("5", msg.getMetadataValue(DEFAULT_METADATA_KEY));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) 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