Search in sources :

Example 56 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class ForeachTestCase method batchSize.

@Test
public void batchSize() throws Exception {
    Foreach foreachMp = createForeach();
    List<Processor> processors = getSimpleMessageProcessors(new TestMessageProcessor("zas"));
    foreachMp.setMessageProcessors(processors);
    foreachMp.setBatchSize(2);
    initialiseIfNeeded(foreachMp, muleContext);
    foreachMp.process(eventBuilder(muleContext).message(of(asList(1, 2, 3))).build());
    assertThat(processedEvents, hasSize(2));
    assertThat(((PrivilegedEvent) processedEvents.get(0)).getMessageAsString(muleContext), is("[1, 2]:foo:zas"));
    assertThat(((PrivilegedEvent) processedEvents.get(1)).getMessageAsString(muleContext), is("[3]:foo:zas"));
}
Also used : InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) TestMessageProcessor(org.mule.tck.testmodels.mule.TestMessageProcessor) Test(org.junit.Test)

Example 57 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class RoundRobinTestCase method usesFirstRouteOnFirstRequest.

@Test
public void usesFirstRouteOnFirstRequest() throws Exception {
    RoundRobin roundRobin = new RoundRobin();
    roundRobin.setAnnotations(getAppleFlowComponentLocationAnnotations());
    List<Processor> routes = new ArrayList<>(2);
    Processor route1 = mock(Processor.class, "route1");
    when(route1.apply(any(Publisher.class))).then(invocation -> invocation.getArguments()[0]);
    routes.add(route1);
    Processor route2 = mock(Processor.class, "route2");
    when(route2.apply(any(Publisher.class))).then(invocation -> invocation.getArguments()[0]);
    routes.add(route2);
    roundRobin.setRoutes(new ArrayList<>(routes));
    initialiseIfNeeded(roundRobin, muleContext);
    Message message = of(singletonList(TEST_MESSAGE));
    roundRobin.process(eventBuilder(muleContext).message(message).build());
    verify(route1).apply(any(Publisher.class));
    verify(route2, never()).apply(any(Publisher.class));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) Message(org.mule.runtime.api.message.Message) ArrayList(java.util.ArrayList) Publisher(org.reactivestreams.Publisher) Test(org.junit.Test)

Example 58 with Processor

use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.

the class FirstSuccessfulTestCase method testRouteReturnsNullMessage.

@Test
public void testRouteReturnsNullMessage() throws Exception {
    Processor nullEventMp = event -> CoreEvent.builder(event).message(null).build();
    FirstSuccessful fs = createFirstSuccessfulRouter(nullEventMp);
    fs.setAnnotations(getAppleFlowComponentLocationAnnotations());
    fs.initialise();
    try {
        fs.process(testEvent());
        fail("Exception expected");
    } catch (CouldNotRouteOutboundMessageException e) {
    // this one was expected
    }
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Message(org.mule.runtime.api.message.Message) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) Processor(org.mule.runtime.core.api.processor.Processor) Assert.assertThat(org.junit.Assert.assertThat) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) CouldNotRouteOutboundMessageException(org.mule.runtime.core.privileged.routing.CouldNotRouteOutboundMessageException) MuleException(org.mule.runtime.api.exception.MuleException) Arrays.asList(java.util.Arrays.asList) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Component(org.mule.runtime.api.component.Component) Assert.fail(org.junit.Assert.fail) MuleContextUtils.eventBuilder(org.mule.tck.util.MuleContextUtils.eventBuilder) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DefaultExceptionPayload(org.mule.runtime.core.internal.message.DefaultExceptionPayload) Error(org.mule.runtime.api.message.Error) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Message.of(org.mule.runtime.api.message.Message.of) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleTestUtils.createErrorMock(org.mule.tck.MuleTestUtils.createErrorMock) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Matchers.is(org.hamcrest.Matchers.is) Mockito.withSettings(org.mockito.Mockito.withSettings) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Mockito.mock(org.mockito.Mockito.mock) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) CouldNotRouteOutboundMessageException(org.mule.runtime.core.privileged.routing.CouldNotRouteOutboundMessageException) Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Aggregations

Processor (org.mule.runtime.core.api.processor.Processor)58 Test (org.junit.Test)31 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 MuleException (org.mule.runtime.api.exception.MuleException)15 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)14 Component (org.mule.runtime.api.component.Component)12 ArrayList (java.util.ArrayList)11 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)11 Publisher (org.reactivestreams.Publisher)11 Message (org.mule.runtime.api.message.Message)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)10 Map (java.util.Map)9 Arrays.asList (java.util.Arrays.asList)8 Flow (org.mule.runtime.core.api.construct.Flow)8 Inject (javax.inject.Inject)7 Assert.assertThat (org.junit.Assert.assertThat)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.when (org.mockito.Mockito.when)7 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)7 Disposable (org.mule.runtime.api.lifecycle.Disposable)7