use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorMutatesEventBefore.
@Test
public void firstInterceptorMutatesEventBefore() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public void before(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event) {
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(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor2).before(any(), mapArgWithEntry("param", TEST_PAYLOAD), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)));
inOrder.verify(interceptor1).around(any(), mapArgWithEntry("param", TEST_PAYLOAD), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), any());
inOrder.verify(interceptor2).around(any(), mapArgWithEntry("param", TEST_PAYLOAD), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), any());
inOrder.verify(processor).process(argThat(hasPayloadValue(TEST_PAYLOAD)));
inOrder.verify(interceptor2).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
inOrder.verify(interceptor1).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(2));
}
}
use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method secondInterceptorMutatesEventAroundAfterProceed.
@Test
public void secondInterceptorMutatesEventAroundAfterProceed() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
@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(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(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor2).before(any(), mapArgWithEntry("param", ""), any());
inOrder.verify(interceptor1).around(any(), mapArgWithEntry("param", ""), any(), any());
inOrder.verify(interceptor2).around(any(), mapArgWithEntry("param", ""), any(), any());
inOrder.verify(processor).process(argThat(hasPayloadValue("")));
inOrder.verify(interceptor2).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
inOrder.verify(interceptor1).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), 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 firstInterceptorDoesntApply.
@Test
public void firstInterceptorDoesntApply() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
startFlowWithInterceptorFactories(new ProcessorInterceptorFactory() {
@Override
public boolean intercept(ComponentLocation location) {
return false;
}
@Override
public ProcessorInterceptor get() {
return interceptor1;
}
}, () -> interceptor2);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(""));
assertThat(result.getError().isPresent(), is(false));
if (useMockInterceptor) {
InOrder inOrder = inOrder(processor, interceptor1, interceptor2);
inOrder.verify(interceptor1, never()).before(any(), any(), any());
inOrder.verify(interceptor2).before(any(), any(), any());
inOrder.verify(interceptor1, never()).around(any(), any(), any(), any());
inOrder.verify(interceptor2).around(any(), any(), any(), any());
inOrder.verify(processor).process(any());
inOrder.verify(interceptor2).after(any(), any(), eq(empty()));
inOrder.verify(interceptor1, never()).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 secondInterceptorSkipsProcessor.
@Test
public void secondInterceptorSkipsProcessor() throws Exception {
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
return action.skip();
}
});
startFlowWithInterceptors(interceptor1, interceptor2);
CoreEvent result = process(flow, eventBuilder(muleContext).message(Message.of("")).build());
assertThat(result.getMessage().getPayload().getValue(), is(""));
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, never()).process(any());
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 DefaultInterceptionEvent method resolve.
/**
* Updates the state of this object if needed, overriding the {@code interceptedInput} with the result built from
* {@code interceptedOutput} and resetting {@code interceptedOutput}.
*
* @return {@link PrivilegedEvent} with the result.
*/
@Override
public InternalEvent resolve() {
final InternalEvent newEvent = interceptedOutput.build();
if (interceptedInput != newEvent) {
interceptedInput = newEvent;
interceptedOutput = InternalEvent.builder(interceptedInput).removeInternalParameter(INTERCEPTION_RESOLVED_PARAMS);
}
return interceptedInput;
}
Aggregations