Search in sources :

Example 26 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class SetPayloadMessageProcessorTestCase method setUp.

@Before
public void setUp() throws Exception {
    setPayloadMessageProcessor = new SetPayloadMessageProcessor();
    muleContext = mock(MuleContext.class);
    setPayloadMessageProcessor.setMuleContext(muleContext);
    expressionManager = mock(ExtendedExpressionManager.class);
    when(muleContext.getExpressionManager()).thenReturn(expressionManager);
    when(muleContext.getConfiguration()).thenReturn(mock(MuleConfiguration.class));
    when(expressionManager.parse(anyString(), any(CoreEvent.class), any(ComponentLocation.class))).thenAnswer(invocation -> (String) invocation.getArguments()[0]);
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) SetPayloadMessageProcessor(org.mule.runtime.core.internal.processor.simple.SetPayloadMessageProcessor) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ExtendedExpressionManager(org.mule.runtime.core.api.el.ExtendedExpressionManager) Before(org.junit.Before)

Example 27 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class DefaultMessageProcessorChainTestCase method testAll.

@Test
public void testAll() throws Exception {
    createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    ScatterGatherRouter scatterGatherRouter = new ScatterGatherRouter();
    scatterGatherRouter.setAnnotations(getAppleFlowComponentLocationAnnotations());
    scatterGatherRouter.setRoutes(asList(newChain(empty(), getAppendingMP("1")), newChain(empty(), getAppendingMP("2")), newChain(empty(), getAppendingMP("3"))));
    initialiseIfNeeded(scatterGatherRouter, true, muleContext);
    scatterGatherRouter.start();
    CoreEvent event = getTestEventUsingFlow("0");
    final MessageProcessorChain chain = newChain(empty(), singletonList(scatterGatherRouter));
    Message result = process(chain, CoreEvent.builder(event).message(event.getMessage()).build()).getMessage();
    assertThat(result.getPayload().getValue(), instanceOf(Map.class));
    Map<String, Message> resultMessage = (Map<String, Message>) result.getPayload().getValue();
    assertThat(resultMessage.values().stream().map(msg -> msg.getPayload().getValue()).collect(toList()).toArray(), is(equalTo(new String[] { "01", "02", "03" })));
    scatterGatherRouter.stop();
    scatterGatherRouter.dispose();
}
Also used : Flow.builder(org.mule.runtime.core.api.construct.Flow.builder) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) Message(org.mule.runtime.api.message.Message) Assert.assertNotSame(org.junit.Assert.assertNotSame) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) ExceptionContextProvider(org.mule.runtime.core.api.execution.ExceptionContextProvider) ScatterGatherRouter(org.mule.runtime.core.internal.routing.ScatterGatherRouter) Collections.singletonList(java.util.Collections.singletonList) MuleContextAware(org.mule.runtime.core.api.context.MuleContextAware) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) SmallTest(org.mule.tck.size.SmallTest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays.asList(java.util.Arrays.asList) ReactorProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.ReactorProcessingStrategyFactory) NON_BLOCKING(org.mule.tck.junit4.AbstractReactiveProcessorTestCase.Mode.NON_BLOCKING) After(org.junit.After) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) REGISTRY_KEY(org.mule.runtime.api.component.location.ConfigurationComponentLocator.REGISTRY_KEY) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) LifecycleUtils.stopIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded) CPU_INTENSIVE(org.mule.runtime.core.api.processor.ReactiveProcessor.ProcessingType.CPU_INTENSIVE) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) Parameterized(org.junit.runners.Parameterized) BLOCKING(org.mule.tck.junit4.AbstractReactiveProcessorTestCase.Mode.BLOCKING) Collection(java.util.Collection) MessageProcessorNotification(org.mule.runtime.api.notification.MessageProcessorNotification) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Message.of(org.mule.runtime.api.message.Message.of) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) ResponseMessageProcessorAdapter(org.mule.runtime.core.internal.processor.ResponseMessageProcessorAdapter) ProactorStreamProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.ProactorStreamProcessingStrategyFactory) Matchers.any(org.mockito.Matchers.any) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) List(java.util.List) AbstractReactiveProcessorTestCase(org.mule.tck.junit4.AbstractReactiveProcessorTestCase) Assert.assertFalse(org.junit.Assert.assertFalse) MESSAGE_PROCESSOR_PRE_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_PRE_INVOKE) ErrorType(org.mule.runtime.api.message.ErrorType) AbstractInterceptingMessageProcessor(org.mule.runtime.core.privileged.processor.AbstractInterceptingMessageProcessor) Mockito.mock(org.mockito.Mockito.mock) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) Optional.empty(java.util.Optional.empty) MessageProcessorBuilder(org.mule.runtime.core.privileged.processor.MessageProcessorBuilder) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Flux.from(reactor.core.publisher.Flux.from) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) Mockito.spy(org.mockito.Mockito.spy) Processor(org.mule.runtime.core.api.processor.Processor) DirectProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.DirectProcessingStrategyFactory) MESSAGE_PROCESSOR_POST_INVOKE(org.mule.runtime.api.notification.MessageProcessorNotification.MESSAGE_PROCESSOR_POST_INVOKE) ChoiceRouter(org.mule.runtime.core.internal.routing.ChoiceRouter) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) ObjectUtils(org.mule.runtime.core.api.util.ObjectUtils) Collections.singletonMap(java.util.Collections.singletonMap) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) BlockingProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.BlockingProcessingStrategyFactory) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) EventContextFactory.create(org.mule.runtime.core.api.event.EventContextFactory.create) Assert.assertTrue(org.junit.Assert.assertTrue) MessageProcessorNotificationListener(org.mule.runtime.api.notification.MessageProcessorNotificationListener) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) APPLE_FLOW(org.mule.tck.MuleTestUtils.APPLE_FLOW) TransactionAwareWorkQueueProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.TransactionAwareWorkQueueProcessingStrategyFactory) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Collectors.toList(java.util.stream.Collectors.toList) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) WorkQueueProcessingStrategyFactory(org.mule.runtime.core.internal.processor.strategy.WorkQueueProcessingStrategyFactory) RandomStringUtils.randomNumeric(org.apache.commons.lang3.RandomStringUtils.randomNumeric) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleConfiguration(org.mule.runtime.core.api.config.MuleConfiguration) Assert.assertEquals(org.junit.Assert.assertEquals) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) ScatterGatherRouter(org.mule.runtime.core.internal.routing.ScatterGatherRouter) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 28 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class CompositeConverterTestCase method appliesTransformerChainOnMessage.

@Test
public void appliesTransformerChainOnMessage() throws Exception {
    CompositeConverter compositeConverter = new CompositeConverter(mockConverterA, mockConverterB);
    MuleContext muleContext = mock(MuleContext.class, RETURNS_DEEP_STUBS);
    compositeConverter.setMuleContext(muleContext);
    final CoreEvent event = testEvent();
    ExtendedTransformationService transformationService = mock(ExtendedTransformationService.class);
    doReturn(mock(Message.class)).when(transformationService).applyTransformers(any(), eq(event), eq(compositeConverter));
    doReturn(transformationService).when(muleContext).getTransformationService();
    compositeConverter.process(event);
    verify(transformationService, times(1)).applyTransformers(eq(testEvent().getMessage()), eq(testEvent()), eq(compositeConverter));
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 29 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class CompositeConverterTestCase method setMuleContext.

@Test
public void setMuleContext() {
    MuleContext mockMuleContext = mock(MuleContext.class);
    CompositeConverter compositeConverter = new CompositeConverter(mockConverterA, mockConverterB);
    compositeConverter.setMuleContext(mockMuleContext);
    verify(mockConverterA, atLeastOnce()).setMuleContext(mockMuleContext);
    verify(mockConverterB, atLeastOnce()).setMuleContext(mockMuleContext);
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 30 with MuleContext

use of org.mule.runtime.core.api.MuleContext in project mule by mulesoft.

the class AbstractLifecycleManager method doOnConnectException.

protected void doOnConnectException(ConnectException ce) throws LifecycleException {
    MuleContext muleContext = ((LegacyConnector) ce.getFailed()).getMuleContext();
    muleContext.getExceptionListener().handleException(ce);
}
Also used : MuleContext(org.mule.runtime.core.api.MuleContext) LegacyConnector(org.mule.runtime.core.privileged.transport.LegacyConnector)

Aggregations

MuleContext (org.mule.runtime.core.api.MuleContext)46 Test (org.junit.Test)17 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Before (org.junit.Before)8 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)8 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)8 MuleException (org.mule.runtime.api.exception.MuleException)7 LifecycleUtils.initialiseIfNeeded (org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded)7 Map (java.util.Map)6 Optional (java.util.Optional)6 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)6 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)5 ConfigurationBuilder (org.mule.runtime.core.api.config.ConfigurationBuilder)5 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Optional.ofNullable (java.util.Optional.ofNullable)4 MuleConfiguration (org.mule.runtime.core.api.config.MuleConfiguration)4