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