Search in sources :

Example 11 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class ForeachTestCase method failingNestedProcessor.

@Test
public void failingNestedProcessor() throws Exception {
    RuntimeException throwable = new BufferOverflowException();
    Foreach foreach = createForeach();
    SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
    InternalTestProcessor failingProcessor = event -> {
        throw throwable;
    };
    foreach.setMessageProcessors(asList(firstProcessor, failingProcessor));
    initialiseIfNeeded(foreach, muleContext);
    try {
        expectNestedProessorException(throwable, failingProcessor);
        process(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build(), false);
    } finally {
        assertThat(firstProcessor.invocations, equalTo(1));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) BufferOverflowException(java.nio.BufferOverflowException) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Processor(org.mule.runtime.core.api.processor.Processor) DEFAULT_COUNTER_VARIABLE(org.mule.runtime.core.internal.routing.Foreach.DEFAULT_COUNTER_VARIABLE) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BaseMatcher(org.hamcrest.BaseMatcher) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ExpectedException.none(org.junit.rules.ExpectedException.none) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MULE_MESSAGE(org.mule.runtime.api.metadata.DataType.MULE_MESSAGE) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Collections.singletonMap(java.util.Collections.singletonMap) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) Description(org.hamcrest.Description) Iterator(java.util.Iterator) DataType(org.mule.runtime.api.metadata.DataType) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Message.of(org.mule.runtime.api.message.Message.of) DataTypeCompatibilityMatcher.assignableTo(org.mule.tck.junit4.matcher.DataTypeCompatibilityMatcher.assignableTo) TypedValue(org.mule.runtime.api.metadata.TypedValue) Collectors.toList(java.util.stream.Collectors.toList) DEFAULT_ROOT_MESSAGE_VARIABLE(org.mule.runtime.core.internal.routing.Foreach.DEFAULT_ROOT_MESSAGE_VARIABLE) List(java.util.List) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Rule(org.junit.Rule) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) Assert.assertEquals(org.junit.Assert.assertEquals) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) BufferOverflowException(java.nio.BufferOverflowException) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 12 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class SimpleCollectionAggregatorTestCase method testAggregateMultipleEvents.

@Test
public void testAggregateMultipleEvents() throws Exception {
    Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    assertNotNull(flow);
    SimpleCollectionAggregator router = new SimpleCollectionAggregator();
    SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
    router.setListener(sensingMessageProcessor);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(router, true, muleContext);
    EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
    Message message1 = Message.of("test event A");
    Message message2 = Message.of("test event B");
    Message message3 = Message.of("test event C");
    CoreEvent event1 = InternalEvent.builder(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).build();
    CoreEvent event2 = InternalEvent.builder(executionContext).message(message2).build();
    CoreEvent event3 = InternalEvent.builder(executionContext).message(message3).build();
    assertNull(router.process(event1));
    assertNull(router.process(event2));
    CoreEvent resultEvent = router.process(event3);
    assertNotNull(sensingMessageProcessor.event);
    assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
    Message nextMessage = sensingMessageProcessor.event.getMessage();
    assertNotNull(nextMessage);
    assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
    List<InternalMessage> list = (List<InternalMessage>) nextMessage.getPayload().getValue();
    assertEquals(3, list.size());
    String[] results = new String[3];
    list.stream().map(msg -> msg.getPayload().getValue()).collect(toList()).toArray(results);
    // Need to sort result because of MULE-5998
    Arrays.sort(results);
    assertEquals("test event A", results[0]);
    assertEquals("test event B", results[1]);
    assertEquals("test event C", results[2]);
}
Also used : EventContext(org.mule.runtime.api.event.EventContext) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 13 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class SimpleCollectionAggregatorTestCase method testAggregateSingleEvent.

@Test
public void testAggregateSingleEvent() throws Exception {
    Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    assertNotNull(flow);
    SimpleCollectionAggregator router = new SimpleCollectionAggregator();
    SensingNullMessageProcessor sensingMessageProcessor = getSensingNullMessageProcessor();
    router.setListener(sensingMessageProcessor);
    router.setMuleContext(muleContext);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(router, true, muleContext);
    EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
    Message message1 = of("test event A");
    CoreEvent event1 = InternalEvent.builder(executionContext).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 1))).build();
    CoreEvent resultEvent = router.process(event1);
    assertNotNull(sensingMessageProcessor.event);
    assertThat(resultEvent, equalTo(sensingMessageProcessor.event));
    Message nextMessage = sensingMessageProcessor.event.getMessage();
    assertNotNull(nextMessage);
    assertTrue(nextMessage.getPayload().getValue() instanceof List<?>);
    List<InternalMessage> payload = (List<InternalMessage>) nextMessage.getPayload().getValue();
    assertEquals(1, payload.size());
    assertEquals("test event A", payload.get(0).getPayload().getValue());
}
Also used : EventContext(org.mule.runtime.api.event.EventContext) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 14 with SensingNullMessageProcessor

use of org.mule.tck.SensingNullMessageProcessor in project mule by mulesoft.

the class SplitAggregateScopeTestCase method failingExpression.

@Test
@DescriptorKey("An invalid collection expression result in a ExpressionRuntimeException")
public void failingExpression() throws Exception {
    SensingNullMessageProcessor nullMessageProcessor = new SensingNullMessageProcessor();
    router.setMessageProcessors(singletonList(nullMessageProcessor));
    router.setCollectionExpression("!@INVALID");
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    expectedException.expect(MessagingException.class);
    expectedException.expectCause(instanceOf(ExpressionRuntimeException.class));
    router.process(testEvent());
}
Also used : ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test) DescriptorKey(javax.management.DescriptorKey)

Aggregations

SensingNullMessageProcessor (org.mule.tck.SensingNullMessageProcessor)14 Test (org.junit.Test)13 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)9 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors.toList (java.util.stream.Collectors.toList)4 MuleException (org.mule.runtime.api.exception.MuleException)4 Message (org.mule.runtime.api.message.Message)4 Processor (org.mule.runtime.core.api.processor.Processor)4 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)4 ExpressionRuntimeException (org.mule.runtime.core.api.expression.ExpressionRuntimeException)3 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)3 BufferOverflowException (java.nio.BufferOverflowException)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Optional (java.util.Optional)2 BaseMatcher (org.hamcrest.BaseMatcher)2