feature/add-scenario-test-for-deceased-partner-with-community-of-heirs #137
@ -21,7 +21,6 @@ import java.math.BigDecimal;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -50,19 +49,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
return Optional.of(currentTestMethodProduces.pop());
|
return Optional.of(currentTestMethodProduces.pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Alias<T extends UseCase<T>>(UUID uuid) {
|
private final static Map<String, UUID> aliases = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return Objects.toString(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasUuid() {
|
|
||||||
return uuid != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static Map<String, Alias<?>> aliases = new HashMap<>();
|
|
||||||
|
|
||||||
private final static Map<String, Object> properties = new HashMap<>();
|
private final static Map<String, Object> properties = new HashMap<>();
|
||||||
public final TestReport testReport = new TestReport(aliases);
|
public final TestReport testReport = new TestReport(aliases);
|
||||||
@ -116,11 +103,9 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
context.define("superuser-alex@hostsharing.net");
|
context.define("superuser-alex@hostsharing.net");
|
||||||
putAlias(
|
putAlias(
|
||||||
"Person: Hostsharing eG",
|
"Person: Hostsharing eG",
|
||||||
new Alias<>(
|
personRepo.findPersonByOptionalNameLike("Hostsharing eG").stream()
|
||||||
personRepo.findPersonByOptionalNameLike("Hostsharing eG")
|
|
||||||
.stream()
|
|
||||||
.map(HsOfficePersonRbacEntity::getUuid)
|
.map(HsOfficePersonRbacEntity::getUuid)
|
||||||
.reduce(Reducer::toSingleElement).orElseThrow())
|
.reduce(Reducer::toSingleElement).orElseThrow()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -212,7 +197,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void putAlias(final String name, final Alias<?> value) {
|
static void putAlias(final String name, final UUID value) {
|
||||||
aliases.put(name, value);
|
aliases.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +211,7 @@ public abstract class ScenarioTest extends ContextBasedTest {
|
|||||||
|
|
||||||
static Map<String, Object> knowVariables() {
|
static Map<String, Object> knowVariables() {
|
||||||
final var map = new LinkedHashMap<String, Object>();
|
final var map = new LinkedHashMap<String, Object>();
|
||||||
ScenarioTest.aliases.forEach((key, value) -> map.put(key, value.uuid()));
|
map.putAll(ScenarioTest.aliases);
|
||||||
map.putAll(ScenarioTest.properties);
|
map.putAll(ScenarioTest.properties);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
import net.hostsharing.hsadminng.config.JsonObjectMapperConfiguration;
|
||||||
import net.hostsharing.hsadminng.hs.scenarios.ScenarioTest.Alias;
|
|
||||||
import net.hostsharing.hsadminng.system.SystemProcess;
|
import net.hostsharing.hsadminng.system.SystemProcess;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
@ -19,6 +18,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static java.lang.String.join;
|
import static java.lang.String.join;
|
||||||
@ -32,7 +32,7 @@ public class TestReport {
|
|||||||
private static final File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md");
|
private static final File markdownLogFile = new File(BUILD_DOC_SCENARIOS, ".last-debug-log.md");
|
||||||
private static final ObjectMapper objectMapper = JsonObjectMapperConfiguration.build();
|
private static final ObjectMapper objectMapper = JsonObjectMapperConfiguration.build();
|
||||||
|
|
||||||
private final Map<String, Alias<?>> aliases;
|
private final Map<String, UUID> aliases;
|
||||||
private final PrintWriter markdownLog; // records everything for debugging purposes
|
private final PrintWriter markdownLog; // records everything for debugging purposes
|
||||||
private File markdownReportFile;
|
private File markdownReportFile;
|
||||||
private PrintWriter markdownReport; // records only the use-case under test, without its pre-requisites
|
private PrintWriter markdownReport; // records only the use-case under test, without its pre-requisites
|
||||||
@ -44,7 +44,7 @@ public class TestReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public TestReport(final Map<String, Alias<?>> aliases) {
|
public TestReport(final Map<String, UUID> aliases) {
|
||||||
this.aliases = aliases;
|
this.aliases = aliases;
|
||||||
this.markdownLog = new PrintWriter(new FileWriter(markdownLogFile));
|
this.markdownLog = new PrintWriter(new FileWriter(markdownLogFile));
|
||||||
}
|
}
|
||||||
@ -132,8 +132,8 @@ public class TestReport {
|
|||||||
final var result = new StringBuilder();
|
final var result = new StringBuilder();
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
for (Map.Entry<String, Alias<?>> entry : aliases.entrySet()) {
|
for (Map.Entry<String, UUID> entry : aliases.entrySet()) {
|
||||||
if (entry.getValue().hasUuid() && line.contains(entry.getValue().toString())) {
|
if ( entry.getValue() != null && line.contains(entry.getValue().toString())) {
|
||||||
line = line + " // " + entry.getKey();
|
line = line + " // " + entry.getKey();
|
||||||
break; // only add comment for one UUID per row (in our case, there is only one per row)
|
break; // only add comment for one UUID per row (in our case, there is only one per row)
|
||||||
}
|
}
|
||||||
|
@ -304,16 +304,12 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
assertThat(alias).as("cannot keep result, no alias found").isNotNull();
|
assertThat(alias).as("cannot keep result, no alias found").isNotNull();
|
||||||
|
|
||||||
final var value = extractor.apply(this);
|
final var value = extractor.apply(this);
|
||||||
ScenarioTest.putAlias(
|
ScenarioTest.putAlias(alias, UUID.fromString(value));
|
||||||
alias,
|
|
||||||
new ScenarioTest.Alias<>(UUID.fromString(value)));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpResponse keepAs(final String alias) {
|
public HttpResponse keepAs(final String alias) {
|
||||||
ScenarioTest.putAlias(
|
ScenarioTest.putAlias(nonNullAlias(alias), locationUuid);
|
||||||
nonNullAlias(alias),
|
|
||||||
new ScenarioTest.Alias<>(locationUuid));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user