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);
}
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));
}
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;
}
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);
}
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);
}
Aggregations