Search in sources :

Example 36 with DataType

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

the class DataTypeBuilderTestCase method buildTypedMapFromImplementationClass.

@Test
public void buildTypedMapFromImplementationClass() {
    final DataType dataType = DataType.builder().mapType(SpecificMap.class).build();
    assertThat(dataType, instanceOf(DefaultMapDataType.class));
    assertThat(dataType.getType(), is(equalTo(SpecificMap.class)));
    assertThat(((DefaultMapDataType) dataType).getKeyDataType(), is(STRING));
    assertThat(((DefaultMapDataType) dataType).getValueDataType(), is(NUMBER));
}
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 37 with DataType

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

the class DataTypeBuilderTestCase method templateFunction.

@Test
public void templateFunction() {
    FunctionParameter functionParameter = new FunctionParameter("fst", NUMBER);
    final DataType template = DataType.builder().functionType(SomeFunction.class).returnType(STRING).parametersType(singletonList(functionParameter)).build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultFunctionDataType.class));
    assertThat(dataType.getType(), is(equalTo(SomeFunction.class)));
    assertThat(((DefaultFunctionDataType) dataType).getReturnType().get(), is(STRING));
    assertThat(((DefaultFunctionDataType) dataType).getParameters(), hasItems(functionParameter));
}
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) DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) FunctionParameter(org.mule.runtime.api.metadata.FunctionParameter) Test(org.junit.Test)

Example 38 with DataType

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

the class DataTypeBuilderTestCase method buildTypedMap.

@Test
public void buildTypedMap() {
    final DataType dataType = DataType.builder().mapType(HashMap.class).keyType(Number.class).keyMediaType(APPLICATION_JAVA).valueType(String.class).valueMediaType(APPLICATION_JSON).build();
    assertThat(dataType, instanceOf(DefaultMapDataType.class));
    assertThat(dataType.getType(), is(equalTo(HashMap.class)));
    DataType keyDataType = ((DefaultMapDataType) dataType).getKeyDataType();
    assertThat(keyDataType.getType(), equalTo(Number.class));
    assertThat(keyDataType.getMediaType(), is(APPLICATION_JAVA));
    DataType valueDataType = ((DefaultMapDataType) dataType).getValueDataType();
    assertThat(valueDataType.getType(), equalTo(String.class));
    assertThat(valueDataType.getMediaType(), is(APPLICATION_JSON));
}
Also used : HashMap(java.util.HashMap) 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 39 with DataType

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

the class DataTypeFactoryTestCase method mimeTypeWithEncodingInformation.

@Test
public void mimeTypeWithEncodingInformation() throws Exception {
    DataType dataType = DataType.builder().type(type).mediaType(format("%s; charset=UTF-8", mimeType)).charset(encoding).build();
    assertThat(dataType.getType(), equalTo(type));
    assertThat(dataType.getMediaType().getPrimaryType(), is(mimeType.split("/")[0]));
    assertThat(dataType.getMediaType().getSubType(), is(mimeType.split("/")[1]));
    assertThat(dataType.getMediaType().getCharset().get(), is(encoding));
}
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)

Example 40 with DataType

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

the class DataTypeFactoryTestCase method createsDataTypeForNonCollection.

@Test
public void createsDataTypeForNonCollection() {
    final DataType dataType = DataType.builder().collectionType(List.class).itemType(type).itemMediaType(mimeType).build();
    assertThat(dataType.getType(), equalTo(List.class));
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    final DataType itemDataType = ((DefaultCollectionDataType) dataType).getItemDataType();
    assertThat(itemDataType.getType(), equalTo(type));
    assertThat(itemDataType.getMediaType().getPrimaryType(), is(mimeType.split("/")[0]));
    assertThat(itemDataType.getMediaType().getSubType(), is(mimeType.split("/")[1]));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) List(java.util.List) 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