use of org.mule.runtime.api.interception.ProcessorParameterValue in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundAfterFailWithCause.
@Test
public void interceptorMutatesEventAroundAfterFailWithCause() throws Exception {
Throwable cause = new RuntimeException("");
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.fail(cause);
}
});
startFlowWithInterceptors(interceptor);
expected.expectCause(sameInstance(cause));
try {
process(flow, eventBuilder(muleContext).message(Message.of("")).build());
} finally {
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(of(cause)));
verifyParametersResolvedAndDisposed(times(1));
}
}
}
use of org.mule.runtime.api.interception.ProcessorParameterValue in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method firstInterceptorThrowsExceptionAround.
@Test
public void firstInterceptorThrowsExceptionAround() throws Exception {
RuntimeException expectedException = new RuntimeException("Some Error");
ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
@Override
public CompletableFuture<InterceptionEvent> around(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event, InterceptionAction action) {
throw expectedException;
}
});
ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
});
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, never()).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.ProcessorParameterValue 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));
}
}
use of org.mule.runtime.api.interception.ProcessorParameterValue in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method secondInterceptorMutatesEventAroundBeforeProceed.
@Test
public void secondInterceptorMutatesEventAroundBeforeProceed() 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) {
event.message(Message.of(TEST_PAYLOAD));
return action.proceed();
}
});
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(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(1));
}
}
use of org.mule.runtime.api.interception.ProcessorParameterValue in project mule by mulesoft.
the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventAroundBeforeProceed.
@Test
public void interceptorMutatesEventAroundBeforeProceed() 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.proceed();
}
});
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(TEST_PAYLOAD)));
inOrder.verify(interceptor).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), eq(empty()));
assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
verifyParametersResolvedAndDisposed(times(1));
}
}
Aggregations