Search in sources :

Example 1 with Apple

use of org.mule.tck.testmodels.fruit.Apple in project mule by mulesoft.

the class ClassUtilsTestCase method testInstanciateClass.

@Test
public void testInstanciateClass() throws Exception {
    Object object = ClassUtils.instantiateClass("org.mule.tck.testmodels.fruit.Orange");
    assertNotNull(object);
    assertTrue(object instanceof Orange);
    object = ClassUtils.instantiateClass("org.mule.tck.testmodels.fruit.FruitBowl", new Apple(), new Banana());
    assertNotNull(object);
    assertTrue(object instanceof FruitBowl);
    FruitBowl bowl = (FruitBowl) object;
    assertTrue(bowl.hasApple());
    assertTrue(bowl.hasBanana());
    try {
        ClassUtils.instantiateClass("java.lang.Bing");
        fail("Class does not exist, ClassNotFoundException should have been thrown");
    } catch (ClassNotFoundException e) {
    // expected
    }
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) FruitBowl(org.mule.tck.testmodels.fruit.FruitBowl) Orange(org.mule.tck.testmodels.fruit.Orange) Banana(org.mule.tck.testmodels.fruit.Banana) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with Apple

use of org.mule.tck.testmodels.fruit.Apple in project mule by mulesoft.

the class ImmutableMapCollectorTestCase method collect.

@Test
public void collect() {
    final List<Fruit> fruits = Arrays.asList(new Apple(), new Banana(), new Kiwi());
    Map<String, Fruit> map = fruits.stream().collect(collector);
    assertThat(map.size(), is(3));
    fruits.forEach(fruit -> {
        Fruit value = map.get(fruit.getClass().getName());
        assertThat(value, sameInstance(fruit));
    });
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) Kiwi(org.mule.tck.testmodels.fruit.Kiwi) Fruit(org.mule.tck.testmodels.fruit.Fruit) Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 3 with Apple

use of org.mule.tck.testmodels.fruit.Apple 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 4 with Apple

use of org.mule.tck.testmodels.fruit.Apple in project mule by mulesoft.

the class AbstractSplitterTestCase method simpleSplitter.

@Test
public void simpleSplitter() throws Exception {
    TestSplitter splitter = new TestSplitter(false);
    MultipleEventSensingMessageProcessor listener = new MultipleEventSensingMessageProcessor();
    splitter.setListener(listener);
    splitter.setMuleContext(muleContext);
    Apple apple = new Apple();
    Banana banana = new Banana();
    Orange orange = new Orange();
    FruitBowl fruitBowl = new FruitBowl();
    fruitBowl.addFruit(apple);
    fruitBowl.addFruit(banana);
    fruitBowl.addFruit(orange);
    final CoreEvent inEvent = eventBuilder(muleContext).message(of(fruitBowl)).build();
    CoreEvent resultEvent = splitter.process(inEvent);
    assertThat(listener.events, hasSize(3));
    assertThat(listener.events.get(0).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(listener.events.get(1).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(listener.events.get(2).getMessage().getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(resultEvent.getMessage().getPayload().getValue(), instanceOf(List.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()), hasSize(3));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(0).getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(1).getPayload().getValue(), instanceOf(Fruit.class));
    assertThat(((List<InternalMessage>) resultEvent.getMessage().getPayload().getValue()).get(2).getPayload().getValue(), instanceOf(Fruit.class));
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) FruitBowl(org.mule.tck.testmodels.fruit.FruitBowl) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) Fruit(org.mule.tck.testmodels.fruit.Fruit) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ArrayList(java.util.ArrayList) List(java.util.List) Orange(org.mule.tck.testmodels.fruit.Orange) Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test)

Example 5 with Apple

use of org.mule.tck.testmodels.fruit.Apple in project mule by mulesoft.

the class ObjectToInputStreamTestCase method testTransformSerializable.

@Test
public void testTransformSerializable() {
    Apple apple = new Apple();
    InputStream serializedApple = new ByteArrayInputStream(muleContext.getObjectSerializer().getExternalProtocol().serialize(apple));
    try {
        assertTrue(compare(serializedApple, (InputStream) transformer.transform(apple)));
    } catch (Exception e) {
        assertTrue(e instanceof TransformerException);
        assertTrue(e.getMessage().contains("does not support source type"));
    }
}
Also used : Apple(org.mule.tck.testmodels.fruit.Apple) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) Test(org.junit.Test)

Aggregations

Apple (org.mule.tck.testmodels.fruit.Apple)15 Test (org.junit.Test)13 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)7 Banana (org.mule.tck.testmodels.fruit.Banana)6 Orange (org.mule.tck.testmodels.fruit.Orange)6 List (java.util.List)4 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)4 SmallTest (org.mule.tck.size.SmallTest)3 Fruit (org.mule.tck.testmodels.fruit.Fruit)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Before (org.junit.Before)2 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)2 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 TypeToken (com.google.common.reflect.TypeToken)1 Description (io.qameta.allure.Description)1 Feature (io.qameta.allure.Feature)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1