Search in sources :

Example 71 with DataType

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

the class DataTypeBuilderTestCase method buildCollection.

@Test
public void buildCollection() {
    final DataType dataType = DataType.fromType(Set.class);
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(Set.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(OBJECT));
}
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)

Example 72 with DataType

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

the class DataTypeBuilderTestCase method cglibSpyProxy.

@Test
public void cglibSpyProxy() {
    final Message muleMessageProxy = spy(new MessageTestImpl());
    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 73 with DataType

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

the class DataTypeBuilderTestCase method templateTypedCollection.

@Test
public void templateTypedCollection() {
    final DataType template = DataType.builder().collectionType(List.class).itemType(String.class).itemMediaType("application/json;charset=UTF-8").mediaType("text/plain;charset=ASCII").build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(List.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(assignableTo(STRING)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getPrimaryType(), is("application"));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getSubType(), is("json"));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getCharset().get(), is(UTF_8));
    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)

Example 74 with DataType

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

the class DataTypeBuilderTestCase method mimeTypeWithEncoding.

@Test
public void mimeTypeWithEncoding() {
    final DataType dataType = DataType.builder().mediaType("text/plain;charset=ASCII").build();
    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) Test(org.junit.Test)

Example 75 with DataType

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

the class DataTypeFactoryTestCase method createsDataTypeForNullPayload.

@Test
public void createsDataTypeForNullPayload() throws Exception {
    DataType dataType = DataType.fromObject(null);
    assertThat(dataType, like(Object.class, MediaType.ANY, null));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

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