feature/use-case-acceptance-tests #116
@ -39,7 +39,7 @@ public class TestReport {
|
|||||||
final var outputWithCommentsForUuids = appendUUIDKey(output.replace("+", "\\+"));
|
final var outputWithCommentsForUuids = appendUUIDKey(output.replace("+", "\\+"));
|
||||||
|
|
||||||
// for tests executed due to @Requires/@Produces there is no markdownFile yet
|
// for tests executed due to @Requires/@Produces there is no markdownFile yet
|
||||||
if (markdownFile != null && silent == 0) { // FIXME: check if markdownFile can even be null
|
if (silent == 0) {
|
||||||
markdownFile.print(outputWithCommentsForUuids);
|
markdownFile.print(outputWithCommentsForUuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,4 +81,5 @@ public class TestReport {
|
|||||||
code.run();
|
code.run();
|
||||||
silent--;
|
silent--;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
private final String resultAlias;
|
private final String resultAlias;
|
||||||
private final Map<String, Object> givenProperties = new LinkedHashMap<>();
|
private final Map<String, Object> givenProperties = new LinkedHashMap<>();
|
||||||
|
|
||||||
private String nextTitle; // just temporary
|
private String nextTitle; // just temporary to override resultAlias for sub-use-cases
|
||||||
|
|
||||||
public UseCase(final ScenarioTest testSuite) {
|
public UseCase(final ScenarioTest testSuite) {
|
||||||
this(testSuite, getResultAliasFromProducesAnnotationInCallStack());
|
this(testSuite, getResultAliasFromProducesAnnotationInCallStack());
|
||||||
@ -218,24 +218,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
locationUuid = UUID.fromString(location.substring(location.lastIndexOf('/') + 1));
|
locationUuid = UUID.fromString(location.substring(location.lastIndexOf('/') + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextTitle != null) {
|
reportRequestAndResponse(httpMethod, uri, requestBody);
|
||||||
testReport.printLine("\n### " + nextTitle + "\n");
|
|
||||||
} else if (resultAlias != null) {
|
|
||||||
testReport.printLine("\n### " + resultAlias + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: maybe refactor into TestReport?
|
|
||||||
testReport.printLine("```");
|
|
||||||
testReport.printLine(httpMethod.name() + " " + uri);
|
|
||||||
testReport.printLine((requestBody != null ? requestBody : "") + "=> status: " + status + " " +
|
|
||||||
(locationUuid != null ? locationUuid : ""));
|
|
||||||
if (httpMethod == HttpMethod.GET || !status.is2xxSuccessful()) {
|
|
||||||
final var jsonNode = objectMapper.readTree(response.body());
|
|
||||||
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
|
|
||||||
testReport.printLine(prettyJson);
|
|
||||||
}
|
|
||||||
testReport.printLine("```");
|
|
||||||
testReport.printLine("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse expecting(final HttpStatus httpStatus) {
|
public HttpResponse expecting(final HttpStatus httpStatus) {
|
||||||
@ -269,6 +252,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public HttpResponse expectArrayElements(final int expectedElementCount) {
|
public HttpResponse expectArrayElements(final int expectedElementCount) {
|
||||||
|
// FIXME: use JsonPath?
|
||||||
final var rootNode = objectMapper.readTree(response.body());
|
final var rootNode = objectMapper.readTree(response.body());
|
||||||
assertThat(rootNode.isArray()).as("array expected, but got: " + response.body()).isTrue();
|
assertThat(rootNode.isArray()).as("array expected, but got: " + response.body()).isTrue();
|
||||||
|
|
||||||
@ -282,6 +266,32 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
public String getFromBody(final String path) {
|
public String getFromBody(final String path) {
|
||||||
return JsonPath.parse(response.body()).read(path);
|
return JsonPath.parse(response.body()).read(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private void reportRequestAndResponse(final HttpMethod httpMethod, final String uri, final String requestBody) {
|
||||||
|
|
||||||
|
// the title
|
||||||
|
if (nextTitle != null) {
|
||||||
|
testReport.printLine("\n### " + nextTitle + "\n");
|
||||||
|
} else if (resultAlias != null) {
|
||||||
|
testReport.printLine("\n### " + resultAlias + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// the request
|
||||||
|
testReport.printLine("```");
|
||||||
|
testReport.printLine(httpMethod.name() + " " + uri);
|
||||||
|
testReport.printLine((requestBody != null ? requestBody.trim() : ""));
|
||||||
|
|
||||||
|
// the response + "=> status: " + status + " " +
|
||||||
|
testReport.printLine(locationUuid != null ? locationUuid.toString() : "");
|
||||||
|
if (httpMethod == HttpMethod.GET || status.isError()) {
|
||||||
|
final var jsonNode = objectMapper.readTree(response.body());
|
||||||
|
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
|
||||||
|
testReport.printLine(prettyJson);
|
||||||
|
}
|
||||||
|
testReport.printLine("```");
|
||||||
|
testReport.printLine("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T self() {
|
protected T self() {
|
||||||
|
Loading…
Reference in New Issue
Block a user