verify CreatePartner

This commit is contained in:
Michael Hoennig 2024-11-04 19:07:40 +01:00
parent 8342aedff4
commit 691c7efc82
5 changed files with 18 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers; import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers; import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -192,7 +193,7 @@ public abstract class UseCase<T extends UseCase<?>> {
return new PathAssertion(path); return new PathAssertion(path);
} }
protected void validate( protected void verify(
final String title, final String title,
final Supplier<UseCase.HttpResponse> http, final Supplier<UseCase.HttpResponse> http,
final Consumer<UseCase.HttpResponse> assertion) { final Consumer<UseCase.HttpResponse> assertion) {
@ -208,7 +209,7 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
public String uriEncoded(final String text) { public String uriEncoded(final String text) {
return encode(ScenarioTest.resolve(text)); return encode(ScenarioTest.resolve(text), StandardCharsets.UTF_8);
} }
public static class JsonTemplate { public static class JsonTemplate {

View File

@ -41,7 +41,7 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
@Override @Override
protected void verify() { protected void verify() {
validate( verify(
"Verify if the New Phone Number Got Added", "Verify if the New Phone Number Got Added",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
.expecting(OK).expecting(JSON).expectArrayElements(1), .expecting(OK).expecting(JSON).expectArrayElements(1),

View File

@ -40,7 +40,7 @@ public class RemovePhoneNumberFromContactData extends UseCase<RemovePhoneNumberF
@Override @Override
protected void verify() { protected void verify() {
validate( verify(
"Verify if the New Phone Number Got Added", "Verify if the New Phone Number Got Added",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
.expecting(OK).expecting(JSON).expectArrayElements(1), .expecting(OK).expecting(JSON).expectArrayElements(1),

View File

@ -54,7 +54,7 @@ public class ReplaceContactData extends UseCase<ReplaceContactData> {
@Override @Override
protected void verify() { protected void verify() {
validate( verify(
"Verify if the Contact-Relation Got Replaced in the Partner-Relation", "Verify if the Contact-Relation Got Replaced in the Partner-Relation",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}")) () -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
.expecting(OK).expecting(JSON).expectArrayElements(1), .expecting(OK).expecting(JSON).expectArrayElements(1),

View File

@ -28,7 +28,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
"Even in production data we expect this query to return just a single result." // TODO.impl: add constraint? "Even in production data we expect this query to return just a single result." // TODO.impl: add constraint?
); );
obtain("Person: %{tradeName???%{givenName???} %{familyName???}}", () -> obtain("Person: %{%{tradeName???}???%{givenName???} %{familyName???}}", () ->
httpPost("/api/hs/office/persons", usingJsonBody(""" httpPost("/api/hs/office/persons", usingJsonBody("""
{ {
"personType": ${personType???}, "personType": ${personType???},
@ -61,7 +61,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
"partnerNumber": ${partnerNumber}, "partnerNumber": ${partnerNumber},
"partnerRel": { "partnerRel": {
"anchorUuid": ${Person: Hostsharing eG}, "anchorUuid": ${Person: Hostsharing eG},
"holderUuid": ${Person: %{tradeName???%{givenName???} %{familyName???}}}, "holderUuid": ${Person: %{%{tradeName???}???%{givenName???} %{familyName???}}},
"contactUuid": ${Contact: %{contactCaption}} "contactUuid": ${Contact: %{contactCaption}}
}, },
"details": { "details": {
@ -72,4 +72,14 @@ public class CreatePartner extends UseCase<CreatePartner> {
""")) """))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON); .expecting(HttpStatus.CREATED).expecting(ContentType.JSON);
} }
@Override
protected void verify() {
verify(
"Verify the New Partner Relation",
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{%{tradeName???}???%{givenName???} %{familyName???}}"))
.expecting(OK).expecting(JSON).expectArrayElements(1),
path("[0].contact.caption").contains("%{contactCaption}")
);
}
} }