From 16538e2524c71494e25dad5ec89f31bd3ff1e22b Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 10:10:56 +0100 Subject: [PATCH 1/4] add shouldUpdatePersonData --- .../scenarios/HsOfficeScenarioTests.java | 11 +++++ .../person/ShouldUpdatePersonData.java | 48 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/person/ShouldUpdatePersonData.java 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..8d1fabb1 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 @@ -17,6 +17,7 @@ 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 +198,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") 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..23fbf726 --- /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() { + verify( + "Verify if the New Phone Number Got Added", + () -> httpGet("/api/hs/office/persons/%{personUuid}") + .expecting(OK).expecting(JSON), + path("familyName").contains("%{newFamilyName}") + ); + } +} -- 2.39.5 From 346912f1e60efbe23b751bb21ed9d838087e2efe Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 10:17:30 +0100 Subject: [PATCH 2/4] fix title in ShouldUpdatePersonData.verify --- .../hs/office/scenarios/person/ShouldUpdatePersonData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 23fbf726..a4af5c22 100644 --- 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 @@ -39,7 +39,7 @@ public class ShouldUpdatePersonData extends UseCase { @Override protected void verify() { verify( - "Verify if the New Phone Number Got Added", + "Verify that the Family Name Got Amended", () -> httpGet("/api/hs/office/persons/%{personUuid}") .expecting(OK).expecting(JSON), path("familyName").contains("%{newFamilyName}") -- 2.39.5 From 2a2b706e6db942407580f27e6288dfa8fedede1d Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 12:10:39 +0100 Subject: [PATCH 3/4] add scenario shouldCreateMembershipForPartner --- .../HsOfficeMembershipController.java | 4 +- .../scenarios/HsOfficeScenarioTests.java | 15 ++++++ .../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 | 2 +- .../RemoveOperationsContactFromPartner.java | 2 +- 13 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/membership/CancelMembership.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 8d1fabb1..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,6 +11,7 @@ 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; @@ -313,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..c130a0bc --- /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 Created", + () -> 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 index a4af5c22..04a61c5f 100644 --- 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 @@ -37,7 +37,7 @@ public class ShouldUpdatePersonData extends UseCase { } @Override - protected void verify() { + protected void verify(final UseCase.HttpResponse response) { verify( "Verify that the Family Name Got Amended", () -> httpGet("/api/hs/office/persons/%{personUuid}") 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}}") -- 2.39.5 From 82f0e9f4b9056b6bc0505b00ff9435052722f755 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 6 Nov 2024 13:37:10 +0100 Subject: [PATCH 4/4] fix verify title in CancelMembership --- .../hs/office/scenarios/membership/CancelMembership.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index c130a0bc..23f718b5 100644 --- 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 @@ -37,7 +37,7 @@ public class CancelMembership extends UseCase { @Override protected void verify(final UseCase.HttpResponse response) { verify( - "Verify That the Membership Got Created", + "Verify That the Membership Got Cancelled", () -> httpGet("/api/hs/office/memberships/%{Membership: %{memberNumber}}") .expecting(OK).expecting(JSON), path("validTo").contains("%{validTo}"), -- 2.39.5