use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method correlationIdLegacy.
@Test
public void correlationIdLegacy() throws MuleException {
final InternalEvent event = InternalEvent.builder(create("id", "serverId", TEST_CONNECTOR_LOCATION, mock(FlowExceptionHandler.class))).correlationId("corr1").message(of(TEST_PAYLOAD)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
assertThat(interceptionEvent.getCorrelationId(), is("corr1"));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class DefaultInterceptionEventTestCase method updateSession.
@Test
public void updateSession() throws MuleException {
final InternalEvent event = this.<InternalEvent.Builder>getEventBuilder().message(of(TEST_PAYLOAD)).build();
final DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(event);
final MuleSession session = ((PrivilegedEvent) event).getSession();
session.setProperty("myKey", "myValue");
interceptionEvent.session(session);
assertThat(((PrivilegedEvent) interceptionEvent.resolve()).getSession().getProperty("myKey"), is("myValue"));
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorMutatesEventAfter.
@Test
public void firstInterceptorMutatesEventAfter() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
event.message(Message.of(TEST_PAYLOAD));
}
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
startFlowWithInterceptors(interceptor1, interceptor2);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(TEST_PAYLOAD));
assertThat(result.getError().isPresent(), is(false));
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor1, interceptor2);
inOrder.verify(interceptor1).before(any(), any(), any());
inOrder.verify(interceptor2).before(any(), any(), any());
inOrder.verify(interceptor1).around(any(), any(), any(), any());
inOrder.verify(interceptor2).around(any(), any(), any(), any());
inOrder.verify(processor).process(argThat(hasPayloadValue("")));
inOrder.verify(interceptor2).after(any(), any(), eq(empty()));
inOrder.verify(interceptor1).after(any(), any(), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAfter.
@Test
public void interceptorMutatesEventAfter() throws Exception {
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
event.message(Message.of(TEST_PAYLOAD));
}
});
startFlowWithInterceptors(interceptor);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(TEST_PAYLOAD));
assertThat(result.getError().isPresent(), is(false));
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor);
inOrder.verify(interceptor).before(any(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor).around(any(), mapArgWithEntry("param", ""), any(), any());
inOrder.verify(processor).process(argThat(hasPayloadValue("")));
inOrder.verify(interceptor).after(any(), any(), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundAfterProceed.
@Test
public void interceptorMutatesEventAroundAfterProceed() throws Exception {
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
action.proceed();
return supplyAsync(() -> {
event.message(Message.of(TEST_PAYLOAD));
return event;
});
}
});
startFlowWithInterceptors(interceptor);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(TEST_PAYLOAD));
assertThat(result.getError().isPresent(), is(false));
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor);
inOrder.verify(interceptor).before(any(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor).around(any(), mapArgWithEntry("param", ""), any(), any());
inOrder.verify(processor).process(argThat(hasPayloadValue("")));
inOrder.verify(interceptor).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
Aggregations