use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class DefaultExpressionManagerMelDefaultTestCase method flowName.
@Test
@Description("Verifies that the flow variable exposing it's name works.")
public void flowName() throws MuleException {
FlowConstruct mockFlowConstruct = mock(FlowConstruct.class);
when(mockFlowConstruct.getName()).thenReturn("myFlowName");
String result = (String) expressionManager.evaluate("#[flow.name]", testEvent(), fromSingleComponent(mockFlowConstruct.getName())).getValue();
assertThat(result, is(mockFlowConstruct.getName()));
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class FirstSuccessfulTestCase method createFirstSuccessfulRouter.
private FirstSuccessful createFirstSuccessfulRouter(Processor... processors) throws Exception {
FirstSuccessful fs = new FirstSuccessful();
fs.setAnnotations(getAppleFlowComponentLocationAnnotations());
final FlowConstruct flow = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
when(flow.getMuleContext()).thenReturn(muleContext);
when(((Component) flow).getLocation()).thenReturn(TEST_CONNECTOR_LOCATION);
fs.setMuleContext(muleContext);
fs.setRoutes(asList(processors));
return fs;
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class NotificationHelperTestCase method fireNotificationForEvent.
@Test
public void fireNotificationForEvent() {
when(messageSource.getLocation()).thenReturn(TEST_CONNECTOR_LOCATION);
final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
when(flowConstruct.getMuleContext()).thenReturn(muleContext);
final int action = 100;
helper.fireNotification(messageSource, event, TEST_CONNECTOR_LOCATION, action);
assertConnectorMessageNotification(eventNotificationHandler, messageSource, TEST_CONNECTOR_LOCATION, action);
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class NotificationHelperTestCase method fireNotificationUsingLocation.
@Test
public void fireNotificationUsingLocation() {
final LocationPart flowPart = mock(LocationPart.class);
when(flowPart.getPartPath()).thenReturn("flowName");
final ComponentLocation location = mock(ComponentLocation.class);
when(location.getParts()).thenReturn(Collections.singletonList(flowPart));
when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder().type(SOURCE).identifier(buildFromStringRepresentation("http:listener")).build());
when(messageSource.getLocation()).thenReturn(location);
final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class));
when(flowConstruct.getMuleContext()).thenReturn(muleContext);
final int action = 100;
helper.fireNotification(messageSource, event, location, action);
assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action);
}
use of org.mule.runtime.core.api.construct.FlowConstruct in project mule by mulesoft.
the class FlowProcessingPhase method runPhase.
@Override
public void runPhase(final FlowProcessingPhaseTemplate flowProcessingPhaseTemplate, final MessageProcessContext messageProcessContext, final PhaseResultNotifier phaseResultNotifier) {
Runnable flowExecutionWork = () -> {
try {
FlowConstruct flowConstruct = registry.<FlowConstruct>lookupByName(messageProcessContext.getMessageSource().getRootContainerLocation().toString()).get();
try {
final AtomicReference exceptionThrownDuringFlowProcessing = new AtomicReference();
TransactionalExecutionTemplate<CoreEvent> transactionTemplate = createTransactionalExecutionTemplate(muleContext, messageProcessContext.getTransactionConfig().orElse(new MuleTransactionConfig()));
CoreEvent response = transactionTemplate.execute(() -> {
try {
Object message = flowProcessingPhaseTemplate.getOriginalMessage();
if (message == null) {
return null;
}
CoreEvent muleEvent = flowProcessingPhaseTemplate.getEvent();
muleEvent = flowProcessingPhaseTemplate.beforeRouteEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.routeEvent(muleEvent);
muleEvent = flowProcessingPhaseTemplate.afterRouteEvent(muleEvent);
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, muleEvent, flowProcessingPhaseTemplate);
return muleEvent;
} catch (Exception e) {
exceptionThrownDuringFlowProcessing.set(e);
throw e;
}
});
if (exceptionThrownDuringFlowProcessing.get() != null && !(exceptionThrownDuringFlowProcessing.get() instanceof ResponseDispatchException)) {
sendResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, response, flowProcessingPhaseTemplate);
}
flowProcessingPhaseTemplate.afterSuccessfulProcessingFlow(response);
} catch (ResponseDispatchException e) {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
} catch (MessagingException e) {
sendFailureResponseIfNeccessary(messageProcessContext.getMessageSource(), flowConstruct, e, flowProcessingPhaseTemplate);
flowProcessingPhaseTemplate.afterFailureProcessingFlow(e);
}
phaseResultNotifier.phaseSuccessfully();
} catch (Exception e) {
MuleException me = new DefaultMuleException(e);
try {
flowProcessingPhaseTemplate.afterFailureProcessingFlow(me);
} catch (MuleException e1) {
logger.warn("Failure during exception processing in flow template: " + e.getMessage());
if (logger.isDebugEnabled()) {
logger.debug("Failure during exception processing in flow template: ", e);
}
}
phaseResultNotifier.phaseFailure(e);
}
};
if (messageProcessContext.supportsAsynchronousProcessing()) {
try {
messageProcessContext.getFlowExecutionExecutor().execute(flowExecutionWork);
} catch (SchedulerBusyException e) {
phaseResultNotifier.phaseFailure(e);
}
} else {
flowExecutionWork.run();
}
}
Aggregations