use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundBeforeSkip.
@Test
public void interceptorMutatesEventAroundBeforeSkip() throws Exception {
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
event.message(Message.of(TEST_PAYLOAD));
return action.skip();
}
});
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, never()).process(any());
inOrder.verify(interceptor).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorErrorResumeAround.
@Test
@io.qameta.allure.Description("Simulates the error handling scenario for XML SDK operations")
public void interceptorErrorResumeAround() throws Exception {
Exception thrown = new Exception();
ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
Mono<InterceptionEvent> errorMono = Mono.error(thrown);
return Mono.from(((BaseEventContext) event.getContext()).error(thrown)).then(errorMono).toFuture();
}
@Override
public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
}
});
startFlowWithInterceptors(interceptor);
expected.expectCause(sameInstance(thrown));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
if (useMockInterceptor) {
new PollingProber().probe(() -> {
verify(interceptor).after(any(), any(), eq(Optional.of(thrown)));
return true;
});
}
}
}
use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method secondInterceptorFailsAround.
@Test
public void secondInterceptorFailsAround() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
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.fail(expectedException);
}
});
startFlowWithInterceptors(interceptor1, interceptor2);
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
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(of(expectedException)));
inOrder.verify(interceptor1).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
use of org.mule.runtime.api.interception.InterceptionEvent in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method secondInterceptorThrowsExceptionAround.
@Test
public void secondInterceptorThrowsExceptionAround() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
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) {
throw expectedException;
}
});
startFlowWithInterceptors(interceptor1, interceptor2);
expected.expectCause(sameInstance(expectedException));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
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(of(expectedException)));
inOrder.verify(interceptor1).after(any(), any(), eq(of(expectedException)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
Aggregations