extract feaure for obtain

This commit is contained in:
Michael Hoennig 2024-12-17 10:20:48 +01:00
parent 1623e72534
commit 2971f4196d
4 changed files with 27 additions and 17 deletions

View File

@ -90,7 +90,9 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
}
"""))
.expecting(CREATED).expecting(JSON)
);
)
.extract("contact.uuid", "Contact: Erbengemeinschaft %{nameOfDeceasedPerson}")
.extract("holder.uuid", "Person: Erbengemeinschaft %{nameOfDeceasedPerson}");
// Repräsentanten Relation zur Erbengemeinschaft für die zuvor erzeugte Person zur Erbengemeinschaft anlegen
@ -108,17 +110,17 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
// "If there are more than one, each needs their own contact"
// );
obtain("Representative-Relation: %{subscriberGivenName} %{subscriberFamilyName} for Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
obtain("Representative-Relation: %{representativeGivenName} %{representativeFamilyName} for Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
httpPost("/api/hs/office/relations", usingJsonBody("""
{
"type": "REPRESENTATIVE",
"anchor.uuid": ${Person: %{partnerPersonTradeName}},
"holder.uuid": {
"anchor.uuid": ${Person: Erbengemeinschaft %{nameOfDeceasedPerson}},
"holder": {
"personType": "NATURAL_PERSON",
"givenName": ${representativeGivenName},
"familyName": ${representativeFamilyName}
},
"contact.uuid": ${Contact: %{subscriberGivenName} %{subscriberFamilyName}}
"contact.uuid": ${Contact: Erbengemeinschaft %{nameOfDeceasedPerson}}
}
"""))
.expecting(CREATED).expecting(JSON),
@ -137,12 +139,10 @@ public class ReplaceDeceasedPartnerWithCommunityOfHeirs extends UseCase<ReplaceD
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
);
// httpGet("/api/hs/office/debitors/%{partnerNumber}") FIXME
obtain("Partner: Erbengemeinschaft %{nameOfDeceasedPerson}", () ->
httpPatch("/api/hs/office/partners/%{Partner: %{partnerNumber}}", usingJsonBody("""
{
"partnerRel": ${Partner-Relation: Erbengemeinschaft %{nameOfDeceasedPerson}}
"partnerRel.uuid": ${Partner-Relation: Erbengemeinschaft %{nameOfDeceasedPerson}}
}
"""))
.expecting(HttpStatus.OK)

View File

@ -50,13 +50,16 @@ public abstract class ScenarioTest extends ContextBasedTest {
return Optional.of(currentTestMethodProduces.pop());
}
record Alias<T extends UseCase<T>>(Class<T> useCase, UUID uuid) {
public record Alias<T extends UseCase<T>>(Class<T> useCase, UUID uuid) {
@Override
public String toString() {
return Objects.toString(uuid);
}
public boolean hasUuid() {
return uuid != null;
}
}
private final static Map<String, Alias<?>> aliases = new HashMap<>();
@ -111,7 +114,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
jpaAttempt.transacted(() ->
{
context.define("superuser-alex@hostsharing.net");
aliases.put(
putAlias(
"Person: Hostsharing eG",
new Alias<>(
null,

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.Alias;
import net.hostsharing.hsadminng.system.SystemProcess;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Order;
@ -31,7 +32,7 @@ public class TestReport {
private static final File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md");
private static final ObjectMapper objectMapper = JsonObjectMapperConfiguration.build();
private final Map<String, ?> aliases;
private final Map<String, Alias<?>> aliases;
private final PrintWriter markdownLog; // records everything for debugging purposes
private File markdownReportFile;
private PrintWriter markdownReport; // records only the use-case under test, without its pre-requisites
@ -43,7 +44,7 @@ public class TestReport {
}
@SneakyThrows
public TestReport(final Map<String, ?> aliases) {
public TestReport(final Map<String, Alias<?>> aliases) {
this.aliases = aliases;
this.markdownLog = new PrintWriter(new FileWriter(markdownLogFile));
}
@ -131,9 +132,8 @@ public class TestReport {
final var result = new StringBuilder();
for (String line : lines) {
for (Map.Entry<String, ?> entry : aliases.entrySet()) {
final var uuidString = entry.getValue().toString();
if (line.contains(uuidString)) {
for (Map.Entry<String, Alias<?>> entry : aliases.entrySet()) {
if (entry.getValue().hasUuid() && line.contains(entry.getValue().toString())) {
line = line + " // " + entry.getKey();
break; // only add comment for one UUID per row (in our case, there is only one per row)
}

View File

@ -134,8 +134,8 @@ public abstract class UseCase<T extends UseCase<?>> {
});
}
public final void obtain(final String alias, final Supplier<HttpResponse> http, final String... extraInfo) {
withTitle(alias, () -> {
public final HttpResponse obtain(final String alias, final Supplier<HttpResponse> http, final String... extraInfo) {
return withTitle(alias, () -> {
final var response = http.get().keep();
Arrays.stream(extraInfo).forEach(testReport::printPara);
return response;
@ -396,6 +396,13 @@ public abstract class UseCase<T extends UseCase<?>> {
final var onlyVisibleInGeneratedMarkdownNotInSource = new String(new char[]{'F', 'I', 'X', 'M', 'E'});
return alias == null ? "unknown alias -- " + onlyVisibleInGeneratedMarkdownNotInSource : alias;
}
public HttpResponse extract(final String jsonPath, final String resolvableName) {
final var resolvedName = ScenarioTest.resolve(resolvableName, DROP_COMMENTS);
final var resolvedJsonPath = getFromBodyAsOptional(jsonPath).givenAsString();
ScenarioTest.putProperty(resolvedName, resolvedJsonPath);
return this;
}
}
protected T self() {