Search in sources :

Example 26 with DataType

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

the class DataTypeUtilsTestCase method generatesContentTypeWithCharset.

@Test
public void generatesContentTypeWithCharset() throws Exception {
    final DataType dataType = DataType.builder().type(Object.class).mediaType(APPLICATION_JSON).charset(UTF_8.name()).build();
    String contentType = dataType.getMediaType().toRfcString();
    assertThat(contentType, equalTo("application/json; charset=UTF-8"));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 27 with DataType

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

the class DataTypeBuilderTestCase method proxy.

@Test
public void proxy() {
    final Class<?> muleMessageProxy = Proxy.getProxyClass(DataTypeBuilderTestCase.class.getClassLoader(), Message.class);
    final DataType dataType = DataType.fromType(muleMessageProxy);
    assertThat(dataType.getType(), is(equalTo(Message.class)));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Example 28 with DataType

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

the class DataTypeBuilderTestCase method cglibClassProxy.

@Test
public void cglibClassProxy() {
    final Message muleMessageProxy = mock(MessageTestImpl.class);
    final DataType dataType = DataType.fromObject(muleMessageProxy);
    assertThat(dataType.getType(), is(equalTo(MessageTestImpl.class)));
}
Also used : Message(org.mule.runtime.api.message.Message) DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Example 29 with DataType

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

the class DataTypeBuilderTestCase method templateTypedMap.

@Test
public void templateTypedMap() {
    final DataType template = DataType.builder().mapType(HashMap.class).keyType(String.class).keyMediaType("text/plain;charset=UTF-8").valueType(Number.class).valueMediaType("application/json;charset=ISO-8859-1").mediaType("text/plain;charset=ASCII").build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultMapDataType.class));
    assertThat(dataType.getType(), is(equalTo(HashMap.class)));
    assertThat(((DefaultMapDataType) dataType).getKeyDataType(), is(assignableTo(TEXT_STRING)));
    assertThat(((DefaultMapDataType) dataType).getKeyDataType().getMediaType().getPrimaryType(), is("text"));
    assertThat(((DefaultMapDataType) dataType).getKeyDataType().getMediaType().getSubType(), is("plain"));
    assertThat(((DefaultMapDataType) dataType).getKeyDataType().getMediaType().getCharset().get(), is(UTF_8));
    assertThat(((DefaultMapDataType) dataType).getValueDataType(), is(assignableTo((NUMBER))));
    assertThat(((DefaultMapDataType) dataType).getValueDataType().getMediaType().getPrimaryType(), is("application"));
    assertThat(((DefaultMapDataType) dataType).getValueDataType().getMediaType().getSubType(), is("json"));
    assertThat(((DefaultMapDataType) dataType).getValueDataType().getMediaType().getCharset().get(), is(ISO_8859_1));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) Test(org.junit.Test)

Example 30 with DataType

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

the class DataTypeBuilderTestCase method templateCollection.

@Test
public void templateCollection() {
    final DataType template = DataType.builder().type(Set.class).mediaType("text/plain;charset=ASCII").build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(Set.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(OBJECT));
    assertThat(dataType.getMediaType().getPrimaryType(), is("text"));
    assertThat(dataType.getMediaType().getSubType(), is("plain"));
    assertThat(dataType.getMediaType().getCharset().get(), is(US_ASCII));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) 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