use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class ChoiceRouterTestCase method testUpdateRoute.
@Test
public void testUpdateRoute() throws Exception {
MessageProcessorChain mp = newChain(empty(), new TestMessageProcessor("bar"));
choiceRouter.addRoute(payloadPazExpression(), mp);
choiceRouter.updateRoute(payloadZapExpression(), mp);
choiceRouter.setMuleContext(muleContext);
choiceRouter.initialise();
assertThat(process(choiceRouter, zapEvent()).getMessage().getPayload().getValue(), is("zap:bar"));
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class MessageProcessorChainObjectFactory method doGetObject.
@Override
public MessageProcessorChain doGetObject() throws Exception {
MessageProcessorChainBuilder builder = getBuilderInstance();
for (Object processor : processors) {
if (processor instanceof Processor) {
builder.chain((Processor) processor);
} else {
throw new IllegalArgumentException(format("MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured. Found a %s", processor.getClass().getName()));
}
}
MessageProcessorChain messageProcessorChain = builder.build();
messageProcessorChain.setMuleContext(muleContext);
return messageProcessorChain;
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain in project mule by mulesoft.
the class CompositeProcessorChainRouterTestCase method childContextChain.
@Test
@Description("Ensure that when a child context is created as part of the execution of one of the composite chains then the chain does not complete and the next chains is not executed until the child context completes.")
public void childContextChain() throws Exception {
Latch latch = new Latch();
AtomicReference<BaseEventContext> childEventContext = new AtomicReference<>();
MessageProcessorChain chainUsingChildContext = newChain(empty(), event -> {
latch.release();
childEventContext.set(child((BaseEventContext) event.getContext(), empty()));
return event;
});
chainRouter = createCompositeProcessorChainRouter(chainUsingChildContext, newChain(empty(), event -> event));
// CompletableFuture is not returned immediately because simply invoking CompositeProcessorChainRouter there is no async
// hand-off and so this blocks until child context completes.
Future<CompletableFuture<Event>> future = scheduler.submit(() -> chainRouter.execute(testEvent()));
latch.await();
try {
future.get(BLOCK_TIMEOUT, MILLISECONDS);
fail("Timeout expected");
} catch (TimeoutException te) {
}
childEventContext.get().success();
assertThat(future.get(BLOCK_TIMEOUT, MILLISECONDS).get().getMessage(), equalTo(testEvent().getMessage()));
}
use of org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain 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.privileged.processor.chain.MessageProcessorChain 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