Package org.mule.api.annotations.param

Source Code of org.mule.api.annotations.param.MixedAnnotationsTestCase

/*
* $Id: MixedAnnotationsTestCase.java 21860 2011-05-09 14:25:41Z tcarlson $
* --------------------------------------------------------------------------------------
* Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
*
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

package org.mule.api.annotations.param;

import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;
import org.mule.tck.FunctionalTestCase;
import org.mule.util.ExceptionUtils;
import org.mule.util.StringDataSource;

import java.util.HashMap;
import java.util.Map;

import javax.activation.DataHandler;

public class MixedAnnotationsTestCase extends FunctionalTestCase
{
    private MuleMessage muleMessage;

    public MixedAnnotationsTestCase()
    {
        setDisposeManagerPerSuite(true);
    }

    @Override
    protected String getConfigResources()
    {
        return "org/mule/test/annotations/mixed-annotations.xml";
    }

    @Override
    public void doSetUp() throws Exception
    {
        super.doSetUp();
       
        Map<String, Object> props = new HashMap<String, Object>(3);
        props.put("foo", "fooValue");
        props.put("bar", "barValue");
        props.put("baz", "bazValue");

        muleMessage = new DefaultMuleMessage("test", props, muleContext);

        try
        {
            muleMessage.addAttachment("foo", new DataHandler(new StringDataSource("fooValue")));
            muleMessage.addAttachment("bar", new DataHandler(new StringDataSource("barValue")));
            muleMessage.addAttachment("baz", new DataHandler(new StringDataSource("bazValue")));
        }
        catch (Exception e)
        {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    public void testProcessAllAnnotated() throws Exception
    {
        MuleClient client = new MuleClient(muleContext);
        MuleMessage message = client.send("vm://allAnnotated", muleMessage);
        assertNotNull("return message from MuleClient.send() should not be null", message);
        assertTrue("Message payload should be a Map", message.getPayload() instanceof Map);
        Map<?, ?> result = (Map<?, ?>) message.getPayload();
        assertEquals(3, result.size());

        //Payload
        assertEquals("test", result.get("payload"));

        //Headers
        assertNotNull(result.get("inboundHeaders"));
        Map<?, ?> headers = (Map<?, ?>)result.get("inboundHeaders");
        assertEquals(2, headers.size());
        assertEquals("fooValue", headers.get("foo"));
        assertEquals("barValue", headers.get("bar"));

        //Attachments
        assertNotNull(result.get("inboundAttachments"));
        Map<?, ?> attachments = (Map<?, ?>)result.get("inboundAttachments");
        assertEquals(3, attachments.size());
        assertNotNull(attachments.get("foo"));
        assertNotNull(attachments.get("bar"));
        assertNotNull(attachments.get("baz"));
    }

    public void testPayloadNotAnnotated() throws Exception
    {
        //When using param annotations every param needs t obe annotated
        try
        {
            muleContext.getClient().send("vm://someAnnotated", muleMessage);
            fail("Exception expected");
        }
        catch (Exception e)
        {
            assertTrue(ExceptionUtils.getRootCause(e) instanceof IllegalArgumentException);
        }
    }
}
TOP

Related Classes of org.mule.api.annotations.param.MixedAnnotationsTestCase

TOP
Copyright © 2018 www.massapi.com. 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.