feature/use-case-acceptance-tests #116
@ -16,9 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
public class TestReport {
|
public class TestReport {
|
||||||
|
|
||||||
private final Map<String, ?> aliases;
|
private final Map<String, ?> aliases;
|
||||||
private final StringBuilder debugLog = new StringBuilder(); // records everything for debugging purposes
|
private final StringBuilder markdownLog = new StringBuilder(); // records everything for debugging purposes
|
||||||
|
|
||||||
private PrintWriter markdownFile;
|
private PrintWriter markdownReport;
|
||||||
private int silent; // do not print anything to test-report if >0
|
private int silent; // do not print anything to test-report if >0
|
||||||
|
|
||||||
public TestReport(final Map<String, ?> aliases) {
|
public TestReport(final Map<String, ?> aliases) {
|
||||||
@ -29,22 +29,22 @@ public class TestReport {
|
|||||||
final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow();
|
final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow();
|
||||||
final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow();
|
final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow();
|
||||||
assertThat(new File("doc/scenarios/").isDirectory() || new File("doc/scenarios/").mkdirs()).as("mkdir doc/scenarios/").isTrue();
|
assertThat(new File("doc/scenarios/").isDirectory() || new File("doc/scenarios/").mkdirs()).as("mkdir doc/scenarios/").isTrue();
|
||||||
markdownFile = new PrintWriter(new FileWriter("doc/scenarios/" + testMethodOrder + "-" + testMethodName + ".md"));
|
markdownReport = new PrintWriter(new FileWriter("doc/scenarios/" + testMethodOrder + "-" + testMethodName + ".md"));
|
||||||
print("## Scenario: " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
print("## Scenario: " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void print(final String output) {
|
public void print(final String output) {
|
||||||
|
|
||||||
final var outputWithCommentsForUuids = appendUUIDKey(output.replace("+", "\\+"));
|
final var outputWithCommentsForUuids = appendUUIDKey(output);
|
||||||
|
|
||||||
// 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 (silent == 0) {
|
if (silent == 0) {
|
||||||
markdownFile.print(outputWithCommentsForUuids);
|
markdownReport.print(outputWithCommentsForUuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
// but the debugLog should contain all output, even if silent
|
// but the debugLog should contain all output, even if silent
|
||||||
debugLog.append(outputWithCommentsForUuids);
|
markdownLog.append(outputWithCommentsForUuids);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printLine(final String output) {
|
public void printLine(final String output) {
|
||||||
@ -56,7 +56,7 @@ public class TestReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
markdownFile.close();
|
markdownReport.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String appendUUIDKey(String multilineText) {
|
private String appendUUIDKey(String multilineText) {
|
||||||
|
@ -281,8 +281,8 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
testReport.printLine(httpMethod.name() + " " + uri);
|
testReport.printLine(httpMethod.name() + " " + uri);
|
||||||
testReport.printLine((requestBody != null ? requestBody.trim() : ""));
|
testReport.printLine((requestBody != null ? requestBody.trim() : ""));
|
||||||
|
|
||||||
// the response + "=> status: " + status + " " +
|
// the response
|
||||||
testReport.printLine(locationUuid != null ? locationUuid.toString() : "");
|
testReport.printLine("=> status: " + status + " " + (locationUuid != null ? locationUuid : ""));
|
||||||
if (httpMethod == HttpMethod.GET || status.isError()) {
|
if (httpMethod == HttpMethod.GET || status.isError()) {
|
||||||
final var jsonNode = objectMapper.readTree(response.body());
|
final var jsonNode = objectMapper.readTree(response.body());
|
||||||
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
|
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user