feature/use-case-acceptance-tests-2 #117

Merged
hsh-michaelhoennig merged 38 commits from feature/use-case-acceptance-tests-2 into master 2024-11-05 13:58:39 +01:00
4 changed files with 43 additions and 37 deletions
Showing only changes of commit 2b81afff4d - Show all commits

View File

@ -6,6 +6,7 @@ import com.jayway.jsonpath.JsonPath;
import io.restassured.http.ContentType;
import lombok.Getter;
import lombok.SneakyThrows;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.PathAssertion;
import net.hostsharing.hsadminng.reflection.AnnotationFinder;
import org.apache.commons.collections4.map.LinkedMap;
import org.assertj.core.api.AbstractStringAssert;
@ -26,6 +27,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
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) {
withTitle(ScenarioTest.resolve(alias), () -> {
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;
code.run();
this.nextTitle = null;
@ -193,6 +184,20 @@ public abstract class UseCase<T extends UseCase<?>> {
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) {
return ScenarioTest.uuid(alias);
}
@ -300,6 +305,8 @@ public abstract class UseCase<T extends UseCase<?>> {
testReport.printLine("\n### " + nextTitle + "\n");
} else if (resultAlias != null) {
testReport.printLine("\n### " + resultAlias + "\n");
} else {
testReport.printLine("\n### FIXME\n");
}
// 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 org.springframework.http.HttpStatus;
import java.util.function.Consumer;
import java.util.function.Supplier;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK;
@ -27,6 +25,7 @@ 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."
);
withTitle("Patch the Additional Phone-Number into the Contact", () ->
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
{
"phoneNumbers": {
@ -34,7 +33,8 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
}
}
"""))
.expecting(HttpStatus.OK);
.expecting(HttpStatus.OK)
);
return null;
}
@ -42,23 +42,10 @@ public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContact
@Override
protected void verify() {
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}"))
.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);
}
}

View File

@ -13,7 +13,7 @@ public class PathAssertion {
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));
}
}

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."
);
withTitle("Replace the Contact-Reference in the Partner-Relation", () ->
httpPatch("/api/hs/office/relations/%{partnerRelationUuid}", usingJsonBody("""
{
"contactUuid": ${Contact: %{newContactCaption}}
}
"""))
.expecting(OK);
.expecting(OK)
);
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}")
);
}
}