encapsulate aliases+properties
This commit is contained in:
parent
4d29c4643b
commit
887ec588b6
@ -1,17 +1,13 @@
|
||||
package net.hostsharing.hsadminng.hs.office.usecases;
|
||||
|
||||
import com.tngtech.archunit.thirdparty.com.google.common.collect.Streams;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.collections4.map.LinkedMap;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -20,11 +16,7 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.nio.file.StandardOpenOption.APPEND;
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
@ -50,16 +42,16 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
|
||||
public final void requires(final String alias, final Function<String, UseCase<?>> useCaseFactory) {
|
||||
if ( !UseCaseTest.aliases.containsKey(alias) ) {
|
||||
if ( !UseCaseTest.containsAlias(alias) ) {
|
||||
requirements.put(alias, useCaseFactory);
|
||||
}
|
||||
}
|
||||
|
||||
public void requires(final String alias) {
|
||||
assumeThat(UseCaseTest.aliases.containsKey(alias))
|
||||
assumeThat(UseCaseTest.containsAlias(alias))
|
||||
.as("skipping because alias '" + alias + "' not found, maybe the other test failed?")
|
||||
.isTrue();
|
||||
log("depends on ["+alias+"]("+UseCaseTest.aliases.get(alias).useCase().getSimpleName()+".md)");
|
||||
log("depends on ["+alias+"]("+UseCaseTest.getAlias(alias).useCase().getSimpleName()+".md)");
|
||||
}
|
||||
|
||||
public final HttpResponse doRun() {
|
||||
@ -70,7 +62,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
protected abstract HttpResponse run();
|
||||
|
||||
public final UseCase<T> given(final String propName, final Object propValue) {
|
||||
UseCaseTest.properties.put(propName, propValue);
|
||||
UseCaseTest.putProperty(propName, propValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -105,7 +97,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
|
||||
public final UUID uuid(final String alias) {
|
||||
return UseCaseTest.aliases.get(alias).uuid();
|
||||
return UseCaseTest.getAlias(alias).uuid();
|
||||
}
|
||||
|
||||
static class JsonTemplate {
|
||||
@ -196,7 +188,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
|
||||
public void keep() {
|
||||
UseCaseTest.aliases.put(
|
||||
UseCaseTest.putAlias(
|
||||
nextTitle != null ? nextTitle : resultAlias,
|
||||
new UseCaseTest.Alias<>(UseCase.this.getClass(), locationUuid));
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
|
||||
record Alias<T extends UseCase<T>>(Class<T> useCase, UUID uuid) {}
|
||||
|
||||
final static Map<String, Alias<?>> aliases = new HashMap<>();
|
||||
final static Map<String, Object> properties = new HashMap<>();
|
||||
private final static Map<String, Alias<?>> aliases = new HashMap<>();
|
||||
private final static Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
@LocalServerPort
|
||||
Integer port;
|
||||
@ -81,6 +81,22 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
markdownFile.println(output);
|
||||
}
|
||||
|
||||
static boolean containsAlias(final String alias) {
|
||||
return aliases.containsKey(alias);
|
||||
}
|
||||
|
||||
static Alias<?> getAlias(final String alias) {
|
||||
return aliases.get(alias);
|
||||
}
|
||||
|
||||
static void putAlias(final String name, final Alias<?> value) {
|
||||
aliases.put(name, value);
|
||||
}
|
||||
|
||||
static void putProperty(final String name, final Object value) {
|
||||
properties.put(name, value);
|
||||
}
|
||||
|
||||
static Stream<Map.Entry<String,?>> knowVariables() {
|
||||
return Streams.concat(
|
||||
UseCaseTest.aliases.entrySet().stream().map(e -> Map.entry(e.getKey(), e.getValue().uuid())),
|
||||
|
Loading…
Reference in New Issue
Block a user