Search in sources :

Example 1 with ProcessorInterceptorFactory

use of org.mule.runtime.api.interception.ProcessorInterceptorFactory 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));
    }
}
Also used : DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 2 with ProcessorInterceptorFactory

use of org.mule.runtime.api.interception.ProcessorInterceptorFactory in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method secondInterceptorDoesntApply.

@Test
public void secondInterceptorDoesntApply() throws Exception {
    ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
    });
    ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {
    });
    startFlowWithInterceptorFactories(() -> interceptor1, new ProcessorInterceptorFactory() {

        @Override
        public boolean intercept(ComponentLocation location) {
            return false;
        }

        @Override
        public ProcessorInterceptor get() {
            return 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).before(any(), any(), any());
        inOrder.verify(interceptor1).around(any(), any(), any(), any());
        inOrder.verify(interceptor2, never()).before(any(), any(), any());
        inOrder.verify(interceptor2, never()).around(any(), any(), any(), any());
        inOrder.verify(processor).process(any());
        inOrder.verify(interceptor2, never()).after(any(), any(), eq(empty()));
        inOrder.verify(interceptor1).after(any(), any(), eq(empty()));
        assertThat(((InternalEvent) result).getInternalParameters().entrySet(), hasSize(0));
        verifyParametersResolvedAndDisposed(times(1));
    }
}
Also used : DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) InOrder(org.mockito.InOrder) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)2 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)2 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)2 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)2 SmallTest (org.mule.tck.size.SmallTest)2