From e97b177a92ba6ccec91e8652bd4b4e84af682235 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 7 Nov 2024 10:11:46 +0100 Subject: [PATCH] feature/use-case-acceptance-tests-3 (#119) Co-authored-by: Michael Hoennig Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/119 Reviewed-by: Marc Sandlus --- .../HsOfficeMembershipController.java | 4 +- .../scenarios/HsOfficeScenarioTests.java | 26 ++++++++++ .../hs/office/scenarios/UseCase.java | 5 +- .../contact/AddPhoneNumberToContactData.java | 2 +- .../RemovePhoneNumberFromContactData.java | 2 +- .../scenarios/contact/ReplaceContactData.java | 2 +- .../membership/CancelMembership.java | 47 ++++++++++++++++++ .../membership/CreateMembership.java | 34 ++++++++----- .../AddOperationsContactToPartner.java | 2 +- .../partner/AddRepresentativeToPartner.java | 2 +- .../scenarios/partner/CreatePartner.java | 2 +- .../person/ShouldUpdatePersonData.java | 48 +++++++++++++++++++ .../RemoveOperationsContactFromPartner.java | 2 +- 13 files changed, 156 insertions(+), 22 deletions(-) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CancelMembership.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/person/ShouldUpdatePersonData.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java index d63f9e6a..7a491961 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/membership/HsOfficeMembershipController.java @@ -34,8 +34,8 @@ public class HsOfficeMembershipController implements HsOfficeMembershipsApi { public ResponseEntity> listMemberships( final String currentSubject, final String assumedRoles, - UUID partnerUuid, - Integer memberNumber) { + final UUID partnerUuid, + final Integer memberNumber) { context.define(currentSubject, assumedRoles); final var entities = ( memberNumber != null) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index 0288ab9f..b08e9f3c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -11,12 +11,14 @@ import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSepaMandateFo import net.hostsharing.hsadminng.hs.office.scenarios.debitor.FinallyDeleteSepaMandateForDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DontDeleteDefaultDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.InvalidateSepaMandateForDebitor; +import net.hostsharing.hsadminng.hs.office.scenarios.membership.CancelMembership; import net.hostsharing.hsadminng.hs.office.scenarios.membership.CreateMembership; import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddOperationsContactToPartner; import net.hostsharing.hsadminng.hs.office.scenarios.partner.CreatePartner; import net.hostsharing.hsadminng.hs.office.scenarios.debitor.DeleteDebitor; import net.hostsharing.hsadminng.hs.office.scenarios.partner.DeletePartner; import net.hostsharing.hsadminng.hs.office.scenarios.partner.AddRepresentativeToPartner; +import net.hostsharing.hsadminng.hs.office.scenarios.person.ShouldUpdatePersonData; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.RemoveOperationsContactFromPartner; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.SubscribeToMailinglist; import net.hostsharing.hsadminng.hs.office.scenarios.subscription.UnsubscribeFromMailinglist; @@ -197,6 +199,16 @@ class HsOfficeScenarioTests extends ScenarioTest { .doRun(); } + @Test + @Order(1201) + @Requires("Partner: Michelle Matthieu") + void shouldUpdatePersonData() { + new ShouldUpdatePersonData(this) + .given("oldFamilyName", "Matthieu") + .given("newFamilyName", "Matthieu-Zhang") + .doRun(); + } + @Test @Order(2010) @Requires("Partner: Test AG") @@ -302,12 +314,26 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(4000) @Requires("Partner: Test AG") + @Produces("Membership: Test AG 00") void shouldCreateMembershipForPartner() { new CreateMembership(this) .given("partnerName", "Test AG") .given("memberNumberSuffix", "00") .given("validFrom", "2024-10-15") + .given("newStatus", "ACTIVE") .given("membershipFeeBillable", "true") + .doRun() + .keep(); + } + + @Test + @Order(4900) + @Requires("Membership: Test AG 00") + void shouldCancelMembershipOfPartner() { + new CancelMembership(this) + .given("memberNumber", "3101000") + .given("validTo", "2025-12-30") + .given("newStatus", "CANCELLED") .doRun(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java index 77aa7b93..f224fff2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/UseCase.java @@ -86,13 +86,13 @@ public abstract class UseCase> { }) ); final var response = run(); - verify(); + verify(response); return response; } protected abstract HttpResponse run(); - protected void verify() { + protected void verify(final HttpResponse response) { } public final UseCase given(final String propName, final Object propValue) { @@ -233,6 +233,7 @@ public abstract class UseCase> { @Getter private final HttpStatus status; + @Getter private UUID locationUuid; @SneakyThrows diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java index 3e837195..5f8d266d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/AddPhoneNumberToContactData.java @@ -40,7 +40,7 @@ public class AddPhoneNumberToContactData extends UseCase.HttpResponse response) { verify( "Verify if the New Phone Number Got Added", () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/RemovePhoneNumberFromContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/RemovePhoneNumberFromContactData.java index c499ee71..715e1832 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/RemovePhoneNumberFromContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/RemovePhoneNumberFromContactData.java @@ -39,7 +39,7 @@ public class RemovePhoneNumberFromContactData extends UseCase.HttpResponse response) { verify( "Verify if the New Phone Number Got Added", () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java index f3e88269..e60bbc8e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/contact/ReplaceContactData.java @@ -57,7 +57,7 @@ public class ReplaceContactData extends UseCase { } @Override - protected void verify() { + protected void verify(final UseCase.HttpResponse response) { verify( "Verify if the Contact-Relation Got Replaced in the Partner-Relation", () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CancelMembership.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CancelMembership.java new file mode 100644 index 00000000..23f718b5 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CancelMembership.java @@ -0,0 +1,47 @@ +package net.hostsharing.hsadminng.hs.office.scenarios.membership; + +import io.restassured.http.ContentType; +import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest; +import net.hostsharing.hsadminng.hs.office.scenarios.UseCase; +import org.springframework.http.HttpStatus; + +import static io.restassured.http.ContentType.JSON; +import static org.springframework.http.HttpStatus.OK; + +public class CancelMembership extends UseCase { + + public CancelMembership(final ScenarioTest testSuite) { + super(testSuite); + } + + @Override + protected HttpResponse run() { + + obtain("Membership: %{memberNumber}", () -> + httpGet("/api/hs/office/memberships?memberNumber=%{memberNumber}") + .expectArrayElements(1), + response -> response.expectArrayElements(1).getFromBody("[0].uuid") + ); + + return withTitle("Patch the New Status Into the Membership", () -> + httpPatch("/api/hs/office/memberships/%{Membership: %{memberNumber}}", usingJsonBody(""" + { + "validTo": ${validTo}, + "status": ${newStatus} + } + """)) + .expecting(HttpStatus.OK).expecting(ContentType.JSON) + ); + } + + @Override + protected void verify(final UseCase.HttpResponse response) { + verify( + "Verify That the Membership Got Cancelled", + () -> httpGet("/api/hs/office/memberships/%{Membership: %{memberNumber}}") + .expecting(OK).expecting(JSON), + path("validTo").contains("%{validTo}"), + path("status").contains("CANCELLED") + ); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CreateMembership.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CreateMembership.java index 5a28f4d4..d1b47aec 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CreateMembership.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CreateMembership.java @@ -5,6 +5,9 @@ import net.hostsharing.hsadminng.hs.office.scenarios.UseCase; import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest; import org.springframework.http.HttpStatus; +import static io.restassured.http.ContentType.JSON; +import static org.springframework.http.HttpStatus.OK; + public class CreateMembership extends UseCase { public CreateMembership(final ScenarioTest testSuite) { @@ -13,17 +16,26 @@ public class CreateMembership extends UseCase { @Override protected HttpResponse run() { - obtain("Membership: %{partnerName} 00", () -> - httpPost("/api/hs/office/memberships", usingJsonBody(""" - { - "partnerUuid": ${Partner: Test AG}, - "memberNumberSuffix": ${memberNumberSuffix}, - "validFrom": ${validFrom}, - "membershipFeeBillable": ${membershipFeeBillable} - } - """)) - .expecting(HttpStatus.CREATED).expecting(ContentType.JSON) + return httpPost("/api/hs/office/memberships", usingJsonBody(""" + { + "partnerUuid": ${Partner: Test AG}, + "memberNumberSuffix": ${memberNumberSuffix}, + "status": "ACTIVE", + "validFrom": ${validFrom}, + "membershipFeeBillable": ${membershipFeeBillable} + } + """)) + .expecting(HttpStatus.CREATED).expecting(ContentType.JSON); + } + + @Override + protected void verify(final UseCase.HttpResponse response) { + verify( + "Verify That the Membership Got Created", + () -> httpGet("/api/hs/office/memberships/" + response.getLocationUuid()) + .expecting(OK).expecting(JSON), + path("validFrom").contains("%{validFrom}"), + path("status").contains("ACTIVE") ); - return null; } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddOperationsContactToPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddOperationsContactToPartner.java index 6c1fd1dd..8cef6e10 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddOperationsContactToPartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddOperationsContactToPartner.java @@ -66,7 +66,7 @@ public class AddOperationsContactToPartner extends UseCase.HttpResponse response) { verify( "Verify the New OPERATIONS Relation", () -> httpGet("/api/hs/office/relations?relationType=OPERATIONS&personData=" + uriEncoded( diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java index c5381684..b90fb532 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/AddRepresentativeToPartner.java @@ -69,7 +69,7 @@ public class AddRepresentativeToPartner extends UseCase.HttpResponse response) { verify( "Verify the REPRESENTATIVE Relation Got Removed", () -> httpGet("/api/hs/office/relations?relationType=REPRESENTATIVE&personData=" + uriEncoded("%{representativeFamilyName}")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/CreatePartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/CreatePartner.java index 9538fdbf..5809ea96 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/CreatePartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/partner/CreatePartner.java @@ -76,7 +76,7 @@ public class CreatePartner extends UseCase { } @Override - protected void verify() { + protected void verify(final UseCase.HttpResponse response) { verify( "Verify the New Partner Relation", () -> httpGet("/api/hs/office/relations?relationType=PARTNER&contactData=&{contactCaption}") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/person/ShouldUpdatePersonData.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/person/ShouldUpdatePersonData.java new file mode 100644 index 00000000..04a61c5f --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/person/ShouldUpdatePersonData.java @@ -0,0 +1,48 @@ +package net.hostsharing.hsadminng.hs.office.scenarios.person; + +import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest; +import net.hostsharing.hsadminng.hs.office.scenarios.UseCase; +import org.springframework.http.HttpStatus; + +import static io.restassured.http.ContentType.JSON; +import static org.springframework.http.HttpStatus.OK; + +public class ShouldUpdatePersonData extends UseCase { + + public ShouldUpdatePersonData(final ScenarioTest testSuite) { + super(testSuite); + } + + @Override + protected HttpResponse run() { + + obtain( + "personUuid", + () -> httpGet("/api/hs/office/persons?name=" + uriEncoded("%{oldFamilyName}")) + .expecting(OK).expecting(JSON), + response -> response.expectArrayElements(1).getFromBody("[0].uuid"), + "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." + ); + + withTitle("Patch the Additional Phone-Number into the Person", () -> + httpPatch("/api/hs/office/persons/%{personUuid}", usingJsonBody(""" + { + "familyName": ${newFamilyName} + } + """)) + .expecting(HttpStatus.OK) + ); + + return null; + } + + @Override + protected void verify(final UseCase.HttpResponse response) { + verify( + "Verify that the Family Name Got Amended", + () -> httpGet("/api/hs/office/persons/%{personUuid}") + .expecting(OK).expecting(JSON), + path("familyName").contains("%{newFamilyName}") + ); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/RemoveOperationsContactFromPartner.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/RemoveOperationsContactFromPartner.java index c30019e7..2190e6d9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/RemoveOperationsContactFromPartner.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/subscription/RemoveOperationsContactFromPartner.java @@ -33,7 +33,7 @@ public class RemoveOperationsContactFromPartner extends UseCase.HttpResponse response) { verify( "Verify the New OPERATIONS Relation", () -> httpGet("/api/hs/office/relations/&{Operations-Contact: %{operationsContactPerson}}")