From 2971f4196d9acb1c4d5d4bbf215bcab9eeaeaac8 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 17 Dec 2024 10:20:48 +0100 Subject: [PATCH] extract feaure for obtain --- ...placeDeceasedPartnerWithCommunityOfHeirs.java | 16 ++++++++-------- .../hsadminng/hs/scenarios/ScenarioTest.java | 7 +++++-- .../hsadminng/hs/scenarios/TestReport.java | 10 +++++----- .../hsadminng/hs/scenarios/UseCase.java | 11 +++++++++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/ReplaceDeceasedPartnerWithCommunityOfHeirs.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/ReplaceDeceasedPartnerWithCommunityOfHeirs.java index e9fb8d7b..d37337df 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/ReplaceDeceasedPartnerWithCommunityOfHeirs.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/ReplaceDeceasedPartnerWithCommunityOfHeirs.java @@ -90,7 +90,9 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase + obtain("Representative-Relation: %{representativeGivenName} %{representativeFamilyName} for Erbengemeinschaft %{nameOfDeceasedPerson}", () -> httpPost("/api/hs/office/relations", usingJsonBody(""" { "type": "REPRESENTATIVE", - "anchor.uuid": ${Person: %{partnerPersonTradeName}}, - "holder.uuid": { + "anchor.uuid": ${Person: Erbengemeinschaft %{nameOfDeceasedPerson}}, + "holder": { "personType": "NATURAL_PERSON", "givenName": ${representativeGivenName}, "familyName": ${representativeFamilyName} }, - "contact.uuid": ${Contact: %{subscriberGivenName} %{subscriberFamilyName}} + "contact.uuid": ${Contact: Erbengemeinschaft %{nameOfDeceasedPerson}} } """)) .expecting(CREATED).expecting(JSON), @@ -137,12 +139,10 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase httpPatch("/api/hs/office/partners/%{Partner: %{partnerNumber}}", usingJsonBody(""" { - "partnerRel": ${Partner-Relation: Erbengemeinschaft %{nameOfDeceasedPerson}} + "partnerRel.uuid": ${Partner-Relation: Erbengemeinschaft %{nameOfDeceasedPerson}} } """)) .expecting(HttpStatus.OK) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/ScenarioTest.java b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/ScenarioTest.java index 75ea20e7..b65c8ca7 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/ScenarioTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/ScenarioTest.java @@ -50,13 +50,16 @@ public abstract class ScenarioTest extends ContextBasedTest { return Optional.of(currentTestMethodProduces.pop()); } - record Alias>(Class useCase, UUID uuid) { + public record Alias>(Class useCase, UUID uuid) { @Override public String toString() { return Objects.toString(uuid); } + public boolean hasUuid() { + return uuid != null; + } } private final static Map> aliases = new HashMap<>(); @@ -111,7 +114,7 @@ public abstract class ScenarioTest extends ContextBasedTest { jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); - aliases.put( + putAlias( "Person: Hostsharing eG", new Alias<>( null, 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 57728f8a..d4c11c36 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/TestReport.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.SneakyThrows; import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration; +import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.Alias; import net.hostsharing.hsadminng.system.SystemProcess; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Order; @@ -31,7 +32,7 @@ public class TestReport { private static final File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md"); private static final ObjectMapper objectMapper = JsonObjectMapperConfiguration.build(); - private final Map aliases; + private final Map> aliases; private final PrintWriter markdownLog; // records everything for debugging purposes private File markdownReportFile; private PrintWriter markdownReport; // records only the use-case under test, without its pre-requisites @@ -43,7 +44,7 @@ public class TestReport { } @SneakyThrows - public TestReport(final Map aliases) { + public TestReport(final Map> aliases) { this.aliases = aliases; this.markdownLog = new PrintWriter(new FileWriter(markdownLogFile)); } @@ -131,9 +132,8 @@ public class TestReport { final var result = new StringBuilder(); for (String line : lines) { - for (Map.Entry entry : aliases.entrySet()) { - final var uuidString = entry.getValue().toString(); - if (line.contains(uuidString)) { + for (Map.Entry> entry : aliases.entrySet()) { + if (entry.getValue().hasUuid() && line.contains(entry.getValue().toString())) { line = line + " // " + entry.getKey(); break; // only add comment for one UUID per row (in our case, there is only one per row) } 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 a64052d8..b4f38fa1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/scenarios/UseCase.java @@ -134,8 +134,8 @@ public abstract class UseCase> { }); } - public final void obtain(final String alias, final Supplier http, final String... extraInfo) { - withTitle(alias, () -> { + public final HttpResponse obtain(final String alias, final Supplier http, final String... extraInfo) { + return withTitle(alias, () -> { final var response = http.get().keep(); Arrays.stream(extraInfo).forEach(testReport::printPara); return response; @@ -396,6 +396,13 @@ public abstract class UseCase> { final var onlyVisibleInGeneratedMarkdownNotInSource = new String(new char[]{'F', 'I', 'X', 'M', 'E'}); return alias == null ? "unknown alias -- " + onlyVisibleInGeneratedMarkdownNotInSource : alias; } + + public HttpResponse extract(final String jsonPath, final String resolvableName) { + final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS); + final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenAsString(); + ScenarioTest.putProperty(resolvedName, resolvedJsonPath); + return this; + } } protected T self() {