Search in sources :

Example 81 with Message

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

the class PetStoreSerializableParameterTestCase method inputStreamParameter.

@Test
public void inputStreamParameter() throws Exception {
    InputStream inputStream = new ByteArrayInputStream(DONKEY.getBytes());
    Message message = flowRunner("dynamicSerializableParameter").withVariable("animal", inputStream).run().getMessage();
    assertThat(message.getPayload().getValue(), is(DONKEY));
}
Also used : Message(org.mule.runtime.api.message.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 82 with Message

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

the class PetStoreSerializableParameterTestCase method dynamicSerializableParameter.

@Test
public void dynamicSerializableParameter() throws Exception {
    Message message = flowRunner("dynamicSerializableParameter").withVariable("animal", DONKEY).run().getMessage();
    assertThat(message.getPayload().getValue(), is(DONKEY));
}
Also used : Message(org.mule.runtime.api.message.Message) Test(org.junit.Test)

Example 83 with Message

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

the class DefaultSourceCallback method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(Result<T, A> result, SourceCallbackContext context) {
    checkArgument(context instanceof SourceCallbackContextAdapter, "The supplied context was not created through this callback, " + "you naughty developer");
    SourceCallbackContextAdapter contextAdapter = (SourceCallbackContextAdapter) context;
    validateNotifications(contextAdapter);
    MessageProcessContext messageProcessContext = processContextSupplier.get();
    SourceResultAdapter resultAdapter = new SourceResultAdapter(result, cursorProviderFactory, defaultMediaType, returnsListOfMessages, context.getCorrelationId());
    Message message = of(resultAdapter);
    executeFlow(context, messageProcessContext, message);
    contextAdapter.dispatched();
}
Also used : Message(org.mule.runtime.api.message.Message) MessageProcessContext(org.mule.runtime.core.privileged.execution.MessageProcessContext) SourceResultAdapter(org.mule.runtime.core.internal.execution.SourceResultAdapter)

Example 84 with Message

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

the class OperationMessageProcessorTestCase method operationReturnsPayloadValueWithTarget.

@Test
public void operationReturnsPayloadValueWithTarget() throws Exception {
    target = TARGET_VAR;
    messageProcessor = setUpOperationMessageProcessor();
    Object value = new Object();
    when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(just(value));
    Message message = (Message) messageProcessor.process(event).getVariables().get(TARGET_VAR).getValue();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(value)));
}
Also used : ExecutionContext(org.mule.runtime.extension.api.runtime.operation.ExecutionContext) Message(org.mule.runtime.api.message.Message) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 85 with Message

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

the class OperationMessageProcessorTestCase method operationReturnsResultMapWithCorrectDataType.

@Test
public void operationReturnsResultMapWithCorrectDataType() throws Exception {
    Object payload = new HashMap<>();
    setUpOperationReturning(Result.builder().output(payload).build(), new TypeToken<Map<String, String>>() {
    }.getType());
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    DataType dataType = message.getPayload().getDataType();
    assertThat(dataType, instanceOf(MapDataType.class));
    assertThat(((MapDataType) dataType).getKeyDataType(), like(String.class, ANY.withCharset(null)));
    assertThat(((MapDataType) dataType).getValueDataType(), like(String.class, ANY));
}
Also used : Message(org.mule.runtime.api.message.Message) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) MapDataType(org.mule.runtime.api.metadata.MapDataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) MapDataType(org.mule.runtime.api.metadata.MapDataType) 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