amendments according to code review
This commit is contained in:
parent
83ab12f3e0
commit
091454b6ab
@ -1,6 +1,5 @@
|
|||||||
package net.hostsharing.hsadminng.hs.office.scenarios.partner;
|
package net.hostsharing.hsadminng.hs.office.scenarios.partner;
|
||||||
|
|
||||||
import io.restassured.http.ContentType;
|
|
||||||
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest;
|
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest;
|
||||||
import net.hostsharing.hsadminng.hs.scenarios.UseCase;
|
import net.hostsharing.hsadminng.hs.scenarios.UseCase;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -28,7 +27,7 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
|
|||||||
|
|
||||||
obtain("Partner: %{partnerNumber}", () ->
|
obtain("Partner: %{partnerNumber}", () ->
|
||||||
httpGet("/api/hs/office/partners/%{partnerNumber}")
|
httpGet("/api/hs/office/partners/%{partnerNumber}")
|
||||||
.expecting(OK).expecting(JSON),
|
.reportWithResponse().expecting(OK).expecting(JSON),
|
||||||
response -> response.getFromBody("uuid"),
|
response -> response.getFromBody("uuid"),
|
||||||
"Even in production data we expect this query to return just a single result." // TODO.impl: add constraint?
|
"Even in production data we expect this query to return just a single result." // TODO.impl: add constraint?
|
||||||
).extractValue("partnerRel.holder.uuid", "Person: %{nameOfDeceasedPerson}");
|
).extractValue("partnerRel.holder.uuid", "Person: %{nameOfDeceasedPerson}");
|
||||||
@ -41,8 +40,6 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
|
|||||||
"holder": {
|
"holder": {
|
||||||
"personType": "UNINCORPORATED_FIRM",
|
"personType": "UNINCORPORATED_FIRM",
|
||||||
"tradeName": "Erbengemeinschaft %{nameOfDeceasedPerson}",
|
"tradeName": "Erbengemeinschaft %{nameOfDeceasedPerson}",
|
||||||
"givenName": ${givenName???},
|
|
||||||
"familyName": ${familyName???}
|
|
||||||
},
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"caption": "Erbengemeinschaft %{nameOfDeceasedPerson}",
|
"caption": "Erbengemeinschaft %{nameOfDeceasedPerson}",
|
||||||
@ -78,22 +75,9 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
|
|||||||
"contact.uuid": ${Contact: Erbengemeinschaft %{nameOfDeceasedPerson}}
|
"contact.uuid": ${Contact: Erbengemeinschaft %{nameOfDeceasedPerson}}
|
||||||
}
|
}
|
||||||
"""))
|
"""))
|
||||||
.expecting(CREATED).expecting(JSON),
|
.reportWithResponse().expecting(CREATED).expecting(JSON)
|
||||||
""
|
|
||||||
).extractUuidAlias("holder.uuid", "Person: %{representativeGivenName} %{representativeFamilyName}");
|
).extractUuidAlias("holder.uuid", "Person: %{representativeGivenName} %{representativeFamilyName}");
|
||||||
|
|
||||||
obtain("Partner-Relation: Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
|
|
||||||
httpPost("/api/hs/office/relations", usingJsonBody("""
|
|
||||||
{
|
|
||||||
"type": "PARTNER",
|
|
||||||
"anchor.uuid": ${Person: Hostsharing eG},
|
|
||||||
"holder.uuid": ${Person: Erbengemeinschaft %{nameOfDeceasedPerson}},
|
|
||||||
"contact.uuid": ${Contact: Erbengemeinschaft %{nameOfDeceasedPerson}}
|
|
||||||
}
|
|
||||||
"""))
|
|
||||||
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
|
||||||
);
|
|
||||||
|
|
||||||
obtain("Partner: Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
|
obtain("Partner: Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
|
||||||
httpPatch("/api/hs/office/partners/%{Partner: %{partnerNumber}}", usingJsonBody("""
|
httpPatch("/api/hs/office/partners/%{Partner: %{partnerNumber}}", usingJsonBody("""
|
||||||
{
|
{
|
||||||
|
@ -129,22 +129,26 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
final String... extraInfo) {
|
final String... extraInfo) {
|
||||||
return withTitle(title, () -> {
|
return withTitle(title, () -> {
|
||||||
final var response = http.get().keep(extractor);
|
final var response = http.get().keep(extractor);
|
||||||
|
response.optionallyReportRequestAndResponse();
|
||||||
Arrays.stream(extraInfo).forEach(testReport::printPara);
|
Arrays.stream(extraInfo).forEach(testReport::printPara);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public final HttpResponse obtain(final String alias, final Supplier<HttpResponse> http, final String... extraInfo) {
|
public final HttpResponse obtain(final String alias, final Supplier<HttpResponse> httpCall, final String... extraInfo) {
|
||||||
return withTitle(alias, () -> {
|
return withTitle(alias, () -> {
|
||||||
final var response = http.get().keep();
|
final var response = httpCall.get().keep();
|
||||||
|
response.optionallyReportRequestAndResponse();
|
||||||
Arrays.stream(extraInfo).forEach(testReport::printPara);
|
Arrays.stream(extraInfo).forEach(testReport::printPara);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse withTitle(final String resolvableTitle, final Supplier<HttpResponse> code) {
|
public HttpResponse withTitle(final String resolvableTitle, final Supplier<HttpResponse> httpCall, final String... extraInfo) {
|
||||||
this.nextTitle = resolvableTitle;
|
this.nextTitle = resolvableTitle;
|
||||||
final var response = code.get();
|
final var response = httpCall.get();
|
||||||
|
response.optionallyReportRequestAndResponse();
|
||||||
|
Arrays.stream(extraInfo).forEach(testReport::printPara);
|
||||||
this.nextTitle = null;
|
this.nextTitle = null;
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -274,7 +278,8 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
@Getter
|
@Getter
|
||||||
private UUID locationUuid;
|
private UUID locationUuid;
|
||||||
|
|
||||||
private boolean reported = false;
|
private boolean reportGenerated = false;
|
||||||
|
private boolean reportGeneratedWithResponse = false;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public HttpResponse(
|
public HttpResponse(
|
||||||
@ -385,7 +390,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private HttpResponse reportRequestAndResponse(final boolean unconditionallyWithResponse) {
|
private HttpResponse reportRequestAndResponse(final boolean unconditionallyWithResponse) {
|
||||||
if (reported) {
|
if (reportGenerated) {
|
||||||
throw new IllegalStateException("request report already generated");
|
throw new IllegalStateException("request report already generated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,19 +414,30 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
testReport.printLine("=> status: " + status + " " + (locationUuid != null ? locationUuid : ""));
|
testReport.printLine("=> status: " + status + " " + (locationUuid != null ? locationUuid : ""));
|
||||||
if (unconditionallyWithResponse || httpMethod == HttpMethod.GET || status.isError()) {
|
if (unconditionallyWithResponse || httpMethod == HttpMethod.GET || status.isError()) {
|
||||||
testReport.printJson(response.body());
|
testReport.printJson(response.body());
|
||||||
|
this.reportGeneratedWithResponse = true;
|
||||||
}
|
}
|
||||||
testReport.printLine("```");
|
testReport.printLine("```");
|
||||||
testReport.printLine("");
|
testReport.printLine("");
|
||||||
|
this.reportGenerated = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private void optionallyReportRequestAndResponse() {
|
private void optionallyReportRequestAndResponse() {
|
||||||
if (!reported) {
|
if (!reportGenerated) {
|
||||||
reportRequestAndResponse(false);
|
reportRequestAndResponse(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyResponseReported(final String action) {
|
||||||
|
if (!reportGenerated) {
|
||||||
|
throw new IllegalStateException("report not generated yet, but expected for `" + action + "`");
|
||||||
|
}
|
||||||
|
if (!reportGeneratedWithResponse) {
|
||||||
|
throw new IllegalStateException("report without response, but response report required for `" + action + "`");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String nonNullAlias(final String alias) {
|
private String nonNullAlias(final String alias) {
|
||||||
// This marker tag should not appear in the source-code, as here is nothing to fix.
|
// This marker tag should not appear in the source-code, as here is nothing to fix.
|
||||||
// But if it appears in generated Markdown files, it should show up when that marker tag is searched.
|
// But if it appears in generated Markdown files, it should show up when that marker tag is searched.
|
||||||
@ -430,6 +446,8 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse extractUuidAlias(final String jsonPath, final String resolvableName) {
|
public HttpResponse extractUuidAlias(final String jsonPath, final String resolvableName) {
|
||||||
|
verifyResponseReported("extractUuidAlias");
|
||||||
|
|
||||||
final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS);
|
final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS);
|
||||||
final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenUUID();
|
final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenUUID();
|
||||||
ScenarioTest.putAlias(resolvedName, resolvedJsonPath);
|
ScenarioTest.putAlias(resolvedName, resolvedJsonPath);
|
||||||
@ -437,6 +455,8 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse extractValue(final String jsonPath, final String resolvableName) {
|
public HttpResponse extractValue(final String jsonPath, final String resolvableName) {
|
||||||
|
verifyResponseReported("extractValue");
|
||||||
|
|
||||||
final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS);
|
final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS);
|
||||||
final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenAsString();
|
final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenAsString();
|
||||||
ScenarioTest.putProperty(resolvedName, resolvedJsonPath);
|
ScenarioTest.putProperty(resolvedName, resolvedJsonPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user