Search in sources :

Example 16 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_NoFile.

@Test
public void testService_NoFile() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    ReadMetadataFromFilesystem service = createService(subDir);
    execute(service, msg);
    assertFalse(msg.headersContainsKey("key5"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 17 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_DoNotOverwriteExistingMetadata.

@Test
public void testService_DoNotOverwriteExistingMetadata() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    msg.addMetadata("key5", "MyValue");
    ReadMetadataFromFilesystem service = createService(subDir);
    service.setOverwriteExistingMetadata(false);
    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);
    execute(service, msg);
    assertTrue(msg.headersContainsKey("key5"));
    assertEquals("MyValue", 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 18 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_OverwriteExistingMetadata.

@Test
public void testService_OverwriteExistingMetadata() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    msg.addMetadata("key5", "MyValue");
    ReadMetadataFromFilesystem service = createService(subDir);
    service.setOverwriteExistingMetadata(true);
    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);
    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 19 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_InputXml.

@Test
public void testService_InputXml() throws Exception {
    String subDir = new GuidGenerator().getUUID().replaceAll(":", "").replaceAll("-", "");
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    ReadMetadataFromFilesystem service = createService(subDir);
    service.setInputStyle(InputStyle.XML);
    service.setFilenameCreator(new FormattedFilenameCreator());
    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), true);
    execute(service, msg);
    assertTrue(msg.headersContainsKey("key5"));
    assertEquals("v5", msg.getMetadataValue("key5"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) FormattedFilenameCreator(com.adaptris.core.FormattedFilenameCreator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 20 with GuidGenerator

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

the class ReadMetadataFromFilesystemTest method testService_Default.

@Test
public void testService_Default() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    ReadMetadataFromFilesystem service = createService(subDir);
    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);
    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)

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