Search in sources :

Example 26 with InterceptionAction

use of org.mule.runtime.api.interception.InterceptionAction 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;
            });
        }
    }
}
Also used : Mono(reactor.core.publisher.Mono) PollingProber(org.mule.tck.probe.PollingProber) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CompletableFuture(java.util.concurrent.CompletableFuture) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 27 with InterceptionAction

use of org.mule.runtime.api.interception.InterceptionAction 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));
        }
    }
}
Also used : DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CompletableFuture(java.util.concurrent.CompletableFuture) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 28 with InterceptionAction

use of org.mule.runtime.api.interception.InterceptionAction 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));
        }
    }
}
Also used : DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) CompletableFuture(java.util.concurrent.CompletableFuture) ExpressionRuntimeException(org.mule.runtime.core.api.expression.ExpressionRuntimeException) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)28 Test (org.junit.Test)28 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)28 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)28 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)28 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)28 ProcessorParameterValue (org.mule.runtime.api.interception.ProcessorParameterValue)28 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)28 SmallTest (org.mule.tck.size.SmallTest)28 InOrder (org.mockito.InOrder)27 ExpressionRuntimeException (org.mule.runtime.core.api.expression.ExpressionRuntimeException)16 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)15 InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)15 ImmutableMap (com.google.common.collect.ImmutableMap)4 Thread.currentThread (java.lang.Thread.currentThread)4 Arrays.asList (java.util.Arrays.asList)4 Collection (java.util.Collection)4 Collections.singletonList (java.util.Collections.singletonList)4 Collections.singletonMap (java.util.Collections.singletonMap)4 HashMap (java.util.HashMap)4