use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class FlowRefFactoryBeanTestCase method getFlowRefProcessor.
private Processor getFlowRefProcessor(FlowRefFactoryBean factoryBean) throws Exception {
Processor processor = factoryBean.getObject();
setMuleContextIfNeeded(processor, mockMuleContext);
return processor;
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class FlowRefFactoryBeanTestCase method verifyProcess.
private void verifyProcess(FlowRefFactoryBean flowRefFactoryBean, Processor target, int lifecycleRounds) throws Exception {
Processor flowRefProcessor = getFlowRefProcessor(flowRefFactoryBean);
initialiseIfNeeded(flowRefProcessor);
startIfNeeded(flowRefProcessor);
assertSame(result.getMessage(), just(newEvent()).cast(CoreEvent.class).transform(flowRefProcessor).block().getMessage());
assertSame(result.getMessage(), just(newEvent()).cast(CoreEvent.class).transform(flowRefProcessor).block().getMessage());
verify(applicationContext).getBean(anyString());
verify(target, times(2)).apply(any(Publisher.class));
stopIfNeeded(flowRefProcessor);
disposeIfNeeded(flowRefProcessor, null);
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class FlowRefFactoryBeanTestCase method dynamicFlowRefSubContextAware.
@Test
public void dynamicFlowRefSubContextAware() throws Exception {
CoreEvent event = testEvent();
MuleContextAware targetMuleContextAware = mock(MuleContextAware.class, INITIALIZABLE_MESSAGE_PROCESSOR);
when(((Processor) targetMuleContextAware).apply(any(Publisher.class))).thenReturn(just(result));
FlowRefFactoryBean flowRefFactoryBean = createDynamicFlowRefFactoryBean((Processor) targetMuleContextAware, null);
assertSame(result.getMessage(), getFlowRefProcessor(flowRefFactoryBean).process(event).getMessage());
verify(targetMuleContextAware).setMuleContext(mockMuleContext);
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class FlowRefFactoryBeanTestCase method createStaticFlowRefFactoryBean.
private FlowRefFactoryBean createStaticFlowRefFactoryBean(Processor target, Object targetBuilder) throws InitialisationException {
doReturn(false).when(expressionManager).isExpression(anyString());
if (targetBuilder != null) {
when(applicationContext.getBean(eq(STATIC_REFERENCED_FLOW))).thenReturn(targetBuilder);
} else {
when(applicationContext.getBean(eq(STATIC_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(STATIC_REFERENCED_FLOW);
}
use of org.mule.runtime.core.api.processor.Processor in project mule by mulesoft.
the class MacroExpansionModuleModel method createModuleOperationChain.
/**
* Takes a one liner call to any given message processor, expand it to creating a "module-operation-chain" scope which has the
* set of properties, the set of parameters and the list of message processors to execute.
*
* @param operationRefModel message processor that will be replaced by a scope element named "module-operation-chain".
* @param operationModel operation that provides both the <parameter/>s and content of the <body/>
* @param moduleGlobalElementsNames collection with the global components names (such as <http:config name="a"../>, <file:config
* name="b"../>, <file:matcher name="c"../> and so on) that are contained within the <module/> that will be macro
* expanded
* @param configRefParentTnsName parent reference to the global element if exists (it might not be global elements in the
* current module). Useful when replacing {@link #TNS_PREFIX} operations, as the references to the global elements will
* be those of the rootest element of the operations consumed by the app.
* @param containerName name of the container that contains the operation to be macro expanded. Not null nor empty.
* @return a new component model that represents the old placeholder but expanded with the content of the <body/>
*/
private ComponentModel createModuleOperationChain(ComponentModel operationRefModel, OperationModel operationModel, Set<String> moduleGlobalElementsNames, Optional<String> configRefParentTnsName, String containerName) {
final OperationComponentModelModelProperty operationComponentModelModelProperty = operationModel.getModelProperty(OperationComponentModelModelProperty.class).get();
final ComponentModel operationModuleComponentModel = operationComponentModelModelProperty.getBodyComponentModel();
List<ComponentModel> bodyProcessors = operationModuleComponentModel.getInnerComponents();
Optional<String> configRefName = referencesOperationsWithinModule(operationRefModel) ? configRefParentTnsName : Optional.ofNullable(operationRefModel.getParameters().get(MODULE_OPERATION_CONFIG_REF));
ComponentModel.Builder processorChainBuilder = new ComponentModel.Builder();
processorChainBuilder.setIdentifier(builder().namespace(CORE_PREFIX).name("module-operation-chain").build());
processorChainBuilder.addParameter("moduleName", extensionModel.getXmlDslModel().getPrefix(), false);
processorChainBuilder.addParameter("moduleOperation", operationModel.getName(), false);
Map<String, String> propertiesMap = extractProperties(configRefName);
Map<String, String> parametersMap = extractParameters(operationRefModel, operationModel.getAllParameterModels());
ComponentModel propertiesComponentModel = getParameterChild(propertiesMap, "module-operation-properties", "module-operation-property-entry");
ComponentModel parametersComponentModel = getParameterChild(parametersMap, "module-operation-parameters", "module-operation-parameter-entry");
processorChainBuilder.addChildComponentModel(propertiesComponentModel);
processorChainBuilder.addChildComponentModel(parametersComponentModel);
for (ComponentModel bodyProcessor : bodyProcessors) {
ComponentModel childMPcomponentModel = lookForTNSOperation(bodyProcessor).map(tnsOperation -> createModuleOperationChain(bodyProcessor, tnsOperation, moduleGlobalElementsNames, configRefName, containerName)).orElseGet(() -> copyOperationComponentModel(bodyProcessor, configRefName, moduleGlobalElementsNames, getLiteralParameters(propertiesMap, parametersMap), containerName));
processorChainBuilder.addChildComponentModel(childMPcomponentModel);
}
copyErrorMappings(operationRefModel, processorChainBuilder);
for (Map.Entry<String, Object> customAttributeEntry : operationRefModel.getCustomAttributes().entrySet()) {
processorChainBuilder.addCustomAttribute(customAttributeEntry.getKey(), customAttributeEntry.getValue());
}
processorChainBuilder.addCustomAttribute(ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME, containerName);
ComponentModel processorChainModel = processorChainBuilder.build();
for (ComponentModel processorChainModelChild : processorChainModel.getInnerComponents()) {
processorChainModelChild.setParent(processorChainModel);
}
operationRefModel.getConfigFileName().ifPresent(processorChainBuilder::setConfigFileName);
operationRefModel.getLineNumber().ifPresent(processorChainBuilder::setLineNumber);
processorChainBuilder.addCustomAttribute(ORIGINAL_IDENTIFIER, operationRefModel.getIdentifier());
return processorChainModel;
}
Aggregations