Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple rest assertions #537

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Triple;
import org.assertj.core.api.SoftAssertions;
import org.jbehave.core.model.ExamplesTable;
import org.jbehave.core.steps.Row;
import org.jbehavesupport.core.TestContext;
Expand Down Expand Up @@ -522,15 +523,18 @@ private String createResponseAssertionErrorMessage(HttpStatus actualResponseStat

private void verifyJson(String json, List<Triple<String, Object, String>> expectedData, String actualResponseMessage) {
assertThat(json).as(actualResponseMessage).isNotEmpty();
SoftAssertions softly = new SoftAssertions();
DocumentContext jsonContext = JsonPath.parse(json);
for (Triple<String, Object, String> data : expectedData) {
String propertyName = data.getLeft();
Object expectedValue = data.getMiddle();

Object actualValue = getValueFromJson(propertyName, json, jsonContext, null);
verifierResolver.getVerifierByName(data.getRight(), equalsVerifier)
.verify(actualValue, expectedValue);
softly.assertThatCode(
() -> verifierResolver.getVerifierByName(data.getRight(), equalsVerifier).verify(actualValue, expectedValue)
).doesNotThrowAnyException();
}
softly.assertAll();
}

private Object getValueFromJson(String propertyName, String json, DocumentContext jsonContext, HttpHeaders headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NegativeRestScenariosIT extends Specification implements TestSupport {
true
result.getFailureCount() == 3
result.getFailures().get(0).getMessage().contains("Expected response code is CREATED but was BAD_REQUEST")
result.getFailures().get(1).getMessage() == "value 'sad' is not equal to 'happy'"
result.getFailures().get(2).getMessage() == "value 'astronaut' is not equal to 'hippopotamus'"
result.getFailures().get(1).getMessage().contains("value 'sad' is not equal to 'happy'")
result.getFailures().get(2).getMessage().contains("value 'astronaut' is not equal to 'hippopotamus'")
}
}