use of org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder 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);
}
use of org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder in project mule by mulesoft.
the class FlowRefFactoryBean method getReferencedFlow.
protected Processor getReferencedFlow(String name, FlowRefMessageProcessor flowRefMessageProcessor) throws MuleException {
if (name == null) {
throw new RoutePathNotFoundException(createStaticMessage("flow-ref name expression returned 'null'"), flowRefMessageProcessor);
}
Component referencedFlow = getReferencedProcessor(name);
if (referencedFlow == null) {
throw new RoutePathNotFoundException(createStaticMessage("No flow/sub-flow with name '%s' found", name), flowRefMessageProcessor);
}
// for subflows, we create a new one so it must be initialised manually
if (!(referencedFlow instanceof Flow)) {
if (referencedFlow instanceof SubflowMessageProcessorChainBuilder) {
MessageProcessorChainBuilder chainBuilder = (MessageProcessorChainBuilder) referencedFlow;
locator.find(flowRefMessageProcessor.getRootContainerLocation()).filter(c -> c instanceof Flow).map(c -> (Flow) c).ifPresent(f -> chainBuilder.setProcessingStrategy(f.getProcessingStrategy()));
referencedFlow = chainBuilder.build();
}
initialiseIfNeeded(referencedFlow, muleContext);
Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations());
annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString());
referencedFlow.setAnnotations(annotations);
startIfNeeded(referencedFlow);
}
return (Processor) referencedFlow;
}
use of org.mule.runtime.core.internal.processor.chain.SubflowMessageProcessorChainBuilder in project mule by mulesoft.
the class SubflowMessageProcessorChainFactoryBean method getBuilderInstance.
protected SubflowMessageProcessorChainBuilder getBuilderInstance() {
SubflowMessageProcessorChainBuilder builder = new SubflowMessageProcessorChainBuilder();
builder.setName(name);
return builder;
}
Aggregations