Compare commits
2 Commits
36b0eb08b4
...
876b3c526e
Author | SHA1 | Date | |
---|---|---|---|
|
876b3c526e | ||
|
794d2f46dc |
@ -25,14 +25,14 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1010)
|
@Order(1010)
|
||||||
@Produces("Partner: Test AG")
|
@Produces(explicitly = "Partner: Test AG", implicitly = "Person: Test AG")
|
||||||
void shouldCreatePartner() {
|
void shouldCreatePartner() {
|
||||||
new CreatePartner(this, "Partner: Test AG")
|
new CreatePartner(this, "Partner: Test AG")
|
||||||
.given("partnerNumber", 30001)
|
.given("partnerNumber", 31010)
|
||||||
.given("personType", "LEGAL_PERSON")
|
.given("personType", "LEGAL_PERSON")
|
||||||
.given("tradeName", "Test AG")
|
.given("tradeName", "Test AG")
|
||||||
.given("contactCaption", "Test AG - Bord of Directors")
|
.given("contactCaption", "Test AG - Board of Directors")
|
||||||
.given("emailAddress", "bord-of-directors@test-ag.example.org")
|
.given("emailAddress", "board-of-directors@test-ag.example.org")
|
||||||
.doRun()
|
.doRun()
|
||||||
.keep();
|
.keep();
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2011)
|
@Order(2011)
|
||||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
@Requires("Person: Test AG")
|
||||||
@Produces("Debitor: Billing GmbH")
|
@Produces("Debitor: Billing GmbH")
|
||||||
void shouldCreateExternalDebitorForPartner() {
|
void shouldCreateExternalDebitorForPartner() {
|
||||||
new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH")
|
new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH")
|
||||||
@ -86,7 +86,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2020)
|
@Order(2020)
|
||||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
@Requires("Person: Test AG")
|
||||||
void shouldDeleteDebitor() {
|
void shouldDeleteDebitor() {
|
||||||
new DeleteDebitor(this)
|
new DeleteDebitor(this)
|
||||||
.given("partnerNumber", 31020)
|
.given("partnerNumber", 31020)
|
||||||
@ -96,8 +96,13 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3000)
|
@Order(3000)
|
||||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
@Requires("Partner: Test AG")
|
||||||
void shouldCreateMembershipForPartner() {
|
void shouldCreateMembershipForPartner() {
|
||||||
new CreateMembership(this).doRun();
|
new CreateMembership(this)
|
||||||
|
.given("partnerName", "Test AG")
|
||||||
|
.given("memberNumberSuffix", "00")
|
||||||
|
.given("validFrom", "2024-10-15")
|
||||||
|
.given("membershipFeeBillable", "true")
|
||||||
|
.doRun();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,12 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
import static java.lang.annotation.ElementType.METHOD;
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
import static java.lang.annotation.RetentionPolicy.CLASS;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
@Target(METHOD)
|
@Target(METHOD)
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface Produces {
|
public @interface Produces {
|
||||||
String value();
|
String value() default ""; // same as explicitly, makes it possible to omit the property name
|
||||||
|
String explicitly() default ""; // same as value
|
||||||
|
String[] implicitly() default {};
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import java.util.UUID;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
|
||||||
import static org.hamcrest.Matchers.startsWith;
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
|
|
||||||
public abstract class UseCase<T extends UseCase<?>> {
|
public abstract class UseCase<T extends UseCase<?>> {
|
||||||
@ -44,13 +43,6 @@ public abstract class UseCase<T extends UseCase<?>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requires(final String alias) {
|
|
||||||
assumeThat(UseCaseTest.containsAlias(alias))
|
|
||||||
.as("skipping because alias '" + alias + "' not found, @Produces(...) missing?")
|
|
||||||
.isTrue();
|
|
||||||
log("depends on [" + alias + "](" + UseCaseTest.getAlias(alias).useCase().getSimpleName() + ".md)");
|
|
||||||
}
|
|
||||||
|
|
||||||
public final HttpResponse doRun() {
|
public final HttpResponse doRun() {
|
||||||
log("### Given Properties\n");
|
log("### Given Properties\n");
|
||||||
log("""
|
log("""
|
||||||
|
@ -7,6 +7,8 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
|
|||||||
import net.hostsharing.hsadminng.lambda.Reducer;
|
import net.hostsharing.hsadminng.lambda.Reducer;
|
||||||
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
|
||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
|
import org.apache.commons.collections4.SetUtils;
|
||||||
|
import org.hibernate.AssertionFailure;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Order;
|
import org.junit.jupiter.api.Order;
|
||||||
@ -20,12 +22,14 @@ import java.io.PrintWriter;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.Arrays.stream;
|
import static java.util.Arrays.asList;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public abstract class UseCaseTest extends ContextBasedTest {
|
public abstract class UseCaseTest extends ContextBasedTest {
|
||||||
@ -56,7 +60,7 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
void init(final TestInfo testInfo) {
|
void init(final TestInfo testInfo) {
|
||||||
createHostsharingPerson();
|
createHostsharingPerson();
|
||||||
callPrerequisites(testInfo);
|
callRequiredProducers(testInfo);
|
||||||
createTestLogMarkdownFile(testInfo);
|
createTestLogMarkdownFile(testInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +102,7 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callPrerequisites(final TestInfo testInfo) throws IllegalAccessException, InvocationTargetException {
|
private void callRequiredProducers(final TestInfo testInfo) throws IllegalAccessException, InvocationTargetException {
|
||||||
final var testMethodRequired = testInfo.getTestMethod()
|
final var testMethodRequired = testInfo.getTestMethod()
|
||||||
.map(m -> m.getAnnotation(Requires.class))
|
.map(m -> m.getAnnotation(Requires.class))
|
||||||
.map(Requires::value)
|
.map(Requires::value)
|
||||||
@ -107,12 +111,48 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
|||||||
for (Method testMethod : getClass().getDeclaredMethods()) {
|
for (Method testMethod : getClass().getDeclaredMethods()) {
|
||||||
final var producesAnnot = testMethod.getAnnotation(Produces.class);
|
final var producesAnnot = testMethod.getAnnotation(Produces.class);
|
||||||
if (producesAnnot != null) {
|
if (producesAnnot != null) {
|
||||||
final var testMethodProduct = producesAnnot.value();
|
final var testMethodProduces = allOf(producesAnnot.value(), producesAnnot.explicitly(), producesAnnot.implicitly());
|
||||||
if (testMethodProduct.equals(testMethodRequired))
|
if ( // that method can produce something required
|
||||||
|
testMethodProduces.contains(testMethodRequired) &&
|
||||||
|
|
||||||
|
// and it does not produce anything we already have (would cause errors)
|
||||||
|
SetUtils.intersection(testMethodProduces, knowVariables().keySet()).isEmpty())
|
||||||
|
|
||||||
|
// then we call the producer method
|
||||||
testMethod.invoke(this);
|
testMethod.invoke(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// public void requires(final String alias) {
|
||||||
|
// assumeThat(UseCaseTest.containsAlias(alias))
|
||||||
|
// .as("skipping because alias '" + alias + "' not found, @Produces(...) missing?")
|
||||||
|
// .isTrue();
|
||||||
|
// log("depends on [" + alias + "](" + UseCaseTest.getAlias(alias).useCase().getSimpleName() + ".md)");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> allOf(final String value, final String explicitly, final String[] implicitly) {
|
||||||
|
final var all = new HashSet<String>();
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
all.add(value);
|
||||||
|
}
|
||||||
|
if (!explicitly.isEmpty()) {
|
||||||
|
all.add(explicitly);
|
||||||
|
}
|
||||||
|
all.addAll(asList(implicitly));
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String oneOf(final String one, final String another) {
|
||||||
|
if (one != null && another == null) {
|
||||||
|
return one;
|
||||||
|
} else if (one == null && another != null) {
|
||||||
|
return another;
|
||||||
|
}
|
||||||
|
throw new AssertionFailure("excactly one value required");
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean containsAlias(final String alias) {
|
static boolean containsAlias(final String alias) {
|
||||||
|
@ -12,7 +12,6 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
|
|||||||
public CreateExternalDebitorForPartner(final UseCaseTest testSuite, final String resultAlias) {
|
public CreateExternalDebitorForPartner(final UseCaseTest testSuite, final String resultAlias) {
|
||||||
super(testSuite, resultAlias);
|
super(testSuite, resultAlias);
|
||||||
|
|
||||||
requires("Person: Test AG");
|
|
||||||
requires("Person: Billing GmbH", alias -> new CreatePerson(testSuite, alias)
|
requires("Person: Billing GmbH", alias -> new CreatePerson(testSuite, alias)
|
||||||
.given("personType", "LEGAL_PERSON")
|
.given("personType", "LEGAL_PERSON")
|
||||||
.given("tradeName", "Billing GmbH")
|
.given("tradeName", "Billing GmbH")
|
||||||
|
@ -10,8 +10,6 @@ public class CreateSelfDebitorForPartner extends UseCase<CreateSelfDebitorForPar
|
|||||||
|
|
||||||
public CreateSelfDebitorForPartner(final UseCaseTest testSuite, final String resultAlias) {
|
public CreateSelfDebitorForPartner(final UseCaseTest testSuite, final String resultAlias) {
|
||||||
super(testSuite, resultAlias);
|
super(testSuite, resultAlias);
|
||||||
|
|
||||||
requires("Person: Test AG");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,19 +9,17 @@ public class CreateMembership extends UseCase<CreateMembership> {
|
|||||||
|
|
||||||
public CreateMembership(final UseCaseTest testSuite) {
|
public CreateMembership(final UseCaseTest testSuite) {
|
||||||
super(testSuite);
|
super(testSuite);
|
||||||
|
|
||||||
requires("Partner: Test AG");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HttpResponse run() {
|
protected HttpResponse run() {
|
||||||
keep("Membership: Test AG 00", () ->
|
keep("Membership: %{partnerName} 00", () ->
|
||||||
httpPost("/api/hs/office/memberships", usingJsonBody("""
|
httpPost("/api/hs/office/memberships", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"partnerUuid": ${Partner: Test AG},
|
"partnerUuid": ${Partner: Test AG},
|
||||||
"memberNumberSuffix": "00",
|
"memberNumberSuffix": ${memberNumberSuffix},
|
||||||
"validFrom": "2024-10-15",
|
"validFrom": ${validFrom},
|
||||||
"membershipFeeBillable": "true"
|
"membershipFeeBillable": ${membershipFeeBillable}
|
||||||
}
|
}
|
||||||
"""))
|
"""))
|
||||||
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
||||||
|
@ -24,7 +24,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
|
|||||||
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
|
||||||
);
|
);
|
||||||
|
|
||||||
keep("Contact: %{tradeName} - Bord of Directors", () ->
|
keep("Contact: %{tradeName} - Board of Directors", () ->
|
||||||
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
||||||
{
|
{
|
||||||
"caption": ${contactCaption},
|
"caption": ${contactCaption},
|
||||||
@ -42,7 +42,7 @@ public class CreatePartner extends UseCase<CreatePartner> {
|
|||||||
"partnerRel": {
|
"partnerRel": {
|
||||||
"anchorUuid": ${Person: Hostsharing eG},
|
"anchorUuid": ${Person: Hostsharing eG},
|
||||||
"holderUuid": ${Person: %{tradeName}},
|
"holderUuid": ${Person: %{tradeName}},
|
||||||
"contactUuid": ${Contact: %{tradeName} - Bord of Directors}
|
"contactUuid": ${Contact: %{tradeName} - Board of Directors}
|
||||||
},
|
},
|
||||||
"details": {
|
"details": {
|
||||||
"registrationOffice": "Registergericht Hamburg",
|
"registrationOffice": "Registergericht Hamburg",
|
||||||
|
@ -12,8 +12,8 @@ public class DeletePartner extends UseCase<DeletePartner> {
|
|||||||
requires("Partner: Delete AG", alias -> new CreatePartner(testSuite, alias)
|
requires("Partner: Delete AG", alias -> new CreatePartner(testSuite, alias)
|
||||||
.given("personType", "LEGAL_PERSON")
|
.given("personType", "LEGAL_PERSON")
|
||||||
.given("tradeName", "Delete AG")
|
.given("tradeName", "Delete AG")
|
||||||
.given("contactCaption", "Delete AG - Bord of Directors")
|
.given("contactCaption", "Delete AG - Board of Directors")
|
||||||
.given("emailAddress", "bord-of-directors@delete-ag.example.org"));
|
.given("emailAddress", "board-of-directors@delete-ag.example.org"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user