add verify section
This commit is contained in:
parent
848fb0aae8
commit
5989d4ab4f
@ -8,6 +8,7 @@ import lombok.Getter;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
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.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.junit.jupiter.api.Test;
|
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));
|
return JsonPath.parse(response.body()).read(ScenarioTest.resolve(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public AbstractStringAssert<?> path(final String path) {
|
||||||
|
return assertThat(getFromBody(path));
|
||||||
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void reportRequestAndResponse(final HttpMethod httpMethod, final String uri, final String requestBody) {
|
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 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.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContactData> {
|
public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContactData> {
|
||||||
@ -17,20 +19,21 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
|
|||||||
@Override
|
@Override
|
||||||
protected HttpResponse run() {
|
protected HttpResponse run() {
|
||||||
|
|
||||||
obtain("partnerContactUuid", () ->
|
obtain(
|
||||||
httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
"partnerContactUuid",
|
||||||
|
() -> httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
|
||||||
.expecting(OK).expecting(JSON),
|
.expecting(OK).expecting(JSON),
|
||||||
response -> response.expectArrayElements(1).getFromBody("[0].contact.uuid"),
|
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."
|
"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("""
|
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"phoneNumbers": {
|
"phoneNumbers": {
|
||||||
${newOfficePhoneNumberKey}: ${newOfficePhoneNumber}
|
${newOfficePhoneNumberKey}: ${newOfficePhoneNumber}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
"""))
|
||||||
"""))
|
|
||||||
.expecting(HttpStatus.OK);
|
.expecting(HttpStatus.OK);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -38,10 +41,24 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void verify() {
|
protected void verify() {
|
||||||
testSuite.testReport.printPara("### Verify");
|
validate(
|
||||||
assertThat(
|
"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).getFromBody("[0].contact.phoneNumbers.%{newOfficePhoneNumberKey}")
|
.expecting(OK).expecting(JSON).expectArrayElements(1),
|
||||||
).isEqualTo(ScenarioTest.resolve("%{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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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