fix missing title and add some verification in AddPhoneNumberToContactData and ReplaceContactData

This commit is contained in:
Michael Hoennig 2024-11-04 14:08:58 +01:00
parent 5989d4ab4f
commit 2b81afff4d
4 changed files with 43 additions and 37 deletions

View File

@ -6,6 +6,7 @@ import com.jayway.jsonpath.JsonPath;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import lombok.Getter; import lombok.Getter;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.PathAssertion;
import net.hostsharing.hsadminng.reflection.AnnotationFinder; import net.hostsharing.hsadminng.reflection.AnnotationFinder;
import org.apache.commons.collections4.map.LinkedMap; import org.apache.commons.collections4.map.LinkedMap;
import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.AbstractStringAssert;
@ -26,6 +27,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -112,17 +114,6 @@ public abstract class UseCase<T extends UseCase<?>> {
}); });
} }
// public final void validate(
// final String title,
// final Supplier<HttpResponse> http,
// final Function<HttpResponse, String> extractor,
// final String... extraInfo) {
// withTitle(ScenarioTest.resolve(title), () -> {
// http.get();
// Arrays.stream(extraInfo).forEach(testReport::printPara);
// });
// }
public final void obtain(final String alias, final Supplier<HttpResponse> http, final String... extraInfo) { public final void obtain(final String alias, final Supplier<HttpResponse> http, final String... extraInfo) {
withTitle(ScenarioTest.resolve(alias), () -> { withTitle(ScenarioTest.resolve(alias), () -> {
http.get().keep(); http.get().keep();
@ -130,7 +121,7 @@ public abstract class UseCase<T extends UseCase<?>> {
}); });
} }
private void withTitle(final String title, final Runnable code) { public void withTitle(final String title, final Runnable code) {
this.nextTitle = title; this.nextTitle = title;
code.run(); code.run();
this.nextTitle = null; this.nextTitle = null;
@ -193,6 +184,20 @@ public abstract class UseCase<T extends UseCase<?>> {
return new HttpResponse(HttpMethod.DELETE, uriPath, null, response); return new HttpResponse(HttpMethod.DELETE, uriPath, null, response);
} }
protected PathAssertion path(final String path) {
return new PathAssertion(path);
}
protected void validate(
final String title,
final Supplier<UseCase<?>.HttpResponse> http,
final Consumer<UseCase<?>.HttpResponse> assertion) {
withTitle(ScenarioTest.resolve(title), () -> {
final var response = http.get();
assertion.accept(response);
});
}
public final UUID uuid(final String alias) { public final UUID uuid(final String alias) {
return ScenarioTest.uuid(alias); return ScenarioTest.uuid(alias);
} }
@ -300,6 +305,8 @@ public abstract class UseCase<T extends UseCase<?>> {
testReport.printLine("\n### " + nextTitle + "\n"); testReport.printLine("\n### " + nextTitle + "\n");
} else if (resultAlias != null) { } else if (resultAlias != null) {
testReport.printLine("\n### " + resultAlias + "\n"); testReport.printLine("\n### " + resultAlias + "\n");
} else {
testReport.printLine("\n### FIXME\n");
} }
// the request // the request

View File

@ -4,8 +4,6 @@ import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
import net.hostsharing.hsadminng.hs.office.scenarios.UseCase; import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static io.restassured.http.ContentType.JSON; import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
@ -27,14 +25,16 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
"In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one." "In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one."
); );
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody(""" withTitle("Patch the Additional Phone-Number into the Contact", () ->
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
{ {
"phoneNumbers": { "phoneNumbers": {
${newOfficePhoneNumberKey}: ${newOfficePhoneNumber} ${newOfficePhoneNumberKey}: ${newOfficePhoneNumber}
} }
} }
""")) """))
.expecting(HttpStatus.OK); .expecting(HttpStatus.OK)
);
return null; return null;
} }
@ -42,23 +42,10 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
@Override @Override
protected void verify() { protected void verify() {
validate( validate(
"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),
path("[0].contact.phoneNumbers.%{newOfficePhoneNumberKey}").isEqualTo("%{newOfficePhoneNumber}") path("[0].contact.phoneNumbers.%{newOfficePhoneNumberKey}").isEqualTo("%{newOfficePhoneNumber}")
); );
} }
private PathAssertion path(final String path) {
return new PathAssertion(path);
}
private void validate(
final String title,
final Supplier<HttpResponse> http,
final Consumer<UseCase.HttpResponse> assertion) {
testSuite.testReport.printPara("### " + title);
final var response = http.get();
assertion.accept(response);
}
} }

View File

@ -13,7 +13,7 @@ public class PathAssertion {
this.path = path; this.path = path;
} }
public Consumer<UseCase.HttpResponse> isEqualTo(final String resolvableValue) { public Consumer<UseCase<?>.HttpResponse> isEqualTo(final String resolvableValue) {
return response -> response.path(path).isEqualTo(ScenarioTest.resolve(resolvableValue)); return response -> response.path(path).isEqualTo(ScenarioTest.resolve(resolvableValue));
} }
} }

View File

@ -40,13 +40,25 @@ public class ReplaceContactData extends UseCase<ReplaceContactData> {
"Please check first if that contact already exists, if so, use it's UUID below." "Please check first if that contact already exists, if so, use it's UUID below."
); );
httpPatch("/api/hs/office/relations/%{partnerRelationUuid}", usingJsonBody(""" withTitle("Replace the Contact-Reference in the Partner-Relation", () ->
{ httpPatch("/api/hs/office/relations/%{partnerRelationUuid}", usingJsonBody("""
"contactUuid": ${Contact: %{newContactCaption}} {
} "contactUuid": ${Contact: %{newContactCaption}}
""")) }
.expecting(OK); """))
.expecting(OK)
);
return null; return null;
} }
@Override
protected void verify() {
validate(
"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),
path("[0].contact.caption").isEqualTo("%{newContactCaption}")
);
}
} }