use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class GraphTransformerResolverTestCase method clearsCacheWhenRemovesTransformer.
@Test
public void clearsCacheWhenRemovesTransformer() throws ResolverException {
Converter xmlToJson = new MockConverterBuilder().from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
Converter inputStreamToXml = new MockConverterBuilder().from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertNotNull(transformer);
graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.REMOVED);
transformer = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertNull(transformer);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class GraphTransformerResolverTestCase method resolvesTransformerWithSameLengthAndSameWeight.
@Test
public void resolvesTransformerWithSameLengthAndSameWeight() throws ResolverException {
Converter xmlToInputStream = new MockConverterBuilder().named("xmlToInputStream").from(XML_DATA_TYPE).to(INPUT_STREAM_DATA_TYPE).weighting(1).build();
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).weighting(1).build();
Converter inputStreamToJson = new MockConverterBuilder().named("inputStreamToJson").from(INPUT_STREAM_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
Converter stringToJson = new MockConverterBuilder().named("stringToJson").from(STRING_DATA_TYPE).to(JSON_DATA_TYPE).weighting(1).build();
graphResolver.transformerChange(xmlToInputStream, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(inputStreamToJson, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(stringToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer = graphResolver.resolve(XML_DATA_TYPE, JSON_DATA_TYPE);
assertTrue(transformer instanceof CompositeConverter);
CompositeConverter compositeConverter = (CompositeConverter) transformer;
assertEquals(2, compositeConverter.getConverters().size());
assertEquals(xmlToInputStream, compositeConverter.getConverters().get(0));
assertEquals(inputStreamToJson, compositeConverter.getConverters().get(1));
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class GraphTransformerResolverTestCase method clearsCacheWhenAddsConverter.
@Test
public void clearsCacheWhenAddsConverter() throws ResolverException {
Converter xmlToJson = new MockConverterBuilder().named("xmlToJson").from(XML_DATA_TYPE).to(JSON_DATA_TYPE).build();
Converter inputStreamToXml = new MockConverterBuilder().named("inputStreamToXml").from(INPUT_STREAM_DATA_TYPE).to(XML_DATA_TYPE).build();
graphResolver.transformerChange(inputStreamToXml, TransformerResolver.RegistryAction.ADDED);
graphResolver.transformerChange(xmlToJson, TransformerResolver.RegistryAction.ADDED);
Transformer transformer1 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertNotNull(transformer1);
Converter xmlToString = new MockConverterBuilder().named("xmlToString").from(XML_DATA_TYPE).to(STRING_DATA_TYPE).build();
graphResolver.transformerChange(xmlToString, TransformerResolver.RegistryAction.ADDED);
Transformer transformer2 = graphResolver.resolve(INPUT_STREAM_DATA_TYPE, JSON_DATA_TYPE);
assertNotSame(transformer1, transformer2);
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class AbstractMockTransformerBuilder method build.
public Transformer build() {
Transformer transformer;
if (name == null || name.isEmpty()) {
transformer = mock(getClassToMock());
} else {
transformer = mock(getClassToMock(), name);
doReturn(name).when(transformer).getName();
}
if (resultDataType != null) {
doReturn(resultDataType).when(transformer).getReturnDataType();
}
if (sourceDataTypes != null) {
doReturn(Arrays.asList(sourceDataTypes)).when(transformer).getSourceDataTypes();
when(transformer.isSourceDataTypeSupported((DataType) argThat(new SupportsSourceDataType()))).thenReturn(true);
}
try {
doReturn(value).when(transformer).transform(Mockito.any(Object.class));
} catch (TransformerException e) {
// Not going to happen during mock setup
}
return transformer;
}
use of org.mule.runtime.core.api.transformer.Transformer in project mule by mulesoft.
the class GZipTransformerTestCase method testCompressAndDecompress.
@Test
public void testCompressAndDecompress() throws Exception {
Transformer compressorTransformer = getTransformer();
Transformer decompressorTransformer = getRoundTripTransformer();
// Compress the test data.
Object compressedData = compressorTransformer.transform(getTestData());
// Decompress the test data.
Object decompressedData = decompressorTransformer.transform(compressedData);
assertTrue(String.format("Compress and decompress process failed. Expected '%s', but got '%s'", getTestData(), decompressedData), compareResults(getTestData(), decompressedData));
}
Aggregations