Package org.mule.api.transformer

Examples of org.mule.api.transformer.Transformer


        muleContext.getRegistry().registerTransformer(new StringToOrange());
    }

    public void testSimpleDiscovery() throws Exception
    {
        Transformer t = muleContext.getRegistry().lookupTransformer(DataTypeFactory.STRING, DataTypeFactory.create(Apple.class));
        assertNotNull(t);
        assertEquals(StringToApple.class, t.getClass());

        t = muleContext.getRegistry().lookupTransformer(DataTypeFactory.STRING, DataTypeFactory.create(Orange.class));
        assertNotNull(t);
        assertEquals(StringToOrange.class, t.getClass());


        try
        {
            muleContext.getRegistry().lookupTransformer(DataTypeFactory.STRING, DataTypeFactory.create(Banana.class));
            fail("There is no transformer to go from String to Banana");
        }
        catch (TransformerException e)
        {
            //expected
        }


        muleContext.getRegistry().registerTransformer(new StringToRedApple());

        t = muleContext.getRegistry().lookupTransformer(DataTypeFactory.STRING, DataTypeFactory.create(RedApple.class));
        assertNotNull(t);
        assertEquals(StringToRedApple.class, t.getClass());
    }
View Full Code Here


        }
    }

    public static boolean isSourceTypeSupportedByFirst(List<Transformer> transformers, Class clazz)
    {
        Transformer transformer = firstOrNull(transformers);
        return null != transformer && transformer.isSourceDataTypeSupported(new DataTypeFactory().create(clazz));
    }
View Full Code Here

            List<Transformer> transformers = new LinkedList<Transformer>();
            StringTokenizer st = new StringTokenizer(names, COMMA);
            while (st.hasMoreTokens())
            {
                String key = st.nextToken().trim();
                Transformer transformer = muleContext.getRegistry().lookupTransformer(key);

                if (transformer == null)
                {
                    throw new DefaultMuleException(CoreMessages.objectNotRegistered("Transformer", key));
                }
View Full Code Here

        assertNull("Credentials must not be created for endpoints without a password.", credentials);
    }

    public void testEventSerialization() throws Exception
    {
        Transformer trans1 = new TestEventTransformer();
        trans1.setName("OptimusPrime");

        Transformer trans2 = new TestEventTransformer();
        trans2.setName("Bumblebee");

        List<Transformer> transformers = new ArrayList<Transformer>();
        transformers.add(trans1);
        transformers.add(trans2);

        InboundEndpoint endpoint = getTestInboundEndpoint("Test", null, transformers,
            new PayloadTypeFilter(Object.class), null);

        MuleEvent event = RequestContext.setEvent(getTestEvent("payload", endpoint));
        Serializable serialized = (Serializable) new SerializableToByteArray().transform(event);
        assertNotNull(serialized);
        ByteArrayToObject trans = new ByteArrayToObject();
        trans.setMuleContext(muleContext);
        MuleEvent deserialized = (MuleEvent) trans.transform(serialized);
       
        // Assert that deserialized event is not null and has muleContext
        assertNotNull(deserialized);
        assertNotNull(deserialized.getMuleContext());

        // Assert that deserialized event has session with same id
        assertNotNull(deserialized.getSession());
        assertEquals(event.getSession().getId(), deserialized.getSession().getId());

        // Assert that deserialized event has service and that the service is the same instance
        assertNotNull(deserialized.getSession().getFlowConstruct());
        assertEquals(event.getSession().getFlowConstruct(), deserialized.getSession().getFlowConstruct());
        assertSame(event.getSession().getFlowConstruct(), deserialized.getSession().getFlowConstruct());

        // Assert that deserialized event has endpoint and that the endpoint is the same instance
        assertNotNull(deserialized.getEndpoint());   
        assertEquals(endpoint, deserialized.getEndpoint());

        List deserializedTransformers = deserialized.getEndpoint().getTransformers();
        assertEquals(2, deserializedTransformers.size());
        assertEquals(trans1.getName(), ((Transformer) deserializedTransformers.get(0)).getName());
        assertEquals(trans2.getName(), ((Transformer) deserializedTransformers.get(1)).getName());
        assertEquals(PayloadTypeFilter.class, deserialized.getEndpoint().getFilter().getClass());
    }
View Full Code Here

        return RequestContext.setEvent(getTestEvent("payload", service, endpoint));
    }

    private void createAndRegisterTransformersEndpointBuilderService() throws Exception
    {
        Transformer trans1 = new TestEventTransformer();
        trans1.setName("OptimusPrime");
        muleContext.getRegistry().registerTransformer(trans1);

        Transformer trans2 = new TestEventTransformer();
        trans2.setName("Bumblebee");
        muleContext.getRegistry().registerTransformer(trans2);

        List<Transformer> transformers = new ArrayList<Transformer>();
        transformers.add(trans1);
        transformers.add(trans2);
View Full Code Here

        assertNotNull("Connector should not be null", c);
        assertNotNull("Service overrides should not be null", c.getServiceOverrides());
        String temp =  (String)c.getServiceOverrides().get(MuleProperties.CONNECTOR_DISPATCHER_FACTORY);
        assertNotNull("DispatcherFactory override should not be null", temp);
        assertEquals(TestMessageDispatcherFactory.class.getName(), temp);
        Transformer transformer = TransformerUtils.firstOrNull(c.getDefaultInboundTransformers(null));
        assertNotNull("InboundTransformer should not be null", transformer);
        assertEquals(NoActionTransformer.class, transformer.getClass());
    }
View Full Code Here

    // MULE-1878
    public void testDuplicate()
    {
        AbstractConnector c1 = (AbstractConnector)muleContext.getRegistry().lookupConnector("test");
        assertNotNull("Connector should not be null", c1);
        Transformer t1 = TransformerUtils.firstOrNull(c1.getDefaultInboundTransformers(null));
        assertNotNull("InboundTransformer should not be null", t1);
        assertEquals(NoActionTransformer.class, t1.getClass());

        AbstractConnector c2 = (AbstractConnector)muleContext.getRegistry().lookupConnector("second");
        assertNotNull("Connector should not be null", c2);
        Transformer t2 = TransformerUtils.firstOrNull(c2.getDefaultInboundTransformers(null));
        assertNull("InboundTransformer should be null", t2);
    }
View Full Code Here

            else
            {
                List<Transformer> transformers = new LinkedList<Transformer>();
                for (String name : transformerNames)
                {
                    Transformer next = muleContext.getRegistry().lookupTransformer(name);
                    if (next == null)
                    {
                        throw new IllegalStateException(CoreMessages.objectNotFound(name).toString());
                    }
                    else
View Full Code Here

    }

    @Override
    public Transformer getTransformer() throws Exception
    {
        Transformer trans = createObject(StringToObjectArray.class);
        trans.setReturnDataType(DataTypeFactory.create(Object[].class));

        EndpointBuilder builder = new EndpointURIEndpointBuilder("test://test", muleContext);
        builder.setEncoding(encoding);
        ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint(
            builder);
        trans.setEndpoint(endpoint);

        return trans;
    }
View Full Code Here

            if (!getReturnClass().isInstance(result))
            {
                //If the return type does not match, lets attempt to transform it before throwing an error
                try
                {
                    Transformer t = muleContext.getRegistry().lookupTransformer(
                        DataTypeFactory.createFromObject(result), DataTypeFactory.create(getReturnClass()));
                    result = t.transform(result);
                }
                catch (TransformerException e)
                {
                    throw new ExpressionRuntimeException(CoreMessages.transformUnexpectedType(result.getClass(),
                    getReturnClass()), e);
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.