Compare commits

..

No commits in common. "5989d4ab4f2a46a1814a7867587377834be6882a" and "5977eaf8285742ad11ede3c5d600a213509f27eb" have entirely different histories.

5 changed files with 4 additions and 121 deletions

View File

@ -1,7 +1,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.ReplaceContactData;
import net.hostsharing.hsadminng.hs.office.scenarios.debitor.CreateExternalDebitorForPartner;
@ -146,17 +145,6 @@ class HsOfficeScenarioTests extends ScenarioTest {
@Test
@Order(1101)
@Requires("Partner: Michelle Matthieu")
void shouldAddPhoneNumberToContactData() {
new AddPhoneNumberToContactData(this)
.given("partnerName", "Matthieu")
.given("newOfficePhoneNumberKey", "mobile")
.given("newOfficePhoneNumber", "+49 152 1234567")
.doRun();
}
@Test
@Order(1103)
@Requires("Partner: Test AG")
void shouldReplaceContactData() {
new ReplaceContactData(this)

View File

@ -8,7 +8,6 @@ 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;
@ -81,16 +80,11 @@ public abstract class UseCase<T extends UseCase<?>> {
}
})
);
final var response = run();
verify();
return response;
return run();
}
protected abstract HttpResponse run();
protected void verify() {
}
public final UseCase<T> given(final String propName, final Object propValue) {
givenProperties.put(propName, propValue);
ScenarioTest.putProperty(propName, propValue);
@ -112,17 +106,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();
@ -284,12 +267,7 @@ public abstract class UseCase<T extends UseCase<?>> {
@SneakyThrows
public String getFromBody(final String path) {
return JsonPath.parse(response.body()).read(ScenarioTest.resolve(path));
}
@SneakyThrows
public AbstractStringAssert<?> path(final String path) {
return assertThat(getFromBody(path));
return JsonPath.parse(response.body()).read(path);
}
@SneakyThrows

View File

@ -1,64 +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 java.util.function.Consumer;
import java.util.function.Supplier;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.OK;
public class AddPhoneNumberToContactData extends UseCase<AddPhoneNumberToContactData> {
public AddPhoneNumberToContactData(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."
);
httpPatch("/api/hs/office/contacts/%{partnerContactUuid}", usingJsonBody("""
{
"phoneNumbers": {
${newOfficePhoneNumberKey}: ${newOfficePhoneNumber}
}
}
"""))
.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.%{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

@ -17,8 +17,8 @@ public class AmendContactData extends UseCase<AmendContactData> {
protected HttpResponse run() {
obtain("partnerContactUuid", () ->
httpGet("/api/hs/office/relations?relationType=PARTNER&personData=" + uriEncoded("%{partnerName}"))
.expecting(OK).expecting(JSON),
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."
);

View File

@ -1,19 +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 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));
}
}