Search in sources :

Example 21 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method setsCustomSessionVariableDataType.

@Test
public void setsCustomSessionVariableDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(APPLICATION_XML).charset(CUSTOM_ENCODING).build();
    ((PrivilegedEvent) testEvent()).getSession().setProperty(TEST_PROPERTY, TEST_PAYLOAD, dataType);
    assertSessionVariableDataType(testEvent(), dataType);
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 22 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method updatesEncodingOnTransformation.

@Test
public void updatesEncodingOnTransformation() throws Exception {
    Message message = Message.builder().value(TEST_PAYLOAD).mediaType(APPLICATION_XML_DEFAULT).build();
    Transformer transformer = mock(Transformer.class);
    when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
    DataType outputDataType = DataType.builder().type(Integer.class).charset(CUSTOM_ENCODING).build();
    when(transformer.getReturnDataType()).thenReturn(outputDataType);
    when(transformer.transform(anyObject())).thenReturn(Integer.valueOf(1));
    CoreEvent muleEvent = mock(CoreEvent.class);
    Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
    assertDataType(result, Integer.class, APPLICATION_XML, CUSTOM_ENCODING);
}
Also used : Transformer(org.mule.runtime.core.api.transformer.Transformer) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 23 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method setsCustomFlowVariableDataType.

@Test
public void setsCustomFlowVariableDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(APPLICATION_XML).charset(CUSTOM_ENCODING).build();
    CoreEvent muleEvent = CoreEvent.builder(testEvent()).addVariable(TEST_PROPERTY, TEST_PAYLOAD, dataType).build();
    assertVariableDataType(muleEvent, dataType);
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Matchers.anyString(org.mockito.Matchers.anyString) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 24 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class MuleMessageDataTypePropagationTestCase method assertInboundPropertyDataType.

private void assertInboundPropertyDataType(InternalMessage muleMessage, DataType dataType) {
    DataType actualDataType = muleMessage.getInboundPropertyDataType(TEST_PROPERTY);
    assertThat(actualDataType, like(dataType));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType)

Example 25 with DataType

use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.

the class SimpleDataTypeTestCase method acceptsSupportedEncoding.

@Test
public void acceptsSupportedEncoding() throws Exception {
    DataType dataType = DataType.builder().charset(UTF_8.name()).build();
    assertThat(dataType.getMediaType().getCharset().get(), equalTo(UTF_8));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

DataType (org.mule.runtime.api.metadata.DataType)102 Test (org.junit.Test)67 SmallTest (org.mule.tck.size.SmallTest)29 DefaultCollectionDataType (org.mule.runtime.core.internal.metadata.DefaultCollectionDataType)24 FunctionDataType (org.mule.runtime.api.metadata.FunctionDataType)20 DefaultFunctionDataType (org.mule.runtime.core.internal.metadata.DefaultFunctionDataType)20 DefaultMapDataType (org.mule.runtime.core.internal.metadata.DefaultMapDataType)20 SimpleDataType (org.mule.runtime.core.internal.metadata.SimpleDataType)20 Message (org.mule.runtime.api.message.Message)18 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)18 TypedValue (org.mule.runtime.api.metadata.TypedValue)12 PrivilegedEvent (org.mule.runtime.core.privileged.event.PrivilegedEvent)12 CompiledExpression (org.mule.mvel2.compiler.CompiledExpression)10 CollectionDataType (org.mule.runtime.api.metadata.CollectionDataType)10 Transformer (org.mule.runtime.core.api.transformer.Transformer)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ParserContext (org.mule.mvel2.ParserContext)7 MapDataType (org.mule.runtime.api.metadata.MapDataType)6 MVELExpressionLanguage (org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage)6