use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DynamicDataTypeConverterResolverTestCase method findsExpectedConverter.
@Test
public void findsExpectedConverter() throws TransformerException {
Transformer expectedConverter = new MockConverterBuilder().from(DataType.BYTE_ARRAY).to(DataType.STRING).build();
when(muleContext.getRegistry()).thenReturn(muleRegistry);
when(muleRegistry.lookupTransformer(DataType.BYTE_ARRAY, DataType.STRING)).thenReturn(expectedConverter);
DynamicDataTypeConversionResolver resolver = new DynamicDataTypeConversionResolver(muleContext);
List<DataType> targetValues = new ArrayList<>();
targetValues.add(DataType.INPUT_STREAM);
targetValues.add(DataType.STRING);
Transformer resolvedConverter = resolver.resolve(DataType.BYTE_ARRAY, targetValues);
assertEquals(expectedConverter, resolvedConverter);
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DataTypeBuilderTestCase method buildTypedCollection.
@Test
public void buildTypedCollection() {
final DataType dataType = DataType.builder().collectionType(List.class).itemType(String.class).itemMediaType(APPLICATION_JSON).build();
assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
assertThat(dataType.getType(), is(equalTo(List.class)));
DataType itemDataType = ((DefaultCollectionDataType) dataType).getItemDataType();
assertThat(itemDataType.getType(), equalTo(String.class));
assertThat(itemDataType.getMediaType(), is(APPLICATION_JSON));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DataTypeBuilderTestCase method templateSimple.
@Test
public void templateSimple() {
final DataType template = DataType.builder().type(String.class).mediaType("text/plain;charset=ASCII").build();
final DataType dataType = DataType.builder(template).build();
assertThat(dataType, instanceOf(SimpleDataType.class));
assertThat(dataType.getType(), is(equalTo(String.class)));
assertThat(dataType.getMediaType().getPrimaryType(), is("text"));
assertThat(dataType.getMediaType().getSubType(), is("plain"));
assertThat(dataType.getMediaType().getCharset().get(), is(US_ASCII));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DataTypeBuilderTestCase method buildSimple.
@Test
public void buildSimple() {
final DataType dataType = DataType.fromType(String.class);
assertThat(dataType, instanceOf(SimpleDataType.class));
assertThat(dataType.getType(), is(equalTo(String.class)));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class DataTypeBuilderTestCase method templateMap.
@Test
public void templateMap() {
final DataType template = DataType.builder().type(HashMap.class).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(OBJECT));
assertThat(((DefaultMapDataType) dataType).getValueDataType(), is(OBJECT));
assertThat(dataType.getMediaType().getPrimaryType(), is("text"));
assertThat(dataType.getMediaType().getSubType(), is("plain"));
assertThat(dataType.getMediaType().getCharset().get(), is(US_ASCII));
}
Aggregations