Search in sources :

Example 56 with StandardWorkflow

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

the class WorkflowManagerTest method testInjectWithReply.

@Test
public void testInjectWithReply() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    workflow.getServiceCollection().add(new AddMetadataService(Arrays.asList(new MetadataElement(getName(), getName()))));
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableAdaptrisMessage msg = createSAM(msgUniqueId);
    try {
        register(mBeans);
        WorkflowManagerMBean workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, WorkflowManagerMBean.class);
        adapterManager.requestStart();
        SerializableAdaptrisMessage reply = (SerializableAdaptrisMessage) workflowManagerProxy.process(msg);
        assertEquals(msgUniqueId, reply.getUniqueId());
        assertEquals(PAYLOAD, reply.getContent());
        assertEquals(PAYLOAD_ENCODING, reply.getContentEncoding());
        assertTrue(reply.containsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, reply.getMetadataValue(METADATA_KEY));
        assertTrue(reply.containsKey(getName()));
        assertEquals(getName(), reply.getMetadataValue(getName()));
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) MetadataElement(com.adaptris.core.MetadataElement) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) ObjectName(javax.management.ObjectName) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 57 with StandardWorkflow

use of com.adaptris.core.StandardWorkflow 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 58 with StandardWorkflow

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

the class WorkflowManagerTest method testProcessAsync.

@Test
public void testProcessAsync() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    AdapterManager adapterManager = new AdapterManager(adapter);
    Channel channel = createChannel("c1");
    ChannelManager channelManager = new ChannelManager(channel, adapterManager);
    StandardWorkflow workflow = createWorkflow("w1");
    MockMessageProducer mockProducer = new MockMessageProducer();
    workflow.setProducer(mockProducer);
    WorkflowManager realWorkflowManager = new WorkflowManager(workflow, channelManager);
    adapterManager.createObjectName();
    ObjectName workflowObj = realWorkflowManager.createObjectName();
    channelManager.createObjectName();
    List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
    mBeans.add(adapterManager);
    mBeans.addAll(adapterManager.getAllDescendants());
    String msgUniqueId = new GuidGenerator().getUUID();
    SerializableMessage msg = createSM(msgUniqueId);
    try {
        register(mBeans);
        MessageProcessor workflowManagerProxy = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        adapterManager.requestStart();
        workflowManagerProxy.processAsync(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage procMsg = mockProducer.getMessages().get(0);
        assertEquals(msgUniqueId, procMsg.getUniqueId());
        assertEquals(PAYLOAD, procMsg.getContent());
        assertEquals(PAYLOAD_ENCODING, procMsg.getContentEncoding());
        assertTrue(procMsg.headersContainsKey(METADATA_KEY));
        assertEquals(METADATA_VALUE, procMsg.getMetadataValue(METADATA_KEY));
    } finally {
        adapter.requestClose();
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) SerializableAdaptrisMessage(com.adaptris.core.SerializableAdaptrisMessage) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) ArrayList(java.util.ArrayList) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) StubSerializableMessage(com.adaptris.core.stubs.StubSerializableMessage) SerializableMessage(com.adaptris.interlok.types.SerializableMessage) GuidGenerator(com.adaptris.util.GuidGenerator) Test(org.junit.Test)

Example 59 with StandardWorkflow

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

the class ExceptionReportServiceTest method testBug2356.

@Test
public void testBug2356() throws Exception {
    ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
    MockMessageProducer mockProducer = new MockMessageProducer();
    StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
    MockChannel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    StandardWorkflow wf = new StandardWorkflow();
    wf.getServiceCollection().add(failingService);
    wf.setConsumer(consumer);
    channel.setMessageErrorHandler(speh);
    channel.getWorkflowList().add(wf);
    try {
        channel.prepare();
        channel.requestStart();
        consumer.submitMessage(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
        assertNotSame(XML_PAYLOAD, failedMessage.getContent());
        XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
        assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
        assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
        String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
        assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) ServiceImp(com.adaptris.core.ServiceImp) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) InsertNode(com.adaptris.util.text.xml.InsertNode) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 60 with StandardWorkflow

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

the class ExampleErrorHandlerCase method createChannel.

protected Channel createChannel(MockMessageConsumer consumer, ProcessingExceptionHandler ceh, ProcessingExceptionHandler weh, Service... services) {
    StandardWorkflow workflow = createWorkflow(consumer, weh, services);
    Channel c = new Channel();
    c.setMessageErrorHandler(ceh);
    c.getWorkflowList().add(workflow);
    return c;
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) Channel(com.adaptris.core.Channel)

Aggregations

StandardWorkflow (com.adaptris.core.StandardWorkflow)102 Test (org.junit.Test)78 Channel (com.adaptris.core.Channel)67 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)55 Adapter (com.adaptris.core.Adapter)53 ObjectName (javax.management.ObjectName)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)38 TimeInterval (com.adaptris.util.TimeInterval)25 StandaloneProducer (com.adaptris.core.StandaloneProducer)20 BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 ArrayList (java.util.ArrayList)14 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)12 MockChannel (com.adaptris.core.stubs.MockChannel)11 Notification (javax.management.Notification)11 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)10 ServiceList (com.adaptris.core.ServiceList)10 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)10 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)9 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)9