Search in sources :

Example 6 with Processor

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

the class ForeachTestCase method failingExpressionInChain.

@Test
public void failingExpressionInChain() throws Exception {
    Foreach foreach = createForeach();
    foreach.setCollectionExpression("!@INVALID");
    SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
    List<Processor> processors = getSimpleMessageProcessors(new TestMessageProcessor("zas"));
    processors.add(0, firstProcessor);
    foreach.setMessageProcessors(processors);
    initialiseIfNeeded(foreach, muleContext);
    try {
        expectExpressionException(foreach);
        processInChain(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build());
    } finally {
        assertThat(firstProcessor.invocations, equalTo(0));
    }
}
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) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 7 with Processor

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

the class ForeachTestCase method failingExpression.

@Test
public void failingExpression() throws Exception {
    Foreach foreach = createForeach();
    foreach.setCollectionExpression("!@INVALID");
    SensingNullMessageProcessor firstProcessor = new SensingNullMessageProcessor();
    List<Processor> processors = getSimpleMessageProcessors(new TestMessageProcessor("zas"));
    processors.add(0, firstProcessor);
    foreach.setMessageProcessors(processors);
    initialiseIfNeeded(foreach, muleContext);
    try {
        expectExpressionException(foreach);
        process(foreach, eventBuilder(muleContext).message(of(new DummyNestedIterableClass().iterator())).build(), false);
    } finally {
        assertThat(firstProcessor.invocations, equalTo(0));
    }
}
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) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 8 with Processor

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

the class RoundRobinTestCase method testRoundRobin.

@Test
public void testRoundRobin() throws Exception {
    RoundRobin rr = new RoundRobin();
    rr.setAnnotations(getAppleFlowComponentLocationAnnotations());
    MuleSession session = new DefaultMuleSession();
    List<TestProcessor> routes = new ArrayList<>(NUMBER_OF_ROUTES);
    for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
        routes.add(new TestProcessor());
    }
    rr.setRoutes(new ArrayList<Processor>(routes));
    initialiseIfNeeded(rr, muleContext);
    List<Thread> threads = new ArrayList<>(NUMBER_OF_ROUTES);
    for (int i = 0; i < NUMBER_OF_ROUTES; i++) {
        threads.add(new Thread(new TestDriver(session, rr, NUMBER_OF_MESSAGES, getTestFlow(muleContext))));
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    for (TestProcessor route : routes) {
        assertEquals(NUMBER_OF_MESSAGES, route.getCount());
    }
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) ArrayList(java.util.ArrayList) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) Test(org.junit.Test)

Example 9 with Processor

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

the class FirstSuccessfulTestCase method testRouteReturnsNullEvent.

@Test
public void testRouteReturnsNullEvent() throws Exception {
    Processor nullReturningMp = event -> null;
    FirstSuccessful fs = createFirstSuccessfulRouter(nullReturningMp);
    fs.setAnnotations(getAppleFlowComponentLocationAnnotations());
    fs.initialise();
    assertThat(fs.process(testEvent()), nullValue());
}
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) Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Example 10 with Processor

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

the class OperationPolicyProcessor method apply.

@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
    return from(publisher).cast(PrivilegedEvent.class).flatMap(operationEvent -> {
        PolicyStateId policyStateId = new PolicyStateId(operationEvent.getContext().getCorrelationId(), policy.getPolicyId());
        Optional<CoreEvent> latestPolicyState = policyStateHandler.getLatestState(policyStateId);
        PrivilegedEvent variablesProviderEvent = (PrivilegedEvent) latestPolicyState.orElseGet(() -> PrivilegedEvent.builder(operationEvent.getContext()).message(of(null)).build());
        policyStateHandler.updateState(policyStateId, variablesProviderEvent);
        PrivilegedEvent policyEvent = policyEventConverter.createEvent(operationEvent, variablesProviderEvent);
        Processor operationCall = buildOperationExecutionWithPolicyFunction(nextProcessor, operationEvent, policyStateId);
        policyStateHandler.updateNextOperation(policyStateId.getExecutionIdentifier(), operationCall);
        return executePolicyChain(operationEvent, policyStateId, policyEvent);
    });
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) PolicyStateId(org.mule.runtime.core.api.policy.PolicyStateId)

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