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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations