Search in sources :

Example 1 with FlowConstruct

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()));
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Matchers.containsString(org.hamcrest.Matchers.containsString) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 2 with FlowConstruct

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;
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Component(org.mule.runtime.api.component.Component)

Example 3 with FlowConstruct

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);
}
Also used : FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Component(org.mule.runtime.api.component.Component) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with FlowConstruct

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);
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) LocationPart(org.mule.runtime.api.component.location.LocationPart) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) Component(org.mule.runtime.api.component.Component) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with FlowConstruct

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();
    }
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) TransactionalExecutionTemplate.createTransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate.createTransactionalExecutionTemplate) TransactionalExecutionTemplate(org.mule.runtime.core.api.execution.TransactionalExecutionTemplate) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ResponseDispatchException(org.mule.runtime.core.privileged.exception.ResponseDispatchException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) SchedulerBusyException(org.mule.runtime.api.scheduler.SchedulerBusyException)

Aggregations

FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)17 Test (org.junit.Test)9 SmallTest (org.mule.tck.size.SmallTest)6 Component (org.mule.runtime.api.component.Component)4 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 Description (io.qameta.allure.Description)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 MuleException (org.mule.runtime.api.exception.MuleException)2 ComponentUtils.getFromAnnotatedObject (org.mule.runtime.core.internal.component.ComponentUtils.getFromAnnotatedObject)2 DefaultExpressionManager (org.mule.runtime.core.internal.el.DefaultExpressionManager)2 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 WeaveDefaultExpressionLanguageFactoryService (org.mule.weave.v2.el.WeaveDefaultExpressionLanguageFactoryService)2 Collection (java.util.Collection)1 Map (java.util.Map)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1