Search in sources :

Example 1 with Flow

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

the class DefaultFlowBuilderTestCase method buildsFullFlow.

@Test
public void buildsFullFlow() throws Exception {
    Processor processor1 = mock(Processor.class);
    Processor processor2 = mock(Processor.class);
    List<Processor> messageProcessors = new ArrayList<>();
    messageProcessors.add(processor1);
    messageProcessors.add(processor2);
    MessageSource messageSource = mock(MessageSource.class);
    ProcessingStrategyFactory processingStrategyFactory = mock(ProcessingStrategyFactory.class);
    ProcessingStrategy processingStrategy = mock(ProcessingStrategy.class);
    when(processingStrategyFactory.create(any(), any())).thenReturn(processingStrategy);
    FlowExceptionHandler exceptionListener = mock(FlowExceptionHandler.class);
    Flow flow = flowBuilder.processors(messageProcessors).source(messageSource).processingStrategyFactory(processingStrategyFactory).messagingExceptionHandler(exceptionListener).build();
    assertThat(flow.getName(), equalTo(FLOW_NAME));
    assertThat(flow.getMuleContext(), is(muleContext));
    assertThat(flow.getProcessors(), contains(processor1, processor2));
    assertThat(flow.getSource(), is(messageSource));
    assertThat(flow.getExceptionListener(), is(exceptionListener));
    assertThat(flow.getProcessingStrategy(), sameInstance(processingStrategy));
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) ProcessingStrategyFactory(org.mule.runtime.core.api.processor.strategy.ProcessingStrategyFactory) MessageSource(org.mule.runtime.core.api.source.MessageSource) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) FlowExceptionHandler(org.mule.runtime.core.api.exception.FlowExceptionHandler) Flow(org.mule.runtime.core.api.construct.Flow) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with Flow

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

the class DefaultFlowBuilderTestCase method buildsSimpleFlow.

@Test
public void buildsSimpleFlow() throws Exception {
    Flow flow = flowBuilder.build();
    assertThat(flow.getName(), equalTo(FLOW_NAME));
    assertThat(flow.getMuleContext(), is(muleContext));
    assertThat(flow.getProcessors(), is(empty()));
    assertThat(flow.getSource(), is(nullValue()));
    assertThat(flow.getExceptionListener(), not(sameInstance(muleContext.getDefaultErrorHandler(Optional.empty()))));
    assertThat(flow.getProcessingStrategy(), sameInstance(processingStrategy));
}
Also used : Flow(org.mule.runtime.core.api.construct.Flow) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with Flow

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

the class DefaultFlowTestCase method customMaxConcurrency.

@Test
public void customMaxConcurrency() throws Exception {
    int customMaxConcurrency = 1;
    Flow customFlow = Flow.builder(FLOW_NAME, muleContext).source(directInboundMessageSource).processors(getSensingNullMessageProcessor()).maxConcurrency(customMaxConcurrency).build();
    try {
        customFlow.initialise();
        customFlow.start();
        assertThat(customFlow.getMaxConcurrency(), equalTo(customMaxConcurrency));
        verify(muleContext.getSchedulerService()).ioScheduler(eq(muleContext.getSchedulerBaseConfig().withName(flow.getName() + "." + BLOCKING.name())));
        customFlow.stop();
    } finally {
        customFlow.dispose();
    }
}
Also used : DefaultFlow(org.mule.runtime.core.internal.construct.DefaultFlowBuilder.DefaultFlow) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Example 4 with Flow

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

the class ResequencerTestCase method testMessageResequencer.

@Test
public void testMessageResequencer() throws Exception {
    MuleSession session = new DefaultMuleSession();
    Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    assertNotNull(flow);
    TestEventResequencer router = new TestEventResequencer(3);
    router.setMuleContext(muleContext);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(router, true, muleContext);
    EventContext context = create(flow, TEST_CONNECTOR_LOCATION, "foo");
    Message message1 = Message.of("test event A");
    Message message2 = Message.of("test event B");
    Message message3 = Message.of("test event C");
    CoreEvent event1 = InternalEvent.builder(context).message(message1).session(session).build();
    CoreEvent event2 = InternalEvent.builder(context).message(message2).session(session).build();
    CoreEvent event3 = InternalEvent.builder(context).message(message3).session(session).build();
    assertNull(router.process(event2));
    assertNull(router.process(event3));
    CoreEvent resultEvent = router.process(event1);
    assertNotNull(resultEvent);
    Message resultMessage = resultEvent.getMessage();
    assertNotNull(resultMessage);
    assertTrue(getPayloadAsString(resultMessage).equals("test event A") || getPayloadAsString(resultMessage).equals("test event B") || getPayloadAsString(resultMessage).equals("test event C"));
}
Also used : EventContext(org.mule.runtime.api.event.EventContext) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) MuleSession(org.mule.runtime.core.privileged.event.MuleSession) DefaultMuleSession(org.mule.runtime.core.privileged.event.DefaultMuleSession) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) MuleTestUtils.createFlow(org.mule.tck.MuleTestUtils.createFlow) Test(org.junit.Test)

Example 5 with Flow

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

the class SimpleCollectionAggregatorTestCase method testAggregateMessageCollections.

@Test
public void testAggregateMessageCollections() throws Exception {
    Flow flow = createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    assertNotNull(flow);
    SimpleCollectionAggregator router = new SimpleCollectionAggregator();
    router.setMuleContext(muleContext);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    initialiseIfNeeded(router, true, muleContext);
    EventContext executionContext = create(flow, TEST_CONNECTOR_LOCATION, "foo");
    Message message1 = of("test event A");
    Message message2 = of("test event B");
    Message message3 = of("test event C");
    Message message4 = of("test event D");
    List<Message> list = new ArrayList<>();
    List<Message> list2 = new ArrayList<>();
    list.add(message1);
    list.add(message2);
    list2.add(message3);
    list2.add(message4);
    Message messageCollection1 = Message.of(list);
    Message messageCollection2 = Message.of(list2);
    CoreEvent event1 = InternalEvent.builder(executionContext).message(messageCollection1).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
    CoreEvent event2 = InternalEvent.builder(executionContext).message(messageCollection2).groupCorrelation(Optional.of(GroupCorrelation.of(0, 2))).build();
    assertNull(router.process(event1));
    CoreEvent resultEvent = router.process(event2);
    assertNotNull(resultEvent);
    Message resultMessage = resultEvent.getMessage();
    assertNotNull(resultMessage);
    List<InternalMessage> payload = (List<InternalMessage>) resultMessage.getPayload().getValue();
    assertEquals(2, payload.size());
    assertEquals("test event A", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(0).getPayload().getValue());
    assertEquals("test event B", ((List<InternalMessage>) payload.get(0).getPayload().getValue()).get(1).getPayload().getValue());
    assertEquals("test event C", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(0).getPayload().getValue());
    assertEquals("test event D", ((List<InternalMessage>) payload.get(1).getPayload().getValue()).get(1).getPayload().getValue());
}
Also used : EventContext(org.mule.runtime.api.event.EventContext) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Message(org.mule.runtime.api.message.Message) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MuleTestUtils.createAndRegisterFlow(org.mule.tck.MuleTestUtils.createAndRegisterFlow) Flow(org.mule.runtime.core.api.construct.Flow) Test(org.junit.Test)

Aggregations

Flow (org.mule.runtime.core.api.construct.Flow)37 Test (org.junit.Test)25 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)19 Message (org.mule.runtime.api.message.Message)14 MuleException (org.mule.runtime.api.exception.MuleException)10 Processor (org.mule.runtime.core.api.processor.Processor)10 EventContext (org.mule.runtime.api.event.EventContext)9 ArrayList (java.util.ArrayList)8 Arrays.asList (java.util.Arrays.asList)8 List (java.util.List)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Collectors.toList (java.util.stream.Collectors.toList)8 Assert.assertThat (org.junit.Assert.assertThat)8 Thread.currentThread (java.lang.Thread.currentThread)7 Collection (java.util.Collection)7 After (org.junit.After)7 Before (org.junit.Before)7 Rule (org.junit.Rule)7 ExpectedException (org.junit.rules.ExpectedException)7 RunWith (org.junit.runner.RunWith)7