All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.sinall.soapor.matchers.XPathValueMatcher Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package com.github.sinall.soapor.matchers;

import com.github.sinall.soapor.SOAPMessageEvaluator;
import org.apache.commons.lang3.ObjectUtils;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

import javax.xml.soap.SOAPMessage;
import java.text.MessageFormat;

public class XPathValueMatcher extends TypeSafeMatcher {

    private String xpath;
    private T expectedValue;
    private String actualValue;

    public XPathValueMatcher(String xpath, T expectedValue) {
        this.xpath = xpath;
        this.expectedValue = expectedValue;
    }

    @Override
    public boolean matchesSafely(SOAPMessage soapMessage) {
        SOAPMessageEvaluator evaluator = new SOAPMessageEvaluator(soapMessage);
        actualValue = evaluator.getValueByXPath(xpath);
        return ObjectUtils.equals(expectedValue.toString(), actualValue);
    }

    @Override
    public void describeTo(Description description) {
        description.appendText(MessageFormat.format("contain \"{0}\" in XPath \"{1}\"", expectedValue, xpath));
    }

    @Override
    public void describeMismatchSafely(SOAPMessage item, org.hamcrest.Description mismatchDescription) {
        mismatchDescription.appendText(MessageFormat.format("contain \"{0}\"", actualValue));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy