Search in sources :

Example 71 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class RetryMessageErrorHandlerMonitorTest method testMBean_FailMessageById.

@Test
public void testMBean_FailMessageById() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    MockMessageProducer failProducer = new MockMessageProducer();
    RetryMessageErrorHandler handler = new RetryMessageErrorHandler(getName(), new StandaloneProducer(failProducer));
    adapter.setMessageErrorHandler(handler);
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        registerMBeans(adapterManager);
        adapterManager.requestStart();
        ObjectName retryObjectName = ObjectName.getInstance(JMX_RETRY_MONITOR_TYPE + adapterManager.createObjectHierarchyString() + ID_PREFIX + getName());
        RetryMessageErrorHandlerMonitorMBean mbean = JMX.newMBeanProxy(mBeanServer, retryObjectName, RetryMessageErrorHandlerMonitorMBean.class);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        // 10 retries 10 minutes apart, so it should be waiting.
        handler.handleProcessingException(msg);
        assertEquals(1, mbean.waitingForRetry().size());
        assertTrue(mbean.waitingForRetry().contains(msg.getUniqueId()));
        mbean.failMessage("hello");
        mbean.failMessage(msg.getUniqueId());
        assertEquals(1, failProducer.messageCount());
    } finally {
        adapterManager.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) RetryMessageErrorHandlerMonitorMBean(com.adaptris.core.RetryMessageErrorHandlerMonitorMBean) Adapter(com.adaptris.core.Adapter) RetryMessageErrorHandler(com.adaptris.core.RetryMessageErrorHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 72 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class StatelessServiceWrapperTest method testWrappedServiceCreateName.

@Test
public void testWrappedServiceCreateName() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("");
    MockMessageProducer prod = new MockMessageProducer();
    Service s = create(prod);
    assertNotSame(StatelessServiceWrapper.class.getName(), s.createName());
    assertEquals(MockMessageProducer.class.getName(), s.createName());
    StatelessServiceWrapper sw = new StatelessServiceWrapper();
    assertEquals(StatelessServiceWrapper.class.getName(), sw.createName());
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExampleBranchingService(com.adaptris.core.stubs.ExampleBranchingService) NullService(com.adaptris.core.NullService) Service(com.adaptris.core.Service) Test(org.junit.Test)

Example 73 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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 74 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter.

@Test
public void testServiceWithXmlSplitter() throws Exception {
    MockMessageProducer producer = createMockProducer();
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new StandaloneProducer(producer));
    service.setMaxThreads(1);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    execute(service, msg);
    assertEquals("Number of messages", 3, producer.getMessages().size());
}
Also used : StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 75 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.

the class PoolingMessageSplitterServiceTest method testServiceWithXmlSplitter_WarmStart_WaitWhileBusy.

@Test
public void testServiceWithXmlSplitter_WarmStart_WaitWhileBusy() throws Exception {
    MockMessageProducer producer = createMockProducer();
    PoolingMessageSplitterService service = SplitterCase.createPooling(new XpathMessageSplitter("/envelope/document", "UTF-8"), new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)), new StandaloneProducer(producer)).withWarmStart(true).withMaxThreads(1).withWaitWhileBusy(true);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_MESSAGE);
    XpathMessageSplitter splitter = new XpathMessageSplitter("/envelope/document", "UTF-8");
    execute(service, msg);
    assertEquals("Number of messages", 3, producer.getMessages().size());
}
Also used : WaitService(com.adaptris.core.services.WaitService) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)321 Test (org.junit.Test)306 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)156 MockChannel (com.adaptris.core.stubs.MockChannel)126 Channel (com.adaptris.core.Channel)125 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)73 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)69 StandaloneProducer (com.adaptris.core.StandaloneProducer)68 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)65 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)56 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)52 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 StandardWorkflow (com.adaptris.core.StandardWorkflow)40 TimeInterval (com.adaptris.util.TimeInterval)40 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 ServiceList (com.adaptris.core.ServiceList)33 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)33 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)27