Compare commits

..

No commits in common. "42c4d4102e116d4e3d67a4c1f6ae4d04c826b3a1" and "5989d4ab4f2a46a1814a7867587377834be6882a" have entirely different histories.

15 changed files with 71 additions and 184 deletions

View File

@ -3,7 +3,6 @@ package net.hostsharing.hsadminng.hs.office.scenarios;
import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.AddPhoneNumberToContactData;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.AmendContactData;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.RemovePhoneNumberFromContactData;
import net.hostsharing.hsadminng.hs.office.scenarios.contact.ReplaceContactData;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateSelfDebitorForPartner;
@ -151,18 +150,8 @@ class HsOfficeScenarioTests extends ScenarioTest {
void shouldAddPhoneNumberToContactData() {
new AddPhoneNumberToContactData(this)
.given("partnerName", "Matthieu")
.given("phoneNumberKeyToAdd", "mobile")
.given("phoneNumberToAdd", "+49 152 1234567")
.doRun();
}
@Test
@Order(1102)
@Requires("Partner: Michelle Matthieu")
void shouldRemovePhoneNumberFromContactData() {
new RemovePhoneNumberFromContactData(this)
.given("partnerName", "Matthieu")
.given("phoneNumberKeyToRemove", "office")
.given("newOfficePhoneNumberKey", "mobile")
.given("newOfficePhoneNumber", "+49 152 1234567")
.doRun();
}

View File

@ -76,7 +76,6 @@ public class TemplateResolver {
private String dropLinesWithNullProperties(final String text) {
return Arrays.stream(text.split("\n"))
.filter(TemplateResolver::keepLine)
.map(TemplateResolver::keptNullValues)
.collect(Collectors.joining("\n"));
}
@ -85,10 +84,6 @@ public class TemplateResolver {
return !trimmed.endsWith("null,") && !trimmed.endsWith("null");
}
private static String keptNullValues(final String line) {
return line.replace(": NULL", ": null");
}
private String copy() {
while (hasMoreChars()) {
if (PlaceholderPrefix.contains(currentChar()) && nextChar() == '{') {

View File

@ -6,10 +6,9 @@ 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.OptionalAssert;
import org.assertj.core.api.AbstractStringAssert;
import org.hibernate.AssertionFailure;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
@ -26,15 +25,12 @@ import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import static java.net.URLEncoder.encode;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.platform.commons.util.StringUtils.isBlank;
import static org.junit.platform.commons.util.StringUtils.isNotBlank;
@ -111,25 +107,33 @@ public abstract class UseCase<T extends UseCase<?>> {
final Function<HttpResponse, String> extractor,
final String... extraInfo) {
withTitle(ScenarioTest.resolve(alias), () -> {
final var response = http.get().keep(extractor);
http.get().keep(extractor);
Arrays.stream(extraInfo).forEach(testReport::printPara);
return response;
});
}
// 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), () -> {
final var response = http.get().keep();
http.get().keep();
Arrays.stream(extraInfo).forEach(testReport::printPara);
return response;
});
}
public HttpResponse withTitle(final String title, final Supplier<HttpResponse> code) {
private void withTitle(final String title, final Runnable code) {
this.nextTitle = title;
final var response = code.get();
code.run();
this.nextTitle = null;
return response;
}
@SneakyThrows
@ -189,21 +193,6 @@ 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);
return response;
});
}
public final UUID uuid(final String alias) {
return ScenarioTest.uuid(alias);
}
@ -225,7 +214,7 @@ public abstract class UseCase<T extends UseCase<?>> {
}
}
public final class HttpResponse {
public class HttpResponse {
@Getter
private final java.net.http.HttpResponse<String> response;
@ -264,7 +253,7 @@ public abstract class UseCase<T extends UseCase<?>> {
return this;
}
public HttpResponse keep(final Function<HttpResponse, String> extractor) {
public void keep(final Function<HttpResponse, String> extractor) {
final var alias = nextTitle != null ? nextTitle : resultAlias;
assertThat(alias).as("cannot keep result, no alias found").isNotNull();
@ -272,16 +261,14 @@ public abstract class UseCase<T extends UseCase<?>> {
ScenarioTest.putAlias(
alias,
new ScenarioTest.Alias<>(UseCase.this.getClass(), UUID.fromString(value)));
return this;
}
public HttpResponse keep() {
public void keep() {
final var alias = nextTitle != null ? nextTitle : resultAlias;
assertThat(alias).as("cannot keep result, no alias found").isNotNull();
ScenarioTest.putAlias(
alias,
new ScenarioTest.Alias<>(UseCase.this.getClass(), locationUuid));
return this;
}
@SneakyThrows
@ -301,17 +288,8 @@ public abstract class UseCase<T extends UseCase<?>> {
}
@SneakyThrows
public Optional<String> getFromBodyAsOptional(final String path) {
try {
return Optional.ofNullable(JsonPath.parse(response.body()).read(ScenarioTest.resolve(path)));
} catch (final Exception e) {
return null; // means the property did not exist at all, not that it was there with value null
}
}
@SneakyThrows
public OptionalAssert<String> path(final String path) {
return assertThat(getFromBodyAsOptional(path));
public AbstractStringAssert<?> path(final String path) {
return assertThat(getFromBody(path));
}
@SneakyThrows
@ -322,8 +300,6 @@ public abstract class UseCase<T extends UseCase<?>> {
testReport.printLine("\n### " + nextTitle + "\n");
} else if (resultAlias != null) {
testReport.printLine("\n### " + resultAlias + "\n");
} else {
fail("please wrap the http...-call in the UseCase using `withTitle(...)`");
}
// the request

View File

@ -4,6 +4,8 @@ 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;
@ -25,16 +27,14 @@ 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": {
${phoneNumberKeyToAdd}: ${phoneNumberToAdd}
${newOfficePhoneNumberKey}: ${newOfficePhoneNumber}
}
}
"""))
.expecting(HttpStatus.OK)
);
.expecting(HttpStatus.OK);
return null;
}
@ -42,10 +42,23 @@ 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.%{phoneNumberKeyToAdd}").contains("%{phoneNumberToAdd}")
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

@ -23,7 +23,6 @@ public class AmendContactData extends UseCase<AmendContactData> {
"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 New Phone Number Into the Contact", () ->
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
{
"caption": ${newContactCaption???},
@ -36,8 +35,7 @@ public class AmendContactData extends UseCase<AmendContactData> {
}
}
"""))
.expecting(HttpStatus.OK)
);
.expecting(HttpStatus.OK);
return null;
}

View File

@ -2,7 +2,6 @@ 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 net.hostsharing.hsadminng.hs.office.scenarios.UseCase.HttpResponse;
import java.util.function.Consumer;
@ -14,12 +13,7 @@ public class PathAssertion {
this.path = path;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public Consumer<UseCase.HttpResponse> contains(final String resolvableValue) {
return response -> response.path(path).contains(ScenarioTest.resolve(resolvableValue));
}
public Consumer<HttpResponse> doesNotExist() {
return response -> response.path(path).isNull(); // here, null Optional means key not found in JSON
public Consumer<UseCase.HttpResponse> isEqualTo(final String resolvableValue) {
return response -> response.path(path).isEqualTo(ScenarioTest.resolve(resolvableValue));
}
}

View File

@ -1,50 +0,0 @@
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 org.springframework.http.HttpStatus;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK;
public class RemovePhoneNumberFromContactData extends UseCase<RemovePhoneNumberFromContactData> {
public RemovePhoneNumberFromContactData(final ScenarioTest testSuite) {
super(testSuite);
}
@Override
protected HttpResponse run() {
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."
);
withTitle("Patch the Additional Phone-Number into the Contact", () ->
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
{
"phoneNumbers": {
${phoneNumberKeyToRemove}: NULL
}
}
"""))
.expecting(HttpStatus.OK)
);
return null;
}
@Override
protected void verify() {
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.%{phoneNumberKeyToRemove}").doesNotExist()
);
}
}

View File

@ -40,25 +40,13 @@ 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").contains("%{newContactCaption}")
);
}
}

View File

@ -24,10 +24,8 @@ public class DeleteDebitor extends UseCase<DeleteDebitor> {
@Override
protected HttpResponse run() {
withTitle("Delete the Debitor using its UUID", () ->
httpDelete("/api/hs/office/debitors/&{Debitor: Test AG - delete debitor}")
.expecting(HttpStatus.NO_CONTENT)
);
.expecting(HttpStatus.NO_CONTENT);
return null;
}
}

View File

@ -24,8 +24,8 @@ public class FinallyDeleteSepaMandateForDebitor extends UseCase<FinallyDeleteSep
);
// TODO.spec: When to allow actual deletion of SEPA-mandates? Add constraint accordingly.
return withTitle("Delete the SEPA-Mandate by its UUID", () -> httpDelete("/api/hs/office/sepamandates/&{SEPA-Mandate: %{bankAccountIBAN}}")
.expecting(HttpStatus.NO_CONTENT)
);
httpDelete("/api/hs/office/sepamandates/&{SEPA-Mandate: %{bankAccountIBAN}}")
.expecting(HttpStatus.NO_CONTENT);
return null;
}
}

View File

@ -22,13 +22,11 @@ public class InvalidateSepaMandateForDebitor extends UseCase<InvalidateSepaManda
"With production data, the bank-account could be used in multiple SEPA-mandates, make sure to use the right one!"
);
return withTitle("Patch the End of the Mandate into the SEPA-Mandate", () ->
httpPatch("/api/hs/office/sepamandates/&{SEPA-Mandate: %{bankAccountIBAN}}", usingJsonBody("""
return httpPatch("/api/hs/office/sepamandates/&{SEPA-Mandate: %{bankAccountIBAN}}", usingJsonBody("""
{
"validUntil": ${mandateValidUntil}
}
"""))
.expecting(OK).expecting(JSON)
);
.expecting(OK).expecting(JSON);
}
}

View File

@ -18,10 +18,8 @@ public class DeletePartner extends UseCase<DeletePartner> {
@Override
protected HttpResponse run() {
withTitle("Delete Partner by its UUID", () ->
httpDelete("/api/hs/office/partners/&{Partner: Delete AG}")
.expecting(HttpStatus.NO_CONTENT)
);
.expecting(HttpStatus.NO_CONTENT);
return null;
}
}

View File

@ -14,14 +14,12 @@ public class CreatePerson extends UseCase<CreatePerson> {
@Override
protected HttpResponse run() {
return withTitle("Create the Person", () ->
httpPost("/api/hs/office/persons", usingJsonBody("""
return httpPost("/api/hs/office/persons", usingJsonBody("""
{
"personType": ${personType},
"tradeName": ${tradeName}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
);
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON);
}
}

View File

@ -1,7 +1,7 @@
package net.hostsharing.hsadminng.hs.office.scenarios.subscription;
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
import net.hostsharing.hsadminng.hs.office.scenarios.UseCase;
import net.hostsharing.hsadminng.hs.office.scenarios.ScenarioTest;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.NO_CONTENT;
@ -16,20 +16,14 @@ public class RemoveOperationsContactFromPartner extends UseCase<RemoveOperations
@Override
protected HttpResponse run() {
obtain("Operations-Contact: %{operationsContactPerson}",
() ->
httpGet("/api/hs/office/relations?relationType=OPERATIONS&name=" + uriEncoded(
"%{operationsContactPerson}"))
obtain("Operations-Contact: %{operationsContactPerson}", () ->
httpGet("/api/hs/office/relations?relationType=OPERATIONS&name=" + uriEncoded("%{operationsContactPerson}"))
.expecting(OK).expecting(JSON),
response -> response.expectArrayElements(1).getFromBody("[0].uuid"),
"In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one."
);
withTitle("Delete the Contact", () ->
httpDelete("/api/hs/office/relations/&{Operations-Contact: %{operationsContactPerson}}")
.expecting(NO_CONTENT)
);
return null;
return httpDelete("/api/hs/office/relations/&{Operations-Contact: %{operationsContactPerson}}")
.expecting(NO_CONTENT);
}
}

View File

@ -25,9 +25,7 @@ public class UnsubscribeFromMailinglist extends UseCase<UnsubscribeFromMailingli
"In production, data this query could result in multiple outputs. In that case, you have to find out which is the right one."
);
return withTitle("Delete the Subscriber-Relation by its UUID", () ->
httpDelete("/api/hs/office/relations/&{Subscription: %{subscriberEMailAddress}}")
.expecting(NO_CONTENT)
);
return httpDelete("/api/hs/office/relations/&{Subscription: %{subscriberEMailAddress}}")
.expecting(NO_CONTENT);
}
}