Search in sources :

Example 16 with DataType

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

the class DefaultMuleEventTestCase method setFlowVariableDefaultDataType.

@Test
public void setFlowVariableDefaultDataType() throws Exception {
    muleEvent = (PrivilegedEvent) CoreEvent.builder(muleEvent).addVariable(PROPERTY_NAME, PROPERTY_VALUE).build();
    DataType dataType = muleEvent.getVariables().get(PROPERTY_NAME).getDataType();
    assertThat(dataType, like(String.class, MediaType.ANY, null));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 17 with DataType

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

the class DefaultMuleEventTestCase method setFlowVariableCustomDataType.

@Test
public void setFlowVariableCustomDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(APPLICATION_XML).charset(CUSTOM_ENCODING).build();
    muleEvent = (PrivilegedEvent) CoreEvent.builder(muleEvent).addVariable(PROPERTY_NAME, PROPERTY_VALUE, dataType).build();
    DataType actualDataType = muleEvent.getVariables().get(PROPERTY_NAME).getDataType();
    assertThat(actualDataType, like(String.class, APPLICATION_XML, CUSTOM_ENCODING));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 18 with DataType

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

the class PropertyEnricherDataTypePropagatorTestCase method propagatesDataTypeForInlinedSessionProperty.

@Test
public void propagatesDataTypeForInlinedSessionProperty() throws Exception {
    final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
    MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
    final CompiledExpression compiledExpression = (CompiledExpression) compileExpression("foo = 'unused'", new ParserContext(expressionLanguage.getParserConfiguration()));
    PrivilegedEvent event = (PrivilegedEvent) testEvent();
    event.getSession().setProperty("foo", "bar");
    final PrivilegedEvent.Builder builder = PrivilegedEvent.builder(testEvent());
    dataTypePropagator.propagate((PrivilegedEvent) testEvent(), builder, new TypedValue(TEST_MESSAGE, expectedDataType), compiledExpression);
    assertThat(builder.build().getSession().getPropertyDataType("foo"), like(String.class, JSON, CUSTOM_ENCODING));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) TypedValue(org.mule.runtime.api.metadata.TypedValue) Test(org.junit.Test)

Example 19 with DataType

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

the class PropertyExpressionDataTypeResolverTestCase method returnsInlineFlowVarDataType.

@Test
public void returnsInlineFlowVarDataType() throws Exception {
    final String expression = "foo";
    final DataType expectedDataType = DataType.builder().type(String.class).mediaType(JSON).charset(CUSTOM_ENCODING).build();
    MVELExpressionLanguage expressionLanguage = new MVELExpressionLanguage(muleContext);
    final CompiledExpression compiledExpression = (CompiledExpression) compileExpression(expression, new ParserContext(expressionLanguage.getParserConfiguration()));
    PrivilegedEvent testEvent = this.<PrivilegedEvent.Builder>getEventBuilder().message(of(TEST_MESSAGE)).addVariable("foo", EXPRESSION_VALUE, expectedDataType).build();
    assertThat(expressionDataTypeResolver.resolve(testEvent, compiledExpression), like(String.class, JSON, CUSTOM_ENCODING));
}
Also used : PrivilegedEvent(org.mule.runtime.core.privileged.event.PrivilegedEvent) DataType(org.mule.runtime.api.metadata.DataType) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) ParserContext(org.mule.mvel2.ParserContext) CompiledExpression(org.mule.mvel2.compiler.CompiledExpression) Test(org.junit.Test)

Example 20 with DataType

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

the class MuleMessageDataTypePropagationTestCase method updatesTypeOnTransformation.

@Test
public void updatesTypeOnTransformation() throws Exception {
    Message message = Message.builder().value(1).mediaType(APPLICATION_XML_DEFAULT).build();
    Transformer transformer = mock(Transformer.class);
    when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
    DataType outputDataType = DataType.builder().type(Integer.class).mediaType(ANY).charset(DEFAULT_ENCODING).build();
    when(transformer.getReturnDataType()).thenReturn(outputDataType);
    when(transformer.transform(anyObject())).thenReturn(1);
    CoreEvent muleEvent = mock(CoreEvent.class);
    Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
    assertDataType(result, Integer.class, APPLICATION_XML, DEFAULT_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)

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