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