feature/use-case-acceptance-tests-2 #117
@ -8,6 +8,7 @@ import lombok.Getter;
|
||||
import lombok.SneakyThrows;
|
||||
import net.hostsharing.hsadminng.reflection.AnnotationFinder;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
import org.assertj.core.api.AbstractStringAssert;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -286,6 +287,11 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
return JsonPath.parse(response.body()).read(ScenarioTest.resolve(path));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public AbstractStringAssert<?> path(final String path) {
|
||||
return assertThat(getFromBody(path));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private void reportRequestAndResponse(final HttpMethod httpMethod, final String uri, final String requestBody) {
|
||||
|
||||
|
@ -4,8 +4,10 @@ import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static io.restassured.http.ContentType.JSON;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContactData> {
|
||||
@ -17,8 +19,9 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
|
||||
@Override
|
||||
protected HttpResponse run() {
|
||||
|
||||
obtain("partnerContactUuid", () ->
|
||||
httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
||||
obtain(
|
||||
"partnerContactUuid",
|
||||
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
||||
.expecting(OK).expecting(JSON),
|
||||
response -> response.expectArrayElements(1).getFromBody("[0].contact.uuid"),
|
||||
"In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one."
|
||||
@ -38,10 +41,24 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
|
||||
|
||||
@Override
|
||||
protected void verify() {
|
||||
testSuite.testReport.printPara("### Verify");
|
||||
assertThat(
|
||||
httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
||||
.expecting(OK).expecting(JSON).expectArrayElements(1).getFromBody("[0].contact.phoneNumbers.%{newOfficePhoneNumberKey}")
|
||||
).isEqualTo(ScenarioTest.resolve("%{newOfficePhoneNumber}"));
|
||||
validate(
|
||||
"Verify If The New Phone Number Got Added",
|
||||
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
||||
.expecting(OK).expecting(JSON).expectArrayElements(1),
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package net.hostsharing.hsadminng.hs.office.scenarios.contact;
|
||||
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
|
||||
import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PathAssertion {
|
||||
|
||||
private final String path;
|
||||
|
||||
public PathAssertion(final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public Consumer<UseCase.HttpResponse> isEqualTo(final String resolvableValue) {
|
||||
return response -> response.path(path).isEqualTo(ScenarioTest.resolve(resolvableValue));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user