Compare commits

..

2 Commits

Author SHA1 Message Date
Michael Hoennig
9146b79b14 verify AddRepresentativeToPartner 2024-11-04 19:14:46 +01:00
Michael Hoennig
691c7efc82 verify CreatePartner 2024-11-04 19:07:40 +01:00
6 changed files with 28 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.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;
import java.util.LinkedHashMap;
@ -192,7 +193,7 @@ public abstract class UseCase<T extends UseCase<?>> {
return new PathAssertion(path);
}
protected void validate(
protected void verify(
final String title,
final Supplier<UseCase.HttpResponse> http,
final Consumer<UseCase.HttpResponse> assertion) {
@ -208,7 +209,7 @@ public abstract class UseCase<T extends UseCase<?>> {
}
public String uriEncoded(final String text) {
return encode(ScenarioTest.resolve(text));
return encode(ScenarioTest.resolve(text), StandardCharsets.UTF_8);
}
public static class JsonTemplate {

View File

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

View File

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

View File

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

View File

@ -65,4 +65,14 @@ public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartn
"""))
.expecting(CREATED).expecting(JSON);
}
@Override
protected void verify() {
verify(
"Verify the New REPRESENTATIVE Relation",
() -> httpGet("/api/hs/office/relations?relationType=REPRESENTATIVE&personData=" + uriEncoded("%{representativeFamilyName}"))
.expecting(OK).expecting(JSON).expectArrayElements(1),
path("[0].contact.caption").contains("%{representativeGivenName} %{representativeFamilyName}")
);
}
}

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?
);
obtain("Person: %{tradeName???%{givenName???} %{familyName???}}", () ->
obtain("Person: %{%{tradeName???}???%{givenName???} %{familyName???}}", () ->
httpPost("/api/hs/office/persons", usingJsonBody("""
{
"personType": ${personType???},
@ -61,7 +61,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
"partnerNumber": ${partnerNumber},
"partnerRel": {
"anchorUuid": ${Person: Hostsharing eG},
"holderUuid": ${Person: %{tradeName???%{givenName???} %{familyName???}}},
"holderUuid": ${Person: %{%{tradeName???}???%{givenName???} %{familyName???}}},
"contactUuid": ${Contact: %{contactCaption}}
},
"details": {
@ -72,4 +72,14 @@ public class CreatePartner extends UseCase<CreatePartner> {
"""))
.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}")
);
}
}