use of org.mule.runtime.core.privileged.event.DefaultMuleSession in project mule by mulesoft.
the class AbstractPolicyProcessorTestCase method sessionModifiedByNextProcessorIsPropagated.
@Test
public void sessionModifiedByNextProcessorIsPropagated() throws MuleException {
DefaultMuleSession session = new DefaultMuleSession();
CoreEvent modifiedSessionEvent = PrivilegedEvent.builder(initialEvent).session(session).build();
when(flowProcessor.apply(any())).thenReturn(just(modifiedSessionEvent));
when(policy.getPolicyChain().apply(any())).thenAnswer(invocation -> just(initialEvent).transform(policyStateHandler.retrieveNextOperation(executionId)));
CoreEvent resultEvent = just(initialEvent).transform(policyProcessor).block();
assertEquals(((PrivilegedEvent) resultEvent).getSession(), session);
}
use of org.mule.runtime.core.privileged.event.DefaultMuleSession in project mule by mulesoft.
the class EventGroup method getMergedSession.
protected MuleSession getMergedSession(PrivilegedEvent[] events) throws ObjectStoreException {
MuleSession session = new DefaultMuleSession(events[0].getSession());
for (int i = 1; i < events.length - 1; i++) {
addAndOverrideSessionProperties(session, events[i]);
}
addAndOverrideSessionProperties(session, events[events.length - 1]);
return session;
}
use of org.mule.runtime.core.privileged.event.DefaultMuleSession in project mule by mulesoft.
the class SplitterTestCase method testEmptySequence.
/**
* Tests that an empty sequence can be routed properly
*/
@Test
public void testEmptySequence() throws Exception {
Object payload = Collections.emptySet();
MuleSession session = new DefaultMuleSession();
Message toSplit = Message.of(payload);
Splitter splitter = new Splitter();
splitter.setMuleContext(muleContext);
splitter.initialise();
CoreEvent event = this.<PrivilegedEvent.Builder>getEventBuilder().message(toSplit).session(session).build();
assertSame(event, splitter.process(event));
}
use of org.mule.runtime.core.privileged.event.DefaultMuleSession in project mule by mulesoft.
the class MessageChunkAggregatorTestCase method testMessageProcessor.
@Test
public void testMessageProcessor() throws Exception {
MuleSession session = new DefaultMuleSession();
Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
assertNotNull(flow);
MessageChunkAggregator router = new MessageChunkAggregator();
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
Message message1 = of("test event A");
Message message2 = of("test event B");
Message message3 = of("test event C");
EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
CoreEvent event1 = InternalEvent.builder(context).message(message1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 3))).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
assertNull(router.process(event1));
assertNull(router.process(event2));
CoreEvent resultEvent = router.process(event3);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
String payload = getPayloadAsString(resultMessage);
assertTrue(payload.contains("test event A"));
assertTrue(payload.contains("test event B"));
assertTrue(payload.contains("test event C"));
assertTrue(payload.matches("test event [A,B,C]test event [A,B,C]test event [A,B,C]"));
}
use of org.mule.runtime.core.privileged.event.DefaultMuleSession in project mule by mulesoft.
the class ResequencerTestCase method testMessageResequencerWithComparator.
@Test
public void testMessageResequencerWithComparator() throws Exception {
MuleSession session = new DefaultMuleSession();
Flow flow = createFlow(muleContext, "test");
assertNotNull(flow);
when(componentLocator.find(any(Location.class))).thenReturn(of(flow));
TestEventResequencer router = new TestEventResequencer(3);
Map<QName, Object> fakeComponentLocationAnnotations = ImmutableMap.<QName, Object>builder().put(LOCATION_KEY, fromSingleComponent("test")).build();
router.setAnnotations(fakeComponentLocationAnnotations);
initialiseIfNeeded(router, true, muleContext);
EventContext context = 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(context).message(message1).session(session).build();
CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
// set a resequencing comparator. We need to reset the router since it will
// not process the same event group
// twice
router = new TestEventResequencer(3);
router.setMuleContext(muleContext);
router.setEventComparator(new EventPayloadComparator());
router.setAnnotations(getAppleFlowComponentLocationAnnotations());
initialiseIfNeeded(router, true, muleContext);
assertNull(router.process(event2));
assertNull(router.process(event3));
CoreEvent resultEvent = router.process(event1);
assertNotNull(resultEvent);
Message resultMessage = resultEvent.getMessage();
assertNotNull(resultMessage);
assertEquals("test event C", getPayloadAsString(resultMessage));
}
Aggregations