Search in sources :

Example 31 with DefaultMessageFactory

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

the class StandardMessageErrorDigestTest method testMBean_GetMessageDigestMultipleWorkflow.

@Test
public void testMBean_GetMessageDigestMultipleWorkflow() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    adapter.setMessageErrorDigester(new StandardMessageErrorDigester(getName()));
    Channel channel1 = createChannel("channel1");
    StandardWorkflow workflow1 = createWorkflow("workflow1");
    StandardWorkflow workflow2 = createWorkflow("workflow2");
    workflow1.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail1")));
    workflow2.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail2")));
    channel1.getWorkflowList().add(workflow1);
    channel1.getWorkflowList().add(workflow2);
    adapter.getChannelList().add(channel1);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName());
        StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class);
        workflow1.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow1"));
        workflow2.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow2"));
        // They should have failed.
        assertNotNull(errDigester.getDigest());
        assertEquals(2, errDigester.getDigest().size());
        assertEquals(2, errDigester.getTotalErrorCount());
        MessageDigestErrorEntry entry1 = errDigester.getDigest().get(0);
        MessageDigestErrorEntry entry2 = errDigester.getDigest().get(1);
        assertEquals("workflow1@channel1", entry1.getWorkflowId());
        assertEquals("workflow2@channel1", entry2.getWorkflowId());
    } finally {
        stop(adapter);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) StandardWorkflow(com.adaptris.core.StandardWorkflow) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Channel(com.adaptris.core.Channel) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 32 with DefaultMessageFactory

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

the class StopProcessingServiceTest method testService.

@Test
public void testService() throws Exception {
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage();
    execute(new StopProcessingService(), msg);
    assertEquals("Stop processing", CoreConstants.STOP_PROCESSING_VALUE, msg.getMetadataValue(CoreConstants.STOP_PROCESSING_KEY));
    assertEquals("Skip producer", CoreConstants.STOP_PROCESSING_VALUE, msg.getMetadataValue(CoreConstants.KEY_WORKFLOW_SKIP_PRODUCER));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 33 with DefaultMessageFactory

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

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

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

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