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;
}
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;
}
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;
}
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;
}
Aggregations