Search in sources :

Example 16 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class SplitAggregateScopeTestCase method defaultTarget.

@Test
@Description("By default the router result populates the outgoing message payload.")
public void defaultTarget() throws Exception {
    CoreEvent original = createListEvent();
    MessageProcessorChain nested = newChain(empty(), event -> event);
    nested.setMuleContext(muleContext);
    router.setMessageProcessors(singletonList(nested));
    muleContext.getInjector().inject(router);
    router.setAnnotations(getAppleFlowComponentLocationAnnotations());
    router.initialise();
    Event result = router.process(original);
    assertThat(result.getMessage().getPayload().getValue(), instanceOf(List.class));
    List<Message> resultList = (List<Message>) result.getMessage().getPayload().getValue();
    assertThat(resultList, hasSize(2));
}
Also used : MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Event(org.mule.runtime.api.event.Event) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 17 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method flowVarsMerged.

@Test
@Description("After successful completion of all routes the variables from each route are merged into the result.")
public void flowVarsMerged() throws Throwable {
    final String beforeVarName = "before";
    final String beforeVarValue = "beforeValue";
    final String beforeVar2Name = "before2";
    final String beforeVar2Value = "before2Value";
    final String beforeVar2NewValue = "before2NewValue";
    final String fooVarName = "foo";
    final String fooVarValue = "fooValue1";
    final String fooVar2Name = "foo2";
    final String fooVar2Value1 = "foo2Value1";
    final String fooVar2Value2 = "foo2Value2";
    final String fooVar3Name = "foo3";
    final String fooVar3Value1 = "foo3Value1";
    final Apple fooVar3Value2 = new Apple();
    CoreEvent original = builder(this.<CoreEvent>newEvent()).addVariable(beforeVarName, beforeVarValue).addVariable(beforeVar2Name, beforeVar2Value).build();
    RoutingPair pair1 = of(original, createChain(event -> builder(event).addVariable(beforeVar2Name, beforeVar2NewValue).addVariable(fooVarName, fooVarValue).addVariable(fooVar2Name, fooVar2Value1).addVariable(fooVar3Name, fooVar3Value1).build()));
    RoutingPair pair2 = of(original, createChain(event -> builder(event).addVariable(fooVar2Name, fooVar2Value2).addVariable(fooVar3Name, fooVar3Value2).build()));
    CoreEvent result = invokeStrategyBlocking(strategy, original, asList(pair1, pair2));
    assertThat(result.getVariables().keySet(), hasSize(5));
    assertThat(result.getVariables().keySet(), hasItems(beforeVarName, beforeVar2Name, fooVarName, fooVarName, fooVar2Name, fooVar3Name));
    assertThat(result.getVariables().get(beforeVarName).getValue(), equalTo(beforeVarValue));
    assertThat(result.getVariables().get(beforeVar2Name).getValue(), equalTo(beforeVar2NewValue));
    assertThat(result.getVariables().get(fooVarName).getValue(), equalTo(fooVarValue));
    TypedValue fooVar2 = result.getVariables().get(fooVar2Name);
    assertThat(fooVar2.getDataType(), equalTo(DataType.builder().collectionType(List.class).itemType(String.class).build()));
    assertThat(((List<String>) fooVar2.getValue()), hasItems(fooVar2Value1, fooVar2Value2));
    TypedValue fooVar3 = result.getVariables().get(fooVar3Name);
    assertThat(fooVar3.getDataType(), equalTo(DataType.builder().collectionType(List.class).itemType(Object.class).build()));
    assertThat(((List<Object>) fooVar3.getValue()), hasItems(fooVar3Value1, fooVar3Value2));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) Schedulers.fromExecutorService(reactor.core.scheduler.Schedulers.fromExecutorService) Apple(org.mule.tck.testmodels.fruit.Apple) IntStream.range(java.util.stream.IntStream.range) Message(org.mule.runtime.api.message.Message) MAX_VALUE(java.lang.Integer.MAX_VALUE) TimeoutException(java.util.concurrent.TimeoutException) Matchers.hasItems(org.hamcrest.Matchers.hasItems) CoreEvent.builder(org.mule.runtime.core.api.event.CoreEvent.builder) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Scheduler(org.mule.runtime.api.scheduler.Scheduler) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Thread.sleep(java.lang.Thread.sleep) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Flux.fromIterable(reactor.core.publisher.Flux.fromIterable) ForkJoinStrategy(org.mule.runtime.core.internal.routing.ForkJoinStrategy) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Message.of(org.mule.runtime.api.message.Message.of) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Matchers.any(org.mockito.Matchers.any) List(java.util.List) AbstractMuleContextTestCase(org.mule.tck.junit4.AbstractMuleContextTestCase) Mockito.atMost(org.mockito.Mockito.atMost) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) RoutingPair.of(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair.of) Mockito.mock(org.mockito.Mockito.mock) CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Callable(java.util.concurrent.Callable) Mockito.spy(org.mockito.Mockito.spy) Processor(org.mule.runtime.core.api.processor.Processor) Function(java.util.function.Function) TIMEOUT(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.TIMEOUT) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Feature(io.qameta.allure.Feature) MuleException(org.mule.runtime.api.exception.MuleException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) Mono.from(reactor.core.publisher.Mono.from) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) CheckedConsumer(org.mule.runtime.core.api.util.func.CheckedConsumer) DataType(org.mule.runtime.api.metadata.DataType) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Mockito.times(org.mockito.Mockito.times) FORK_JOIN_STRATEGIES(org.mule.test.allure.AllureConstants.ForkJoinStrategiesFeature.FORK_JOIN_STRATEGIES) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) TypedValue(org.mule.runtime.api.metadata.TypedValue) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) Rule(org.junit.Rule) Exceptions.rxExceptionToMuleException(org.mule.runtime.core.api.rx.Exceptions.rxExceptionToMuleException) Description(io.qameta.allure.Description) Apple(org.mule.tck.testmodels.fruit.Apple) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 18 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method concurrentRejectedExecution.

@Test
@Description("When executing concurrently the strategy will throw a RejectedExceptionException if the scheduler being used throws a RejectedExceptionException.")
public void concurrentRejectedExecution() throws Throwable {
    when(scheduler.submit(any(Callable.class))).thenThrow(new RejectedExecutionException());
    setupConcurrentProcessingStrategy();
    strategy = createStrategy(processingStrategy, 4, true, MAX_VALUE);
    expectedException.expect(MessagingException.class);
    expectedException.expectCause(instanceOf(RejectedExecutionException.class));
    invokeStrategyBlocking(strategy, testEvent(), createRoutingPairs(1));
}
Also used : Callable(java.util.concurrent.Callable) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 19 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method errorDelayed.

@Test
@Description("When an error occurs all routes are executed regardless and a CompositeRoutingException is thrown containing a RoutingResult with details of both failures and successes.")
public void errorDelayed() throws Throwable {
    Processor processorSpy = createProcessorSpy(testEvent().getMessage());
    RuntimeException exception1 = new IllegalStateException();
    RoutingPair failingPair1 = of(testEvent(), createFailingRoutingPair(exception1));
    RuntimeException exception2 = new UnsupportedOperationException();
    RoutingPair failingPair2 = of(testEvent(), createFailingRoutingPair(exception2));
    RuntimeException exception3 = new IndexOutOfBoundsException();
    RoutingPair failingPair3 = of(testEvent(), createFailingRoutingPair(exception3));
    RoutingPair okPair = of(testEvent(), createChain(processorSpy));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair1, failingPair2, failingPair3, okPair), throwable -> {
        verify(processorSpy, times(1)).process(any(CoreEvent.class));
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 3);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 1, 3);
        assertThat(routingResult.getFailures().get("0").getCause(), is(exception1));
        assertThat(routingResult.getFailures().get("1").getCause(), is(exception2));
        assertThat(routingResult.getFailures().get("2").getCause(), is(exception3));
        assertThat(routingResult.getFailures().get("3"), is(nullValue()));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) InternalProcessor(org.mule.runtime.core.privileged.processor.InternalProcessor) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 20 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class AbstractForkJoinStrategyTestCase method error.

@Test
@Description("Errors are thrown via CompositeRoutingException with RoutingResult containing details of failures.")
public void error() throws Throwable {
    RuntimeException exception = new IllegalStateException();
    RoutingPair failingPair = of(testEvent(), createFailingRoutingPair(exception));
    expectedException.expect(instanceOf(CompositeRoutingException.class));
    invokeStrategyBlocking(strategy, testEvent(), asList(failingPair), throwable -> {
        CompositeRoutingException compositeRoutingException = assertCompositeRoutingException(throwable, 1);
        RoutingResult routingResult = assertRoutingResult(compositeRoutingException, 0, 1);
        assertThat(routingResult.getFailures().get("0").getCause(), is(exception));
    });
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) RoutingPair(org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Description (io.qameta.allure.Description)123 Test (org.junit.Test)111 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)41 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Message (org.mule.runtime.api.message.Message)13 TypedValue (org.mule.runtime.api.metadata.TypedValue)13 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)12 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)12 OperationParameters (org.mule.runtime.extension.api.client.OperationParameters)12 Issue (io.qameta.allure.Issue)10 Matchers.anyString (org.mockito.Matchers.anyString)8 List (java.util.List)7 MavenConfiguration (org.mule.maven.client.api.model.MavenConfiguration)7 Processor (org.mule.runtime.core.api.processor.Processor)7 PlainCommand (com.axibase.tsd.api.model.command.PlainCommand)6 PropertyCommand (com.axibase.tsd.api.model.command.PropertyCommand)6 Property (com.axibase.tsd.api.model.property.Property)6 RemoteRepository (org.mule.maven.client.api.model.RemoteRepository)6 Event (org.mule.runtime.api.event.Event)6 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)6