Search in sources :

Example 21 with Processor

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

the class DefaultMessageProcessorChainTestCase method testNestedMPChainLifecycle.

@Test
public void testNestedMPChainLifecycle() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    DefaultMessageProcessorChainBuilder nestedBuilder = new DefaultMessageProcessorChainBuilder();
    AppendingInterceptingMP mp1 = new AppendingInterceptingMP("1");
    AppendingInterceptingMP mp2 = new AppendingInterceptingMP("2");
    AppendingInterceptingMP mpa = new AppendingInterceptingMP("a");
    AppendingInterceptingMP mpb = new AppendingInterceptingMP("b");
    Processor chain = builder.chain(mp1, nestedBuilder.chain(mpa, mpb).build(), mp2).build();
    initialiseIfNeeded(chain, muleContext);
    ((Lifecycle) chain).start();
    ((Lifecycle) chain).stop();
    ((Lifecycle) chain).dispose();
    assertLifecycle(mp1);
    assertLifecycle(mp2);
    assertLifecycle(mpa);
    assertLifecycle(mpb);
}
Also used : AbstractInterceptingMessageProcessor(org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 22 with Processor

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

the class OutboundRouterTestCase method testAddGoodProcessor.

@Test
public void testAddGoodProcessor() throws Exception {
    AbstractOutboundRouter router = new DummyOutboundRouter();
    Processor processor = getTestMessageProcessor();
    router.addRoute(processor);
    assertNotNull(router.getRoutes());
    assertTrue(router.getRoutes().contains(processor));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) Test(org.junit.Test)

Example 23 with Processor

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

the class AsyncMessageProcessorsFactoryBean method getObject.

@Override
public AsyncDelegateMessageProcessor getObject() throws Exception {
    DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
    builder.setName("'async' child chain");
    for (Object processor : messageProcessors) {
        if (processor instanceof Processor) {
            builder.chain((Processor) processor);
        } else if (processor instanceof MessageProcessorBuilder) {
            builder.chain((MessageProcessorBuilder) processor);
        } else {
            throw new IllegalArgumentException("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
        }
    }
    AsyncDelegateMessageProcessor delegate = new AsyncDelegateMessageProcessor(builder, name);
    delegate.setAnnotations(getAnnotations());
    if (getMaxConcurrency() != null) {
        delegate.setMaxConcurrency(getMaxConcurrency());
    }
    return delegate;
}
Also used : DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) Processor(org.mule.runtime.core.api.processor.Processor) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) NameableObject(org.mule.runtime.api.meta.NameableObject) AsyncDelegateMessageProcessor(org.mule.runtime.core.internal.processor.AsyncDelegateMessageProcessor) MessageProcessorBuilder(org.mule.runtime.core.privileged.processor.MessageProcessorBuilder)

Example 24 with Processor

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

the class FlowRefFactoryBeanTestCase method createDynamicFlowRefFactoryBean.

private FlowRefFactoryBean createDynamicFlowRefFactoryBean(Processor target, Object targetBuilder) throws InitialisationException {
    doReturn(true).when(expressionManager).isExpression(anyString());
    doReturn(PARSED_DYNAMIC_REFERENCED_FLOW).when(expressionManager).parse(eq(DYNAMIC_REFERENCED_FLOW), any(CoreEvent.class), any(ComponentLocation.class));
    if (targetBuilder != null) {
        when(applicationContext.getBean(eq(PARSED_DYNAMIC_REFERENCED_FLOW))).thenReturn(targetBuilder);
    } else {
        when(applicationContext.getBean(eq(PARSED_DYNAMIC_REFERENCED_FLOW))).thenReturn(target);
    }
    if (target instanceof MessageProcessorChain) {
        Processor processor = ((MessageProcessorChain) target).getMessageProcessors().get(0);
        when(processor.apply(any())).thenAnswer(successAnswer());
    } else {
        when(target.apply(any())).thenAnswer(successAnswer());
    }
    return createFlowRefFactoryBean(DYNAMIC_REFERENCED_FLOW);
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 25 with Processor

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

the class FlowRefFactoryBeanTestCase method dynamicFlowRefSubFlowMessageProcessorChain.

@Test
public void dynamicFlowRefSubFlowMessageProcessorChain() throws Exception {
    CoreEvent event = testEvent();
    Processor targetSubFlowConstructAware = (Processor) mock(Object.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetSubFlowConstructAware.apply(any(Publisher.class))).thenReturn(just(result));
    Processor targetMuleContextAwareAware = (Processor) mock(MuleContextAware.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetMuleContextAwareAware.apply(any(Publisher.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    MessageProcessorChain targetSubFlowChain = mock(MessageProcessorChain.class, INITIALIZABLE_MESSAGE_PROCESSOR);
    when(targetSubFlowChain.apply(any(Publisher.class))).thenReturn(just(result));
    List<Processor> targetSubFlowProcessors = asList(targetSubFlowConstructAware, targetMuleContextAwareAware);
    when(targetSubFlowChain.getMessageProcessors()).thenReturn(targetSubFlowProcessors);
    SubflowMessageProcessorChainBuilder chainBuilder = new SubflowMessageProcessorChainBuilder();
    chainBuilder.chain(targetSubFlowProcessors);
    FlowRefFactoryBean flowRefFactoryBean = createDynamicFlowRefFactoryBean(targetSubFlowChain, chainBuilder);
    final Processor flowRefProcessor = getFlowRefProcessor(flowRefFactoryBean);
    just(event).transform(flowRefProcessor).block();
    verify((MuleContextAware) targetMuleContextAwareAware, atLeastOnce()).setMuleContext(mockMuleContext);
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) MuleContextAware(org.mule.runtime.core.api.context.MuleContextAware) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) SubflowMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder) SmallTest(org.mule.tck.size.SmallTest) 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