Package org.mule.api.transformer

Examples of org.mule.api.transformer.Transformer


    }

    @Test
    public void lookupsTransformerByPriority() throws Exception
    {
        Transformer result =  muleContext.getRegistry().lookupTransformer(new SimpleDataType(BloodOrange.class), new SimpleDataType(Fruit.class));
        assertNotNull(result);
        assertEquals(t1, result);
    }
View Full Code Here


        ArrayList<Transformer> transformers = new ArrayList<Transformer>();
        when(muleRegistry.lookupTransformers(dataTypeA, dataTypeB)).thenReturn(transformers);
        TypeBasedTransformerResolver resolver = new TypeBasedTransformerResolver();
        resolver.setMuleContext(muleContext);

        Transformer resolvedTransformer = resolver.resolve(dataTypeA, dataTypeB);
        assertNull(resolvedTransformer);
    }
View Full Code Here

    @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<Transformer>();
        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);
    }
View Full Code Here

    }

    @Test
    public void cachesTransformerResolvers() throws Exception
    {
        Transformer transformer1 = muleRegistryHelper.lookupTransformer(DataTypeFactory.STRING, ORANGE_DATA_TYPE);
        Transformer transformer2 = muleRegistryHelper.lookupTransformer(ORANGE_DATA_TYPE, DataTypeFactory.STRING);

        Mockito.verify(registry, times(0)).lookupObjects(TransformerResolver.class);
        assertEquals(stringToOrange, transformer1);
        assertEquals(orangeToString, transformer2);
    }
View Full Code Here

    @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<Transformer>();
        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);
    }
View Full Code Here

     * {@inheritDoc}
     */
    public Transformer lookupTransformer(DataType source, DataType result) throws TransformerException
    {
        final String dataTypePairHash = getDataTypeSourceResultPairHash(source, result);
        Transformer cachedTransformer = (Transformer) exactTransformerCache.get(dataTypePairHash);
        if (cachedTransformer != null)
        {
            return cachedTransformer;
        }

        Transformer trans = resolveTransformer(source, result);

        if (trans != null)
        {
            Transformer concurrentlyAddedTransformer = (Transformer) exactTransformerCache.putIfAbsent(
                    dataTypePairHash, trans);
            if (concurrentlyAddedTransformer != null)
            {
                return concurrentlyAddedTransformer;
            }
View Full Code Here

        {
            for (TransformerResolver resolver : transformerResolvers)
            {
                try
                {
                    Transformer trans = resolver.resolve(source, result);
                    if (trans != null)
                    {
                        return trans;
                    }
                }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void unregisterTransformer(String transformerName) throws MuleException
    {
        Transformer transformer = lookupTransformer(transformerName);
        notifyTransformerResolvers(transformer, TransformerResolver.RegistryAction.REMOVED);
        registry.unregisterObject(transformerName, Transformer.class);

    }
View Full Code Here

        DynamicDataTypeConversionResolver resolver = new DynamicDataTypeConversionResolver(muleContext);

        List<DataType<?>> targetTypes = new ArrayList<DataType<?>>();
        targetTypes.add(DataTypeFactory.STRING);
        Transformer resolvedConverter = resolver.resolve(DataTypeFactory.INPUT_STREAM, targetTypes);

        assertEquals(null, resolvedConverter);
    }
View Full Code Here

    }

    @Test
    public void findsExpectedConverter() throws TransformerException
    {
        Transformer expectedConverter = new MockConverterBuilder().from(DataTypeFactory.BYTE_ARRAY).to(DataTypeFactory.STRING).build();

        when(muleContext.getRegistry()).thenReturn(muleRegistry);
        when(muleRegistry.lookupTransformer(DataTypeFactory.BYTE_ARRAY, DataTypeFactory.STRING)).thenReturn(expectedConverter);

        DynamicDataTypeConversionResolver resolver = new DynamicDataTypeConversionResolver(muleContext);

        List<DataType<?>> targetTypes = new ArrayList<DataType<?>>();
        targetTypes.add(DataTypeFactory.INPUT_STREAM);
        targetTypes.add(DataTypeFactory.STRING);
        Transformer resolvedConverter = resolver.resolve(DataTypeFactory.BYTE_ARRAY, targetTypes);

        assertEquals(expectedConverter, resolvedConverter);
    }
View Full Code Here

TOP

Related Classes of org.mule.api.transformer.Transformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.