Search in sources :

Example 56 with DataType

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

the class SpringRegistryBootstrap method doRegisterTransformer.

@Override
protected void doRegisterTransformer(TransformerBootstrapProperty bootstrapProperty, Class<?> returnClass, Class<? extends Transformer> transformerClass) throws Exception {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(transformerClass);
    DataType returnType = null;
    if (returnClass != null) {
        DataTypeParamsBuilder dataTypeBuilder = DataType.builder().type(returnClass);
        if (isNotEmpty(bootstrapProperty.getMimeType())) {
            dataTypeBuilder = dataTypeBuilder.mediaType(bootstrapProperty.getMimeType());
        }
        builder.addPropertyValue("returnDataType", dataTypeBuilder.build());
    }
    String name = bootstrapProperty.getName();
    if (name == null) {
        // Prefixes the generated default name to ensure there is less chance of conflict if the user registers
        // the transformer with the same name
        name = "_" + TransformerUtils.generateTransformerName(transformerClass, returnType);
    }
    builder.addPropertyValue("name", name);
    notifyIfOptional(name, bootstrapProperty.getOptional());
    doRegisterObject(name, builder);
}
Also used : DataTypeParamsBuilder(org.mule.runtime.api.metadata.DataTypeParamsBuilder) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) DataType(org.mule.runtime.api.metadata.DataType)

Example 57 with DataType

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

the class TestLegacyMessageUtils method getOutboundPropertyDataType.

/**
 * Gets an outbound property data type from the message.
 *
 * @param message message used to obtain the data from. Must be a {@link InternalMessage}
 * @param name the name or key of the property. This must be non-null.
 * @return the property data type or null if the property does not exist in the specified scope
 * @throws {@link IllegalStateException} if there is any problem accessing the legacy message API using reflection
 */
public static DataType getOutboundPropertyDataType(Message message, String name) {
    try {
        Method method = message.getClass().getMethod("getOutboundPropertyDataType", String.class);
        method.setAccessible(true);
        return (DataType) method.invoke(message, name);
    } catch (Exception e) {
        throw new IllegalStateException(LEGACY_MESSAGE_API_ERROR, e);
    }
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) Method(java.lang.reflect.Method)

Example 58 with DataType

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

the class DefaultMuleEventTestCase method setSessionVariableDefaultDataType.

@Test
public void setSessionVariableDefaultDataType() throws Exception {
    muleEvent.getSession().setProperty(PROPERTY_NAME, PROPERTY_VALUE);
    DataType dataType = muleEvent.getSession().getPropertyDataType(PROPERTY_NAME);
    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 59 with DataType

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

the class DefaultMuleEventTestCase method setSessionVariableCustomDataType.

@Test
public void setSessionVariableCustomDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(APPLICATION_XML).charset(CUSTOM_ENCODING).build();
    muleEvent.getSession().setProperty(PROPERTY_NAME, PROPERTY_VALUE, dataType);
    DataType actualDataType = muleEvent.getSession().getPropertyDataType(PROPERTY_NAME);
    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 60 with DataType

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

the class MVELExpressionLanguageTestCase method returnsDataType.

@Test
public void returnsDataType() throws Exception {
    DataType dataType = DataType.builder().type(String.class).mediaType(JSON).charset(UTF_16.name()).build();
    CoreEvent event = createEvent(TEST_MESSAGE, dataType);
    TypedValue typedValue = evaluateTyped("payload", event);
    assertThat((String) typedValue.getValue(), equalTo(TEST_MESSAGE));
    assertThat(typedValue.getDataType(), like(String.class, JSON, UTF_16));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) DataType(org.mule.runtime.api.metadata.DataType) Matchers.containsString(org.hamcrest.Matchers.containsString) TypedValue(org.mule.runtime.api.metadata.TypedValue) 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