Package org.mule.munit.config

Source Code of org.mule.munit.config.SetMessageProcessor

/*
* 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.munit.config;

import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.api.transport.PropertyScope;
import org.mule.munit.AssertModule;

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


/**
* <p>
* Sets the payload
* </p>
*
* @author Mulesoft Inc.
* @since 3.3.2
*/
public class SetMessageProcessor extends MunitMessageProcessor
{

    private Object payload;

    private Map<String, Object> invocationProperties;
    private Map<String, Object> inboundProperties;
    private Map<String, Object> sessionProperties;
    private Map<String, Object> outboundProperties;


    @Override
    protected void doProcess(MuleMessage mulemessage, AssertModule module)
    {
        DefaultMuleMessage defaultMuleMessage = (DefaultMuleMessage) mulemessage;

        setProperties(defaultMuleMessage, inboundProperties, PropertyScope.INBOUND);
        setProperties(defaultMuleMessage, invocationProperties, PropertyScope.INVOCATION);
        setProperties(defaultMuleMessage, outboundProperties, PropertyScope.OUTBOUND);
        setProperties(defaultMuleMessage, sessionProperties, PropertyScope.SESSION);
        defaultMuleMessage.setPayload(evaluate(mulemessage, payload));
    }

    private Map<String, Object> setProperties(DefaultMuleMessage message, Map<String, Object> properties, PropertyScope scope)
    {
        Map<String, Object> evaluatedMap = new HashMap<String, Object>();
        if (properties != null)
        {
            for (Map.Entry<String, Object> entry : properties.entrySet())
            {
                message.setProperty(entry.getKey(), evaluate(message, entry.getValue()), scope);
            }
        }

        return evaluatedMap;
    }


    @Override
    protected String getProcessor()
    {
        return "set";
    }

    public void setPayload(Object value)
    {
        this.payload = value;
    }

    public void setInvocationProperties(Map<String, Object> invocationProperties)
    {
        this.invocationProperties = invocationProperties;
    }

    public void setInboundProperties(Map<String, Object> inboundProperties)
    {
        this.inboundProperties = inboundProperties;
    }

    public void setSessionProperties(Map<String, Object> sessionProperties)
    {
        this.sessionProperties = sessionProperties;
    }

    public void setOutboundProperties(Map<String, Object> outboundProperties)
    {
        this.outboundProperties = outboundProperties;
    }
}
TOP

Related Classes of org.mule.munit.config.SetMessageProcessor

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.