
de.codecentric.mule.assertobjectequals.AssertObjectEqualsConnector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assert-object-equals-connector Show documentation
Show all versions of assert-object-equals-connector Show documentation
A Mule connector for comparing object structures (Map/List) or XML in MUnit tests.
The newest version!
package de.codecentric.mule.assertobjectequals;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;
import org.mule.api.MuleMessage;
import org.mule.api.annotations.Category;
import org.mule.api.annotations.Connector;
import org.mule.api.annotations.Processor;
import org.mule.api.annotations.display.FriendlyName;
import org.mule.api.annotations.param.Default;
import org.mule.api.annotations.param.Literal;
import org.mule.api.expression.ExpressionManager;
import org.mule.api.transformer.DataType;
import org.mule.api.transport.OutputHandler;
import org.mule.devkit.api.transformer.DefaultTranformingValue;
import org.mule.devkit.api.transformer.TransformingValue;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.DefaultComparisonFormatter;
import org.xmlunit.diff.Diff;
@Connector(name = "assert-object-equals", friendlyName = "Assert Object Equals", description = "Compares two Java Map/List based structures)")
@Category(name = "org.mule.tooling.category.munit", description = "MUnit")
public class AssertObjectEqualsConnector {
@Inject
private MuleContext muleContext;
public void setMuleContext(MuleContext muleContext) {
this.muleContext = muleContext;
}
/**
* Compare two objects. Drill down into {@link Map} and {@link List}, use {@link Object#equals(Object)} for all other
* classes.
*
* @param expected
* The expected value. Automatic conversions are provided:
*
* - InputStream is read/parsed as Json
* - byte[] is parsed as Json
* - String is parsed as Json when it starts with [ or { (after
trim()
*
* Remember: Encoding for Json is always UTF8
* @param actualExpression
* The actual value. Automatic conversions are provided:
*
* - InputStream is read/parsed as Json
* - byte[] is parsed as Json
* - String is parsed as Json when it starts with [ or { (after
trim()
*
* Remember: Encoding for Json is always UTF8
* @param containsOnlyOnMaps
* The actual value entry set of maps can contain more values than the expected set. So you tests do not fail
* when there are more elements than expected in the result.
*
* @param checkMapOrder
* The order of map entries is checked. The default is to ignore order of map entries.
*
* @param pathOptions
* Options for path patterns to control the comparison. Syntax of one List entry: Zero to n
path
* parts. The parts can have the following syntax:
*
* ?
: Wildcard one, matches one element in a path
* *
: Wildcard any, matches zero to n
elements in a path
* [#]
: List wildcard, matches a list entry with any index
* [0]
: Matches a list entry with the given number. 0 or positive numbers: Count from
* beginning, negative number: Cound from end (-1 is last element)
* ['.*']
: Matches a map entry where the key must match the given regular expression. If you
* need a ' in the expression, just write ''. The example '.*' matches all keys.
*
* A space as separator. One or more of the following options (case not relevant):
*
* CONTAINS_ONLY_ON_MAPS: The actual value entry set of maps can contain more values than the expected set.
* So you tests do not fail when there are more elements than expected in the result.
*
* CHECK_MAP_ORDER: The order of map entries is checked. The default is to ignore order of map entries.
*
* IGNORE: The actual node and its subtree is ignored completely.
*
* @param event
* The {@link MuleEvent}, needed to run the expresion evaluator.
*
* @return The original payload.
* @throws Exception
* When comparison fails or on technical problems (e.g. parsing)
*/
@SuppressWarnings("unchecked")
@Processor(friendlyName = "Compare Objects")
public TransformingValue
© 2015 - 2025 Weber Informatics LLC | Privacy Policy