use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getDataTypeFromObject.
@Test
public void getDataTypeFromObject() {
Class<Object> objectClass = Object.class;
ObjectTypeBuilder objectTypeBuilder = BaseTypeBuilder.create(JAVA).objectType().id(objectClass.getName());
DataType dataType = toDataType(objectTypeBuilder.build());
assertThat(dataType.getType(), is(equalTo(objectClass)));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class OperationMessageProcessorTestCase method operationReturnsCollectionWithCorrectDataType.
@Test
public void operationReturnsCollectionWithCorrectDataType() throws Exception {
Object payload = new ArrayList<>();
setUpOperationReturning(payload, new TypeToken<List<Integer>>() {
}.getType());
Message message = messageProcessor.process(event).getMessage();
assertThat(message, is(notNullValue()));
assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
DataType dataType = message.getPayload().getDataType();
assertThat(dataType, instanceOf(CollectionDataType.class));
assertThat(((CollectionDataType) dataType).getItemDataType(), like(Integer.class, ANY.withCharset(null)));
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TransformerChainingTestCase method getIncreaseByOneTransformer.
private Transformer getIncreaseByOneTransformer() throws Exception {
AbstractTransformer transformer = new AbstractTransformer() {
@Override
protected Object doTransform(Object src, Charset encoding) throws TransformerException {
return new Integer(((Integer) src).intValue() + 1);
}
};
DataType integerDataType = DataType.fromType(Integer.class);
transformer.registerSourceType(integerDataType);
transformer.setReturnDataType(DataType.builder(integerDataType).charset(getDefaultEncoding(muleContext)).build());
return transformer;
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class TransformationServiceTestCase method failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion2.
@Test
public void failsOnConverterWhenSourceAndReturnTypeDoesNotMatchAndThereIsNoImplicitConversion2() throws MuleException {
// Converter(B->C), payload A: FAIL
ByteArrayInputStream payload = new ByteArrayInputStream(TEST_PAYLOAD.getBytes());
DataType originalSourceType = DataType.fromType(payload.getClass());
Transformer converter1 = new MockConverterBuilder().from(originalSourceType).to(dataTypeC).build();
A transformedPayload = new A();
when(converter1.transform(any())).thenReturn(transformedPayload);
Message message = of(payload);
try {
transformationService.applyTransformers(message, null, converter1);
fail("Transformation is supposed to fail");
} catch (MessageTransformerException expected) {
assertThat(expected.getErrorMessage().getPayload().getValue(), is(transformedPayload));
}
}
use of org.mule.runtime.api.metadata.DataType in project mule by mulesoft.
the class StreamingUtilsTestCase method consumeTypedRepeatableIteratorPayload.
@Test
@Description("Test that repeatable iterator is consumed into a list while maintaining the collection data type")
public void consumeTypedRepeatableIteratorPayload() throws Exception {
CursorIteratorProvider payload = asCursorProvider(TEST_LIST);
DataType dataType = DataType.builder().collectionType(ArrayList.class).itemType(String.class).build();
CoreEvent event = consumeRepeatablePayload(getEventBuilder().message(Message.builder().payload(new TypedValue<>(payload, dataType)).build()).build());
assertConsumedObjectStream(payload, event);
dataType = event.getMessage().getPayload().getDataType();
assertThat(dataType, is(instanceOf(CollectionDataType.class)));
assertThat(((CollectionDataType) dataType).getItemDataType(), equalTo(STRING));
}
Aggregations