Search in sources :

Example 1 with XMLEqualAssertionProperties

use of io.irontest.models.assertion.XMLEqualAssertionProperties in project irontest by zheng-wang.

the class XMLEqualAssertionVerifier method _verify.

/**
 * @param assertion
 * @param input the XML string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult _verify(Assertion assertion, Object input) throws Exception {
    XMLEqualAssertionProperties assertionProperties = (XMLEqualAssertionProperties) assertion.getOtherProperties();
    // validate arguments
    if (assertionProperties.getExpectedXML() == null) {
        throw new IllegalArgumentException("Expected XML is null.");
    } else if (input == null) {
        throw new IllegalArgumentException("Actual XML is null.");
    }
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    String differencesStr = XMLUtils.compareXML(assertionProperties.getExpectedXML(), (String) input);
    if (differencesStr.length() > 0) {
        result.setResult(TestResult.FAILED);
        result.setDifferences(differencesStr);
    } else {
        result.setResult(TestResult.PASSED);
    }
    return result;
}
Also used : XMLEqualAssertionProperties(io.irontest.models.assertion.XMLEqualAssertionProperties) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Example 2 with XMLEqualAssertionProperties

use of io.irontest.models.assertion.XMLEqualAssertionProperties in project irontest by zheng-wang.

the class XMLEqualAssertionVerifier method verify.

/**
 * @param inputs contains only one argument: the XML string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult verify(Object... inputs) {
    XMLEqualAssertionProperties assertionProperties = (XMLEqualAssertionProperties) getAssertion().getOtherProperties();
    // validate arguments
    if (assertionProperties.getExpectedXML() == null) {
        throw new IllegalArgumentException("Expected XML is null.");
    } else if (inputs[0] == null) {
        throw new IllegalArgumentException("Actual XML is null.");
    } else if (inputs[0].equals("")) {
        throw new IllegalArgumentException("Actual XML is empty.");
    }
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    String differencesStr = XMLUtils.compareXML(assertionProperties.getExpectedXML(), (String) inputs[0]);
    if (differencesStr.length() > 0) {
        result.setResult(TestResult.FAILED);
        result.setDifferences(differencesStr);
    } else {
        result.setResult(TestResult.PASSED);
    }
    return result;
}
Also used : XMLEqualAssertionProperties(io.irontest.models.assertion.XMLEqualAssertionProperties) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Aggregations

MessageEqualAssertionVerificationResult (io.irontest.models.assertion.MessageEqualAssertionVerificationResult)2 XMLEqualAssertionProperties (io.irontest.models.assertion.XMLEqualAssertionProperties)2