Search in sources :

Example 66 with DefaultMessageFactory

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

the class MessageTypeTranslatorCase method start.

public static void start(MessageTypeTranslatorImp trans, Session session) throws Exception {
    trans.registerSession(session);
    trans.registerMessageFactory(new DefaultMessageFactory());
    LifecycleHelper.init(trans);
    LifecycleHelper.start(trans);
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory)

Example 67 with DefaultMessageFactory

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

the class FsMessageProducerTest method testProduceWithTempDir.

@Test
public void testProduceWithTempDir() throws Exception {
    String subdir = new GuidGenerator().safeUUID();
    String tmpDir = new GuidGenerator().safeUUID();
    String tempDir = PROPERTIES.getProperty(BASE_TEMP_DIR) + "/" + tmpDir;
    FsProducer producer = createProducer(subdir);
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    File tmpParentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_TEMP_DIR), true));
    try {
        producer.setTempDirectory(tempDir);
        StandaloneProducer sp = new StandaloneProducer(producer);
        ServiceCase.execute(sp, new DefaultMessageFactory().newMessage(TEXT));
        File f = new File(tmpParentDir, tmpDir);
        assertTrue(f.exists());
        assertTrue(f.isDirectory());
        assertEquals(1, new File(parentDir, subdir).listFiles().length);
        assertEquals(0, new File(tmpParentDir, tmpDir).listFiles().length);
    } finally {
        FileUtils.deleteQuietly(new File(parentDir, subdir));
        FileUtils.deleteQuietly(new File(tmpParentDir, tmpDir));
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 68 with DefaultMessageFactory

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

the class AggregatingFsConsumeServiceTest method testService.

@Test
public void testService() throws Exception {
    Object o = new Object();
    File tempFile = TempFileUtils.createTrackedFile(o);
    String url = "file://localhost/" + tempFile.getCanonicalPath().replaceAll("\\\\", "/");
    AggregatingFsConsumer afc = createConsumer(url, null, new ReplaceWithFirstMessage());
    AggregatingFsConsumeService service = createAggregatingService(afc);
    File wipFile = new File(tempFile.getParent(), tempFile.getName() + afc.wipSuffix());
    try {
        writeDataMessage(tempFile);
        start(service);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
        service.doService(msg);
        assertNotSame(INITIAL_PAYLOAD, msg.getContent());
        assertEquals(DATA_PAYLOAD, msg.getContent());
        assertFalse(tempFile.exists());
        assertFalse(wipFile.exists());
    } finally {
        stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) File(java.io.File) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 69 with DefaultMessageFactory

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

the class AggregatingFsConsumeServiceTest method testServiceNonDeleting.

@Test
public void testServiceNonDeleting() throws Exception {
    Object o = new Object();
    File tempFile = TempFileUtils.createTrackedFile(o);
    String url = "file://localhost/" + tempFile.getCanonicalPath().replaceAll("\\\\", "/");
    AggregatingFsConsumer afc = createConsumer(url, null, new ReplaceWithFirstMessage());
    afc.setDeleteAggregatedFiles(false);
    AggregatingFsConsumeService service = createAggregatingService(afc);
    File wipFile = new File(tempFile.getParent(), tempFile.getName() + afc.wipSuffix());
    try {
        writeDataMessage(tempFile);
        start(service);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
        service.doService(msg);
        assertNotSame(INITIAL_PAYLOAD, msg.getContent());
        assertEquals(DATA_PAYLOAD, msg.getContent());
        assertTrue(tempFile.exists());
        assertFalse(wipFile.exists());
    } finally {
        stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) File(java.io.File) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 70 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory 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)

Aggregations

DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)170 Test (org.junit.Test)163 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)158 Channel (com.adaptris.core.Channel)37 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 StandaloneProducer (com.adaptris.core.StandaloneProducer)27 ServiceException (com.adaptris.core.ServiceException)26 File (java.io.File)26 ServiceList (com.adaptris.core.ServiceList)18 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)18 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)18 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)18 GuidGenerator (com.adaptris.util.GuidGenerator)18 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)15 ValidationStage (com.adaptris.transform.validate.ValidationStage)15 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)12 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10