feature/use-case-acceptance-tests #116

Merged
hsh-michaelhoennig merged 49 commits from feature/use-case-acceptance-tests into master 2024-10-30 11:40:46 +01:00
4 changed files with 46 additions and 24 deletions
Showing only changes of commit 36b0eb08b4 - Show all commits

View File

@ -66,6 +66,8 @@ class HsOfficeUseCasesTest extends UseCaseTest {
@Test @Test
@Order(2011) @Order(2011)
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
@Produces("Debitor: Billing GmbH")
void shouldCreateExternalDebitorForPartner() { void shouldCreateExternalDebitorForPartner() {
new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH") new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH")
.given("partnerPersonUuid", "%{Person: Test AG}") .given("partnerPersonUuid", "%{Person: Test AG}")
@ -84,6 +86,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
@Test @Test
@Order(2020) @Order(2020)
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
void shouldDeleteDebitor() { void shouldDeleteDebitor() {
new DeleteDebitor(this) new DeleteDebitor(this)
.given("partnerNumber", 31020) .given("partnerNumber", 31020)
@ -93,6 +96,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
@Test @Test
@Order(3000) @Order(3000)
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
void shouldCreateMembershipForPartner() { void shouldCreateMembershipForPartner() {
new CreateMembership(this).doRun(); new CreateMembership(this).doRun();
} }

View File

@ -46,7 +46,7 @@ public abstract class UseCase<T extends UseCase<?>> {
public void requires(final String alias) { public void requires(final String alias) {
assumeThat(UseCaseTest.containsAlias(alias)) assumeThat(UseCaseTest.containsAlias(alias))
.as("skipping because alias '" + alias + "' not found, maybe the other test failed?") .as("skipping because alias '" + alias + "' not found, @Produces(...) missing?")
.isTrue(); .isTrue();
log("depends on [" + alias + "](" + UseCaseTest.getAlias(alias).useCase().getSimpleName() + ".md)"); log("depends on [" + alias + "](" + UseCaseTest.getAlias(alias).useCase().getSimpleName() + ".md)");
} }

View File

@ -15,10 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter; 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.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -32,8 +32,8 @@ public abstract class UseCaseTest extends ContextBasedTest {
final static String RUN_AS_USER = "superuser-alex@hostsharing.net"; // TODO.test: use global:AGENT when implemented final static String RUN_AS_USER = "superuser-alex@hostsharing.net"; // TODO.test: use global:AGENT when implemented
@Getter // @Getter
public static TestInfo currentTestInfo; // public static TestInfo currentTestInfo;
@Getter @Getter
private PrintWriter markdownFile; private PrintWriter markdownFile;
@ -55,6 +55,26 @@ public abstract class UseCaseTest extends ContextBasedTest {
@SneakyThrows @SneakyThrows
@BeforeEach @BeforeEach
void init(final TestInfo testInfo) { void init(final TestInfo testInfo) {
createHostsharingPerson();
callPrerequisites(testInfo);
createTestLogMarkdownFile(testInfo);
}
@AfterEach
void cleanup() {
properties.clear();
markdownFile.close();
}
@SneakyThrows
void log(final String output) {
// for tests executed due to @Requires/@Produces there is no markdownFile yet
if (markdownFile != null) {
markdownFile.println(output);
}
}
private void createHostsharingPerson() {
jpaAttempt.transacted(() -> jpaAttempt.transacted(() ->
{ {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
@ -69,44 +89,32 @@ public abstract class UseCaseTest extends ContextBasedTest {
); );
} }
); );
}
callPrerequisites(testInfo); private void createTestLogMarkdownFile(final TestInfo testInfo) throws IOException {
final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow(); final var testMethodName = testInfo.getTestMethod().map(Method::getName).orElseThrow();
final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow(); final var testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow();
markdownFile = new PrintWriter(new FileWriter( testMethodOrder + "-" + testMethodName + ".md")); markdownFile = new PrintWriter(new FileWriter( testMethodOrder + "-" + testMethodName + ".md"));
log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2")); log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
currentTestInfo = testInfo; // FIXME: remove?
} }
private void callPrerequisites(final TestInfo testInfo) throws IllegalAccessException, InvocationTargetException { private void callPrerequisites(final TestInfo testInfo) throws IllegalAccessException, InvocationTargetException {
final var testMethodRequired = testInfo.getTestMethod().map(m -> m.getAnnotation(Requires.class).value()).orElse(null); final var testMethodRequired = testInfo.getTestMethod()
.map(m -> m.getAnnotation(Requires.class))
.map(Requires::value)
.orElse(null);
if (testMethodRequired != null) { if (testMethodRequired != null) {
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 testMethodProduct = producesAnnot.value();
if (testMethodProduct.equals(testMethodRequired)) if (testMethodProduct.equals(testMethodRequired))
testMethod.invoke(this); testMethod.invoke(this);
} }
} }
} }
} }
@AfterEach
void cleanup() {
properties.clear();
markdownFile.close();
}
@SneakyThrows
void log(final String output) {
if (markdownFile != null) {
markdownFile.println(output);
}
}
static boolean containsAlias(final String alias) { static boolean containsAlias(final String alias) {
return aliases.containsKey(alias); return aliases.containsKey(alias);
} }

View File

@ -21,6 +21,16 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
@Override @Override
protected HttpResponse run() { protected HttpResponse run() {
keep("BankAccount: Billing GmbH - refund bank account", () ->
httpPost("/api/hs/office/bankaccounts", usingJsonBody("""
{
"holder": "Billing GmbH - refund bank account",
"iban": "DE02120300000000202051",
"bic": "BYLADEM1001"
}
"""))
.expecting(CREATED).expecting(JSON)
);
keep("Contact: Billing GmbH - Test AG billing", () -> keep("Contact: Billing GmbH - Test AG billing", () ->
httpPost("/api/hs/office/contacts", usingJsonBody(""" httpPost("/api/hs/office/contacts", usingJsonBody("""
@ -48,7 +58,7 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
"vatCountryCode": ${vatCountryCode}, "vatCountryCode": ${vatCountryCode},
"vatBusiness": ${vatBusiness}, "vatBusiness": ${vatBusiness},
"vatReverseCharge": ${vatReverseCharge}, "vatReverseCharge": ${vatReverseCharge},
"refundBankAccountUuid": ${BankAccount: Test AG - refund bank account}, "refundBankAccountUuid": ${BankAccount: Billing GmbH - refund bank account},
"defaultPrefix": ${defaultPrefix} "defaultPrefix": ${defaultPrefix}
} }
""")) """))