Search in sources :

Example 1 with MessageEqualAssertionVerificationResult

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

the class JSONEqualAssertionVerifier method _verify.

/**
 * @param assertion
 * @param input the JSON string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult _verify(Assertion assertion, Object input) {
    JSONEqualAssertionProperties assertionProperties = (JSONEqualAssertionProperties) assertion.getOtherProperties();
    // validate arguments
    if (assertionProperties.getExpectedJSON() == null) {
        throw new IllegalArgumentException("Expected JSON is null.");
    } else if (input == null) {
        throw new IllegalArgumentException("Actual JSON is null.");
    }
    String expectedJSON = assertionProperties.getExpectedJSON().replaceAll(JSON_UNIT_PLACEHOLDER_REGEX, JSON_UNIT_PLACEHOLDER_DELIMITER_REPLACEMENT);
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    try {
        assertJsonEquals(expectedJSON, input);
    } catch (IllegalArgumentException e) {
        Throwable c = e.getCause();
        if (c instanceof JsonParseException) {
            throw new IllegalArgumentException(e.getMessage() + " " + c.getMessage());
        } else {
            throw e;
        }
    } catch (AssertionError ae) {
        result.setDifferences(ae.getMessage());
    }
    if (result.getDifferences() == null) {
        result.setResult(TestResult.PASSED);
    } else {
        result.setResult(TestResult.FAILED);
    }
    return result;
}
Also used : JSONEqualAssertionProperties(io.irontest.models.assertion.JSONEqualAssertionProperties) JsonParseException(com.fasterxml.jackson.core.JsonParseException) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Example 2 with MessageEqualAssertionVerificationResult

use of io.irontest.models.assertion.MessageEqualAssertionVerificationResult 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 3 with MessageEqualAssertionVerificationResult

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

the class JSONEqualAssertionVerifier method verify.

/**
 * @param inputs contains only one argument: the JSON string that the assertion is verified against
 * @return
 */
@Override
public AssertionVerificationResult verify(Object... inputs) {
    JSONEqualAssertionProperties assertionProperties = (JSONEqualAssertionProperties) getAssertion().getOtherProperties();
    String expectedJSON = assertionProperties.getExpectedJSON();
    // validate arguments
    if (expectedJSON == null) {
        throw new IllegalArgumentException("Expected JSON is null.");
    } else if (inputs[0] == null) {
        throw new IllegalArgumentException("Actual JSON is null.");
    } else if (inputs[0].equals("")) {
        throw new IllegalArgumentException("Actual JSON is empty.");
    }
    MessageEqualAssertionVerificationResult result = new MessageEqualAssertionVerificationResult();
    try {
        assertJsonEquals(expectedJSON, inputs[0]);
    } catch (IllegalArgumentException e) {
        Throwable c = e.getCause();
        if (c instanceof JsonParseException) {
            throw new IllegalArgumentException(e.getMessage() + " " + c.getMessage());
        } else {
            throw e;
        }
    } catch (AssertionError ae) {
        result.setDifferences(ae.getMessage());
    }
    if (result.getDifferences() == null) {
        result.setResult(TestResult.PASSED);
    } else {
        result.setResult(TestResult.FAILED);
    }
    return result;
}
Also used : JSONEqualAssertionProperties(io.irontest.models.assertion.JSONEqualAssertionProperties) JsonParseException(com.fasterxml.jackson.core.JsonParseException) MessageEqualAssertionVerificationResult(io.irontest.models.assertion.MessageEqualAssertionVerificationResult)

Example 4 with MessageEqualAssertionVerificationResult

use of io.irontest.models.assertion.MessageEqualAssertionVerificationResult 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)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JSONEqualAssertionProperties (io.irontest.models.assertion.JSONEqualAssertionProperties)2 XMLEqualAssertionProperties (io.irontest.models.assertion.XMLEqualAssertionProperties)2