Search in sources :

Example 6 with InternalEvent

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

Example 7 with InternalEvent

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

Example 8 with InternalEvent

use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method interceptorMutatesEventBefore.

@Test
public void interceptorMutatesEventBefore() throws Exception {
    ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {

        @Override
        public void before(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event) {
            event.message(Message.of(TEST_PAYLOAD));
        }
    });
    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", TEST_PAYLOAD), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), 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(2));
    }
}
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) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 9 with InternalEvent

use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method secondInterceptorMutatesEventBefore.

@Test
public void secondInterceptorMutatesEventBefore() throws Exception {
    ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
    });
    ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {

        @Override
        public void before(ComponentLocation location, Map<String, ProcessorParameterValue> parameters, InterceptionEvent event) {
            event.message(Message.of(TEST_PAYLOAD));
        }
    });
    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", TEST_PAYLOAD), any(), 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));
    }
}
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) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ProcessorParameterValue(org.mule.runtime.api.interception.ProcessorParameterValue) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 10 with InternalEvent

use of org.mule.runtime.core.internal.message.InternalEvent in project mule by mulesoft.

the class ReactiveInterceptorAdapterTestCase method secondInterceptorMutatesEventAfter.

@Test
public void secondInterceptorMutatesEventAfter() throws Exception {
    ProcessorInterceptor interceptor1 = prepareInterceptor(new TestProcessorInterceptor("outer") {
    });
    ProcessorInterceptor interceptor2 = prepareInterceptor(new TestProcessorInterceptor("inner") {

        @Override
        public void after(ComponentLocation location, InterceptionEvent event, Optional<Throwable> thrown) {
            event.message(Message.of(TEST_PAYLOAD));
        }
    });
    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(), 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).process(argThat(hasPayloadValue("")));
        inOrder.verify(interceptor2).after(any(), any(), eq(empty()));
        inOrder.verify(interceptor1).after(any(), argThat(interceptionHasPayloadValue(TEST_PAYLOAD)), 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) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

InternalEvent (org.mule.runtime.core.internal.message.InternalEvent)32 Test (org.junit.Test)30 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)23 InOrder (org.mockito.InOrder)22 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)22 SmallTest (org.mule.tck.size.SmallTest)22 DefaultComponentLocation (org.mule.runtime.dsl.api.component.config.DefaultComponentLocation)21 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)20 ProcessorParameterValue (org.mule.runtime.api.interception.ProcessorParameterValue)16 CompletableFuture (java.util.concurrent.CompletableFuture)14 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)14 DefaultInterceptionEvent (org.mule.runtime.core.internal.interception.DefaultInterceptionEvent)7 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)5 Component (org.mule.runtime.api.component.Component)4 Message (org.mule.runtime.api.message.Message)4 MuleSession (org.mule.runtime.core.privileged.event.MuleSession)4 Collections.singletonList (java.util.Collections.singletonList)3 Map (java.util.Map)3 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)3