Package org.mule.transformer.simple

Examples of org.mule.transformer.simple.MessagePropertiesTransformer


    }

    @Test
    public void testOverwriteFlagEnabledByDefault() throws Exception
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        Map<String, Object> add = new HashMap<String, Object>();
        add.put("addedProperty", "overwrittenValue");
        t.setAddProperties(add);
        t.setMuleContext(muleContext);

        MuleMessage msg = new DefaultMuleMessage("message", muleContext);
        msg.setOutboundProperty("addedProperty", "originalValue");
        MuleEventContext ctx = getTestEventContext(msg);
        // context clones message
        msg = ctx.getMessage();
        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, (String)null);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        compareProperties(msg, transformed);
View Full Code Here


    }

    @Test
    public void testOverwriteFalsePreservesOriginal() throws Exception
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        Map<String, Object> add = new HashMap<String, Object>();
        add.put("addedProperty", "overwrittenValue");
        t.setAddProperties(add);
        t.setOverwrite(false);
        t.setMuleContext(muleContext);

        DefaultMuleMessage msg = new DefaultMuleMessage("message", muleContext);
        msg.setProperty("addedProperty", "originalValue", PropertyScope.INVOCATION);
        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, (String)null);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        compareProperties(msg, transformed);
View Full Code Here

    }

    @Test
    public void testExpressionsInAddProperties() throws Exception
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        Map<String, Object> add = new HashMap<String, Object>();
        add.put("Foo", "#[header:public-house]");
        t.setAddProperties(add);
        t.setMuleContext(muleContext);

        DefaultMuleMessage msg = new DefaultMuleMessage("message", muleContext);
        msg.setOutboundProperty("public-house", "Bar");
        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, (String)null);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        compareProperties(msg, transformed);
View Full Code Here

    }

    @Test
    public void testRenameProperties() throws Exception
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        Map<String, String> add = new HashMap<String, String>();
        add.put("Foo", "Baz");
        t.setRenameProperties(add);
        t.setScope(PropertyScope.INVOCATION);
        t.setMuleContext(muleContext);

        DefaultMuleMessage msg = new DefaultMuleMessage("message", muleContext);
        msg.setInvocationProperty("Foo", "Bar");
        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        compareProperties(msg, transformed);
View Full Code Here

    }

    @Test
    public void testDelete() throws Exception
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        t.setDeleteProperties("badProperty");
        t.setMuleContext(muleContext);

        DefaultMuleMessage msg = new DefaultMuleMessage("message", muleContext);
        msg.setOutboundProperty("badProperty", "badValue");
        assertEquals("badValue", msg.<Object>getOutboundProperty("badProperty"));
        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg, (String)null);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        compareProperties(msg, transformed);
View Full Code Here

    }

    @Test
    public void testTransformerConfig() throws Exception
    {
        MessagePropertiesTransformer transformer = (MessagePropertiesTransformer) muleContext.getRegistry().lookupTransformer("testTransformer");
        transformer.setMuleContext(muleContext);
        assertNotNull(transformer);
        assertNotNull(transformer.getAddProperties());
        assertNotNull(transformer.getDeleteProperties());
        assertEquals(2, transformer.getAddProperties().size());
        assertEquals(2, transformer.getDeleteProperties().size());
        assertEquals(1, transformer.getRenameProperties().size());
        assertTrue(transformer.isOverwrite());
        assertEquals("text/baz;charset=UTF-16BE", transformer.getAddProperties().get("Content-Type"));
        assertEquals("value", transformer.getAddProperties().get("key"));
        assertEquals("test-property1", transformer.getDeleteProperties().get(0));
        assertEquals("test-property2", transformer.getDeleteProperties().get(1));
        assertEquals("Faz", transformer.getRenameProperties().get("Foo"));
        assertEquals(PropertyScope.OUTBOUND, transformer.getScope());
    }
View Full Code Here

    }

    private void doTestMessageTransformationWithExpression(String expression, String[] validProperties, String[] invalidProperties)
            throws TransformerException
    {
        MessagePropertiesTransformer t = createTransformerWithExpression(expression);

        DefaultMuleMessage msg = new DefaultMuleMessage("message", muleContext);
        addPropertiesToMessage(validProperties, msg);
        addPropertiesToMessage(invalidProperties, msg);

        DefaultMuleMessage transformed = (DefaultMuleMessage) t.transform(msg);
        assertSame(msg, transformed);
        assertEquals(msg.getUniqueId(), transformed.getUniqueId());
        assertEquals(msg.getPayload(), transformed.getPayload());
        assertMessageContainsExpectedProperties(validProperties, invalidProperties, transformed);
    }
View Full Code Here

        }
    }

    private MessagePropertiesTransformer createTransformerWithExpression(String expression)
    {
        MessagePropertiesTransformer t = new MessagePropertiesTransformer();
        t.setDeleteProperties(expression);
        t.setMuleContext(muleContext);
        return t;
    }
View Full Code Here

    {
        MuleMessage msg = new DefaultMuleMessage("message", muleContext);
       
        // Add properties to scope
       
        MessagePropertiesTransformer add = new MessagePropertiesTransformer();
        add.setScope(PropertyScope.INVOCATION);
        Map<String, Object> addProps = new HashMap<String, Object>();
        addProps.put("foo", "bar");
        addProps.put("foo2", "baz");
        add.setAddProperties(addProps);
        add.setMuleContext(muleContext);
        add.initialise();

        msg = (DefaultMuleMessage) add.transform(msg, (String)null);

        assertEquals("bar", msg.getInvocationProperty("foo"));
        assertNull(msg.getOutboundProperty("foo"));
        assertNull(msg.getSessionProperty("foo"));

        // Remove property from the wrong scope
       
        MessagePropertiesTransformer deleteWrongScope = new MessagePropertiesTransformer();
        deleteWrongScope.setScope(PropertyScope.OUTBOUND);
        deleteWrongScope.setDeleteProperties("foo");
        deleteWrongScope.setMuleContext(muleContext);
        deleteWrongScope.initialise();

        msg = (DefaultMuleMessage) deleteWrongScope.transform(msg, (String)null);
        assertEquals("bar", msg.getInvocationProperty("foo"));

        // Remove property from the correct scope
       
        MessagePropertiesTransformer delete = new MessagePropertiesTransformer();
        delete.setScope(PropertyScope.INVOCATION);
        delete.setDeleteProperties(Collections.singletonList("foo"));
        delete.setMuleContext(muleContext);
        delete.initialise();

        msg = (DefaultMuleMessage) delete.transform(msg, (String)null);
        assertNull(msg.getInvocationProperty("foo"));
        assertEquals("baz", msg.getInvocationProperty("foo2"));
    }
View Full Code Here

    {
        // if transformers have been configured, preemptively drop the content-length header to prevent side effects
        // induced by mismatches
        if ((configurationPattern.hasTransformers()) || (configurationPattern.hasResponseTransformers()))
        {
            final MessagePropertiesTransformer contentLengthHeaderRemover = newContentLengthHeaderRemover();
            if (configurationPattern.hasTransformers())
            {
                builder.chain(contentLengthHeaderRemover);
            }
            if (configurationPattern.hasResponseTransformers())
View Full Code Here

TOP

Related Classes of org.mule.transformer.simple.MessagePropertiesTransformer

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.