use of org.mule.runtime.api.message.Message in project mule by mulesoft.
the class VariablesTestCase method variableFromFlowScope.
@Test
public void variableFromFlowScope() throws Exception {
Message message = of("");
CoreEvent event = InternalEvent.builder(context).message(message).addVariable("foo", "bar").build();
((PrivilegedEvent) event).getSession().setProperty("foo", "NOTbar");
assertEquals(event.getVariables().get("foo").getValue(), evaluate("foo", event));
}
use of org.mule.runtime.api.message.Message 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.api.message.Message 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.api.message.Message 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.api.message.Message in project mule by mulesoft.
the class AbstractForkJoinStrategyTestCase method timeoutEager.
@Test
@Description("When configured with delayErrors='false' the first timeout causes strategy to throw a TimeoutException.")
public void timeoutEager() throws Throwable {
strategy = createStrategy(processingStrategy, 1, false, 50);
Message pair2Result = of(2);
Processor pair2Processor = createProcessorSpy(pair2Result);
RoutingPair pair2 = of(testEvent(), createChain(pair2Processor));
expectedException.expect(instanceOf(DefaultMuleException.class));
expectedException.expectCause(instanceOf(TimeoutException.class));
invokeStrategyBlocking(strategy, testEvent(), asList(createRoutingPairWithSleep(of(1), 250), pair2), throwable -> verify(pair2Processor, never()).process(any(CoreEvent.class)));
}
Aggregations