diff --git a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java index b700d556..016633a7 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java @@ -1,5 +1,7 @@ package net.hostsharing.hsadminng.hs.scenarios; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; import net.hostsharing.hsadminng.system.SystemProcess; import org.jetbrains.annotations.NotNull; @@ -23,9 +25,11 @@ import static org.assertj.core.api.Assertions.assertThat; public class TestReport { public static final File BUILD_DOC_SCENARIOS = new File("build/doc/scenarios"); - private final static File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md"); public static final SimpleDateFormat MM_DD_YYYY_HH_MM_SS = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss"); + private static final File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md"); + private static final ObjectMapper objectMapper = new ObjectMapper(); + private final Map aliases; private final PrintWriter markdownLog; // records everything for debugging purposes private File markdownReportFile; @@ -76,6 +80,11 @@ public class TestReport { printLine("\n" +output + "\n"); } + @SneakyThrows + public void printJson(final String json) { + printLine(prettyJson(json)); + } + void silent(final Runnable code) { silent++; code.run(); @@ -100,6 +109,14 @@ public class TestReport { return convertedTestMethodName.replaceAll(": should ", ": "); } + private static String prettyJson(final String json) throws JsonProcessingException { + if (json == null) { + return ""; + } + final var jsonNode = objectMapper.readTree(json); + return "// pretty json\n" + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode); + } + private String asClickableLink(final File file) { return file.toURI().toString().replace("file:/", "file:///"); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java index 5da51293..a64052d8 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java @@ -379,14 +379,12 @@ public abstract class UseCase> { // the request testReport.printLine("```"); testReport.printLine(httpMethod.name() + " " + uri); - testReport.printLine((requestBody != null ? requestBody.trim() : "")); + testReport.printJson(requestBody); // the response testReport.printLine("=> status: " + status + " " + (locationUuid != null ? locationUuid : "")); if (httpMethod == HttpMethod.GET || status.isError()) { - final var jsonNode = objectMapper.readTree(response.body()); - final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode); - testReport.printLine(prettyJson); + testReport.printJson(response.body()); } testReport.printLine("```"); testReport.printLine("");