use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class SplitAggregateScopeTestCase method customTargetDefaultPayload.
@Test
@Description("When a custom target is configured the router result is set in a variable and the input event is output.")
public void customTargetDefaultPayload() throws Exception {
final String variableName = "foo";
CoreEvent original = createListEvent();
MessageProcessorChain nested = newChain(empty(), event -> event);
nested.setMuleContext(muleContext);
router.setMessageProcessors(singletonList(nested));
router.setTarget(variableName);
muleContext.getInjector().inject(router);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
router.initialise();
Event result = router.process(original);
assertThat(result.getMessage(), equalTo(original.getMessage()));
final TypedValue<?> typedValue = result.getVariables().get(variableName);
assertThat(typedValue.getValue(), instanceOf(List.class));
assertThat(List.class.isAssignableFrom(typedValue.getDataType().getType()), is(true));
List<Message> resultList = (List<Message>) typedValue.getValue();
assertThat(resultList, hasSize(2));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class SplitAggregateScopeTestCase method defaultTarget.
@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
CoreEvent original = createListEvent();
MessageProcessorChain nested = newChain(empty(), event -> event);
nested.setMuleContext(muleContext);
router.setMessageProcessors(singletonList(nested));
muleContext.getInjector().inject(router);
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
router.initialise();
Event result = router.process(original);
assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
List<Message> resultList = (List<Message>) result.getMessage().getPayload().getValue();
assertThat(resultList, hasSize(2));
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class SplitterIteratorTestCase method testExpressionSplitterWithIteratorInput.
@Test
public void testExpressionSplitterWithIteratorInput() throws Exception {
CoreEvent result = splitter.process(muleEvent);
List<?> values = (List<?>) result.getMessage().getPayload().getValue();
assertThat(values.size(), is(integers.size()));
assertListValues(values);
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class SplitterTestCase method assertRouted.
private void assertRouted(Object payload, int count, boolean counted) throws Exception, MuleException {
MuleSession session = new DefaultMuleSession();
Map<String, Serializable> inboundProps = new HashMap<>();
inboundProps.put("inbound1", "1");
inboundProps.put("inbound2", 2);
inboundProps.put("inbound3", session);
Map<String, Serializable> outboundProps = new HashMap<>();
outboundProps.put("outbound1", "3");
outboundProps.put("outbound2", 4);
outboundProps.put("outbound3", session);
Map<String, Object> invocationProps = new HashMap<>();
invocationProps.put("invoke1", "5");
invocationProps.put("invoke2", 6);
invocationProps.put("invoke3", session);
Set<Integer> expectedSequences = new HashSet<>();
for (int i = 1; i <= count; i++) {
expectedSequences.add(i);
}
Message toSplit = InternalMessage.builder().value(payload).inboundProperties(inboundProps).outboundProperties(outboundProps).build();
Splitter splitter = new Splitter();
Grabber grabber = new Grabber();
splitter.setMuleContext(muleContext);
splitter.setListener(grabber);
splitter.initialise();
final Builder eventBuilder = this.<PrivilegedEvent.Builder>getEventBuilder().message(toSplit).session(session);
for (Map.Entry<String, Object> entry : invocationProps.entrySet()) {
eventBuilder.addVariable(entry.getKey(), entry.getValue());
}
CoreEvent event = eventBuilder.build();
splitter.process(event);
List<CoreEvent> splits = grabber.getEvents();
assertEquals(count, splits.size());
Set<Object> actualSequences = new HashSet<>();
assertSplitParts(count, counted, inboundProps, outboundProps, invocationProps, splits, actualSequences);
assertEquals(expectedSequences, actualSequences);
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class UntilSuccessfulTestCase method testTemporaryDeliveryFailure.
@Test
public void testTemporaryDeliveryFailure() throws Exception {
targetMessageProcessor.setNumberOfFailuresToSimulate(untilSuccessful.getMaxRetries());
untilSuccessful.setMuleContext(muleContext);
untilSuccessful.initialise();
untilSuccessful.start();
final CoreEvent testEvent = eventBuilder(muleContext).message(of("ERROR")).build();
assertSame(testEvent.getMessage(), untilSuccessful.process(testEvent).getMessage());
assertTargetEventReceived(testEvent);
assertEquals(targetMessageProcessor.getEventCount(), untilSuccessful.getMaxRetries() + 1);
}
Aggregations