Search in sources :

Example 31 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationExecutionTestCase method operationWhichReturnsListOfMessages.

@Test
public void operationWhichReturnsListOfMessages() throws Exception {
    TypedValue<List<Message>> payload = runFlow("getAllEnemies").getMessage().getPayload();
    assertThat(payload.getDataType(), is(assignableTo(MULE_MESSAGE_COLLECTION)));
    List<Message> enemies = payload.getValue();
    HeisenbergExtension heisenberg = getConfig(HEISENBERG);
    assertThat(enemies, hasSize(heisenberg.getEnemies().size()));
    int index = 0;
    for (Message enemyMessage : enemies) {
        assertEnemyMessage(heisenberg, index, enemyMessage);
        index++;
    }
}
Also used : Message(org.mule.runtime.api.message.Message) List(java.util.List) ArrayList(java.util.ArrayList) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 32 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationExecutionTestCase method getInlineGroupDefinition.

@Test
public void getInlineGroupDefinition() throws Exception {
    Message message = flowRunner("getBarberPreferences").withPayload(EMPTY_STRING).run().getMessage();
    assertThat(message.getPayload().getValue(), is(notNullValue()));
    assertThat(message.getPayload().getDataType().getMediaType().matches(APPLICATION_JAVA), is(true));
    BarberPreferences preferences = (BarberPreferences) message.getPayload().getValue();
    assertThat(preferences.getBeardTrimming(), is(BarberPreferences.BEARD_KIND.MUSTACHE));
    assertThat(preferences.isFullyBald(), is(false));
}
Also used : BarberPreferences(org.mule.test.heisenberg.extension.model.BarberPreferences) Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 33 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class OperationExecutionTestCase method operationWithReturnValueOnTarget.

@Test
public void operationWithReturnValueOnTarget() throws Exception {
    FlowRunner runner = flowRunner("sayMyNameOnTarget").withPayload(EMPTY_STRING);
    CoreEvent responseEvent = runner.run();
    assertThat(responseEvent.getMessage().getPayload().getValue(), is(EMPTY_STRING));
    Message responseMessage = (Message) responseEvent.getVariables().get("myFace").getValue();
    assertThat(responseMessage.getPayload().getValue(), is(HEISENBERG));
}
Also used : FlowRunner(org.mule.functional.api.flow.FlowRunner) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Test(org.junit.Test)

Example 34 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method skipsConverterThatDoesNotMatchWhenOriginalPayloadMatchesExpectedOutputType.

@Test
public void skipsConverterThatDoesNotMatchWhenOriginalPayloadMatchesExpectedOutputType() throws MuleException {
    // Converter(B->C), payload C: OK - skips transformer but C is the expected output type -> OK
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
    Message message = of(new C());
    message = transformationService.applyTransformers(message, null, converter1);
    assertTrue(message.getPayload().getValue() instanceof C);
    verifyTransformerNotExecuted(converter1);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 35 with Message

use of org.mule.runtime.api.message.Message in project mule by mulesoft.

the class TransformationServiceTestCase method failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion.

@Test
public void failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion() throws MuleException {
    // Converter(B->C), payload A: FAIL
    Transformer converter1 = new MockConverterBuilder().from(dataTypeB).to(dataTypeC).build();
    Message message = of(new A());
    try {
        transformationService.applyTransformers(message, null, converter1);
        fail("Transformation is supposed to fail");
    } catch (IllegalArgumentException expected) {
    }
    verifyTransformerNotExecuted(converter1);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) MockConverterBuilder(org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder) Message(org.mule.runtime.api.message.Message) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Message (org.mule.runtime.api.message.Message)226 Test (org.junit.Test)189 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)104 SmallTest (org.mule.tck.size.SmallTest)68 InternalMessage (org.mule.runtime.core.internal.message.InternalMessage)46 Transformer (org.mule.runtime.core.api.transformer.Transformer)35 DataType (org.mule.runtime.api.metadata.DataType)33 ArrayList (java.util.ArrayList)26 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)26 Processor (org.mule.runtime.core.api.processor.Processor)25 List (java.util.List)20 Assert.assertThat (org.junit.Assert.assertThat)19 ExpectedException (org.junit.rules.ExpectedException)19 MuleContextUtils.eventBuilder (org.mule.tck.util.MuleContextUtils.eventBuilder)19 Map (java.util.Map)18 Rule (org.junit.Rule)18 MockConverterBuilder (org.mule.runtime.core.internal.transformer.builder.MockConverterBuilder)18 ExpectedException.none (org.junit.rules.ExpectedException.none)17 MockTransformerBuilder (org.mule.runtime.core.internal.transformer.builder.MockTransformerBuilder)17 TypedValue (org.mule.runtime.api.metadata.TypedValue)16