use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultRouterResultsHandlerTestCase method aggregateSingleEvent.
@Test
public void aggregateSingleEvent() {
Message message1 = Message.of("test event A");
InternalEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key1", "value1").build();
event1.getSession().setProperty("key", "value");
Message message2 = Message.of("test event B");
InternalEvent event2 = InternalEvent.builder(context).message(message2).addVariable("key2", "value2").build();
event2.getSession().setProperty("key", "valueNEW");
event2.getSession().setProperty("key1", "value1");
CoreEvent result = resultsHandler.aggregateResults(singletonList(event2), event1);
assertSame(event2, result);
// Because same event instance is returned rather than MessageCollection
// don't copy invocation properties
assertThat(result.getVariables().keySet(), not(hasItem("key1")));
assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
PrivilegedEvent privilegedResult = (PrivilegedEvent) result;
assertThat(privilegedResult.getSession().getProperty("key"), equalTo("valueNEW"));
assertThat(privilegedResult.getSession().getProperty("key1"), equalTo("value1"));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultRouterResultsHandlerTestCase method aggregateMultipleEvents.
@Test
public void aggregateMultipleEvents() throws Exception {
DataType simpleDateType1 = DataType.builder().type(String.class).mediaType("text/plain").build();
Message message1 = Message.of("test event A");
Message message2 = Message.of("test event B");
Message message3 = Message.of("test event C");
PrivilegedEvent event1 = InternalEvent.builder(context).message(message1).addVariable("key1", "value1", simpleDateType1).build();
MuleSession session = event1.getSession();
PrivilegedEvent event2 = InternalEvent.builder(context).message(message2).session(session).addVariable("key2", "value2", simpleDateType1).build();
InternalEvent event3 = InternalEvent.builder(context).message(message3).session(session).addVariable("key3", "value3", simpleDateType1).build();
event1.getSession().setProperty("key", "value");
event2.getSession().setProperty("key1", "value1");
event2.getSession().setProperty("key2", "value2");
event3.getSession().setProperty("KEY2", "value2NEW");
event3.getSession().setProperty("key3", "value3");
List<CoreEvent> events = new ArrayList<>();
events.add(event2);
events.add(event3);
PrivilegedEvent result = (PrivilegedEvent) resultsHandler.aggregateResults(events, event1);
assertThat(result, notNullValue());
assertThat((List<InternalMessage>) result.getMessage().getPayload().getValue(), hasSize(2));
assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
assertThat(((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(0), is(message2));
assertThat(((List<InternalMessage>) result.getMessage().getPayload().getValue()).get(1), is(message3));
// Because a new MuleMessageCollection is created, propagate properties from
// original event
assertThat(result.getVariables().get("key1").getValue(), equalTo("value1"));
assertThat(result.getVariables().get("key1").getDataType(), equalTo(simpleDateType1));
assertThat(result.getVariables().get("key2").getValue(), equalTo("value2"));
assertThat(result.getVariables().get("key3").getValue(), equalTo("value3"));
// Root id
assertThat(result.getCorrelationId(), equalTo(event1.getCorrelationId()));
assertThat(result.getSession().getProperty("key"), is("value"));
assertThat(result.getSession().getProperty("key1"), is("value1"));
assertThat(result.getSession().getProperty("key2"), is("value2NEW"));
assertThat(result.getSession().getProperty("key3"), is("value3"));
assertThat(result.getSession().getProperty("key4"), nullValue());
}
Aggregations