use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TypeBasedTransformerResolverTestCase method doesNotFailIfCannotResolveType.
@Test
public void doesNotFailIfCannotResolveType() throws ResolverException, TransformerException {
MuleRegistry muleRegistry = mock(MuleRegistry.class);
when(muleContext.getRegistry()).thenReturn(muleRegistry);
ArrayList<Transformer> transformers = new ArrayList<>();
when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
resolver.setMuleContext(muleContext);
Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
assertNull(resolvedTransformer);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TypeBasedTransformerResolverTestCase method resolvesTypeWithOneMatchingTransformer.
@Test
public void resolvesTypeWithOneMatchingTransformer() throws ResolverException, TransformerException {
MuleRegistry muleRegistry = mock(MuleRegistry.class);
when(muleContext.getRegistry()).thenReturn(muleRegistry);
Transformer aToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).build();
ArrayList<Transformer> transformers = new ArrayList<>();
transformers.add(aToBConverter);
when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
resolver.setMuleContext(muleContext);
Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
assertEquals(aToBConverter, resolvedTransformer);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class TypeBasedTransformerResolverTestCase method resolvesTypeWithTwoMatchingTransformer.
@Test
public void resolvesTypeWithTwoMatchingTransformer() throws ResolverException, TransformerException {
MuleRegistry muleRegistry = mock(MuleRegistry.class);
when(muleContext.getRegistry()).thenReturn(muleRegistry);
Transformer aToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).weighting(1).build();
Transformer betterAToBConverter = new MockConverterBuilder().from(dataTypeA).to(dataTypeB).weighting(2).build();
ArrayList<Transformer> transformers = new ArrayList<>();
transformers.add(aToBConverter);
transformers.add(betterAToBConverter);
when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
resolver.setMuleContext(muleContext);
Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
assertEquals(betterAToBConverter, resolvedTransformer);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class MuleMessageDataTypePropagationTestCase method maintainsCurrentDataTypeClassWhenTransformerOutputTypeIsObject.
@Test
public void maintainsCurrentDataTypeClassWhenTransformerOutputTypeIsObject() throws Exception {
Message message = of(TEST_PAYLOAD);
Transformer transformer = mock(Transformer.class);
when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
DataType outputDataType = DataType.builder().type(Object.class).mediaType(ANY).build();
when(transformer.getReturnDataType()).thenReturn(outputDataType);
when(transformer.transform(message)).thenReturn(TEST_PAYLOAD);
CoreEvent muleEvent = mock(CoreEvent.class);
Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
assertDataType(result, String.class, ANY, DEFAULT_ENCODING);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class MuleMessageDataTypePropagationTestCase method updatesMimeTypeOnTransformation.
@Test
public void updatesMimeTypeOnTransformation() throws Exception {
Message message = Message.builder().value(TEST_PAYLOAD).mediaType(ANY.withCharset(CUSTOM_ENCODING)).build();
Transformer transformer = mock(Transformer.class);
when(transformer.isSourceDataTypeSupported(any())).thenReturn(true);
DataType outputDataType = DataType.builder().type(Integer.class).mediaType(APPLICATION_XML).build();
when(transformer.getReturnDataType()).thenReturn(outputDataType);
when(transformer.transform(anyString())).thenReturn(1);
CoreEvent muleEvent = mock(CoreEvent.class);
Message result = transformationService.applyTransformers(message, muleEvent, singletonList(transformer));
assertDataType(result, Integer.class, APPLICATION_XML, CUSTOM_ENCODING);
}
Aggregations