print formatted output of HTTP GET

This commit is contained in:
Michael Hoennig 2024-10-25 15:23:40 +02:00
parent e12d0b0ba2
commit 765b679042
2 changed files with 9 additions and 4 deletions

View File

@ -103,7 +103,7 @@ public abstract class UseCase<T extends UseCase<?>> {
.timeout(Duration.ofSeconds(10))
.build();
final var response = client.send(request, BodyHandlers.ofString());
return new HttpResponse(HttpMethod.POST, uriPath, null, response);
return new HttpResponse(HttpMethod.GET, uriPath, null, response);
}
@SneakyThrows
@ -178,6 +178,7 @@ public abstract class UseCase<T extends UseCase<?>> {
private UUID locationUuid;
@SneakyThrows
public HttpResponse(
final HttpMethod httpMethod,
final String uri,
@ -199,10 +200,12 @@ public abstract class UseCase<T extends UseCase<?>> {
}
printLine("```");
printLine(httpMethod.name() + " " + uri);
printLine(requestBody + "=> status: " + status + " " +
printLine((requestBody != null ? requestBody : "") + "=> status: " + status + " " +
(locationUuid != null ? locationUuid : ""));
if (!status.is2xxSuccessful()) {
printLine(response.body()); // FIXME: prettyPrint
if (httpMethod == HttpMethod.GET || !status.is2xxSuccessful()) {
final var jsonNode = objectMapper.readTree(response.body());
final var prettyJson = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
printLine(prettyJson);
}
printLine("```");
printLine("");

View File

@ -20,6 +20,8 @@ public class CreateSelfDebitorForPartner extends UseCase<CreateSelfDebitorForPar
.expecting(OK).expecting(JSON),
response -> response.getFromBody("[0].holder.uuid")
);
printPara("From that output above, we're taking the UUID of the holder of the first result element.");
printPara("**HINT**: With production data, you might get multiple results and have to decide which is the right one.");
keep("BankAccount: Test AG - refund bank account", () ->
httpPost("/api/hs/office/bankaccounts", usingJsonBody("""