feature/use-case-acceptance-tests #116
@ -66,6 +66,8 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
||||
|
||||
@Test
|
||||
@Order(2011)
|
||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
||||
@Produces("Debitor: Billing GmbH")
|
||||
void shouldCreateExternalDebitorForPartner() {
|
||||
new CreateExternalDebitorForPartner(this, "Debitor: Billing GmbH")
|
||||
.given("partnerPersonUuid", "%{Person: Test AG}")
|
||||
@ -84,6 +86,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
||||
|
||||
@Test
|
||||
@Order(2020)
|
||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
||||
void shouldDeleteDebitor() {
|
||||
new DeleteDebitor(this)
|
||||
.given("partnerNumber", 31020)
|
||||
@ -93,6 +96,7 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
||||
|
||||
@Test
|
||||
@Order(3000)
|
||||
@Requires("Partner: Test AG") // FIXME: eigentlich "Person: Test AG"
|
||||
void shouldCreateMembershipForPartner() {
|
||||
new CreateMembership(this).doRun();
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
|
||||
public void requires(final String 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();
|
||||
log("depends on [" + alias + "](" + UseCaseTest.getAlias(alias).useCase().getSimpleName() + ".md)");
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
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
|
||||
|
||||
@Getter
|
||||
public static TestInfo currentTestInfo;
|
||||
// @Getter
|
||||
// public static TestInfo currentTestInfo;
|
||||
|
||||
@Getter
|
||||
private PrintWriter markdownFile;
|
||||
@ -55,6 +55,26 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
@SneakyThrows
|
||||
@BeforeEach
|
||||
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(() ->
|
||||
{
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
@ -69,19 +89,20 @@ 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 testMethodOrder = testInfo.getTestMethod().map(m -> m.getAnnotation(Order.class).value()).orElseThrow();
|
||||
markdownFile = new PrintWriter(new FileWriter( testMethodOrder + "-" + testMethodName + ".md"));
|
||||
log("## Testcase " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
||||
|
||||
currentTestInfo = testInfo; // FIXME: remove?
|
||||
}
|
||||
|
||||
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) {
|
||||
for (Method testMethod : getClass().getDeclaredMethods()) {
|
||||
final var producesAnnot = testMethod.getAnnotation(Produces.class);
|
||||
@ -94,19 +115,6 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
return aliases.containsKey(alias);
|
||||
}
|
||||
|
@ -21,6 +21,16 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
|
||||
|
||||
@Override
|
||||
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", () ->
|
||||
httpPost("/api/hs/office/contacts", usingJsonBody("""
|
||||
@ -48,7 +58,7 @@ public class CreateExternalDebitorForPartner extends UseCase<CreateExternalDebit
|
||||
"vatCountryCode": ${vatCountryCode},
|
||||
"vatBusiness": ${vatBusiness},
|
||||
"vatReverseCharge": ${vatReverseCharge},
|
||||
"refundBankAccountUuid": ${BankAccount: Test AG - refund bank account},
|
||||
"refundBankAccountUuid": ${BankAccount: Billing GmbH - refund bank account},
|
||||
"defaultPrefix": ${defaultPrefix}
|
||||
}
|
||||
"""))
|
||||
|
Loading…
Reference in New Issue
Block a user