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
5 changed files with 113 additions and 18 deletions
Showing only changes of commit fe7b515b11 - Show all commits

View File

@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.hs.office.usecases.membership.CreateMembership;
import net.hostsharing.hsadminng.hs.office.usecases.partner.CreatePartner; import net.hostsharing.hsadminng.hs.office.usecases.partner.CreatePartner;
import net.hostsharing.hsadminng.hs.office.usecases.debitor.DeleteDebitor; import net.hostsharing.hsadminng.hs.office.usecases.debitor.DeleteDebitor;
import net.hostsharing.hsadminng.hs.office.usecases.partner.DeletePartner; import net.hostsharing.hsadminng.hs.office.usecases.partner.DeletePartner;
import net.hostsharing.hsadminng.hs.office.usecases.subscription.AddRepresentativeToPartner;
import net.hostsharing.hsadminng.hs.office.usecases.subscription.SubscribeToMailinglist; import net.hostsharing.hsadminng.hs.office.usecases.subscription.SubscribeToMailinglist;
import net.hostsharing.hsadminng.hs.office.usecases.subscription.UnsubscribeFromMailinglist; import net.hostsharing.hsadminng.hs.office.usecases.subscription.UnsubscribeFromMailinglist;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt; import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
@ -44,6 +45,25 @@ class HsOfficeUseCasesTest extends UseCaseTest {
@Test @Test
@Order(1020) @Order(1020)
@Requires("Person: Test AG")
@Produces("Representative: Tracy Trust for Test AG")
void shouldAddRepresentativeToPartner() {
new AddRepresentativeToPartner(this)
.given("partnerPersonUuid", "%{Person: Test AG}")
.given("representativeFamilyName", "Tracy")
.given("representativeGivenName", "Trust")
.given("representativePostalAddress", """
An der Alster 100
20000 Hamburg
""")
.given("representativePhoneNumber", "+49 40 123456")
.given("representativeEMailAddress", "tracy.trust@example.org")
.doRun()
.keep();
}
@Test
@Order(1090)
void shouldDeletePartner() { void shouldDeletePartner() {
new DeletePartner(this) new DeletePartner(this)
.given("partnerNumber", 31020) .given("partnerNumber", 31020)

View File

@ -109,6 +109,7 @@ public class TemplateResolver {
return switch (value) { return switch (value) {
case Boolean bool -> bool.toString(); case Boolean bool -> bool.toString();
case Number number -> number.toString(); case Number number -> number.toString();
case String string -> "\"" + string.replace("\n", "\\n") + "\"";
default -> "\"" + value + "\""; default -> "\"" + value + "\"";
}; };
} }

View File

@ -39,8 +39,7 @@ public abstract class UseCase<T extends UseCase<?>> {
this.testSuite = testSuite; this.testSuite = testSuite;
this.resultAlias = resultAlias; this.resultAlias = resultAlias;
if (resultAlias != null) { if (resultAlias != null) {
log("### UseCase " + resultAlias); printLine("### UseCase: " + resultAlias);
log("");
} }
} }
@ -51,13 +50,13 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
public final HttpResponse doRun() { public final HttpResponse doRun() {
log("### Given Properties\n"); printLine("### Given Properties");
log(""" printLine("""
| name | value | | name | value |
|------|-------| |------|-------|
""".trim()); """.trim());
givenProperties.forEach((key, value) -> log("| " + key + " | " + value + " |")); givenProperties.forEach((key, value) -> printLine("| " + key + " | " + value.toString().replace("\n", "<br>") + " |"));
log(""); printLine("");
requirements.forEach((alias, factory) -> factory.apply(alias).run().keep()); requirements.forEach((alias, factory) -> factory.apply(alias).run().keep());
// final var testMethodProduct = testInfo.getTestMethod().map(m -> m.getAnnotation(Produces.class).value()).orElseThrow(); // final var testMethodProduct = testInfo.getTestMethod().map(m -> m.getAnnotation(Produces.class).value()).orElseThrow();
@ -153,19 +152,19 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
if (nextTitle != null) { if (nextTitle != null) {
log("\n### " + nextTitle + "\n"); print("\n### " + nextTitle + "\n");
} else if (resultAlias != null) { } else if (resultAlias != null) {
log("\n### " + resultAlias + "\n"); print("\n### " + resultAlias + "\n");
} }
log("```"); print("```");
log(httpMethod.name() + " " + uri); print(httpMethod.name() + " " + uri);
log(requestBody + "=> status: " + status + " " + print(requestBody + "=> status: " + status + " " +
(locationUuid != null ? locationUuid : "")); (locationUuid != null ? locationUuid : ""));
if (!status.is2xxSuccessful()) { if (!status.is2xxSuccessful()) {
log(response.getBody().prettyPrint()); print(response.getBody().prettyPrint());
} }
log("```"); print("```");
log(""); print("");
} }
public HttpResponse expecting(final HttpStatus httpStatus) { public HttpResponse expecting(final HttpStatus httpStatus) {
@ -187,8 +186,16 @@ public abstract class UseCase<T extends UseCase<?>> {
} }
} }
void log(final String output) { public void print(final String output) {
testSuite.log(output); testSuite.print(output);
}
public void printLine(final String output) {
testSuite.printLine(output);
}
public void printPara(final String output) {
testSuite.printPara(output);
} }
protected T self() { protected T self() {

View File

@ -72,13 +72,21 @@ public abstract class UseCaseTest extends ContextBasedTest {
} }
@SneakyThrows @SneakyThrows
void log(final String output) { void print(final String output) {
// for tests executed due to @Requires/@Produces there is no markdownFile yet // for tests executed due to @Requires/@Produces there is no markdownFile yet
if (markdownFile != null) { if (markdownFile != null) {
markdownFile.println(output); markdownFile.println(output);
} }
} }
void printLine(final String output) {
print(output + "\n");
}
void printPara(final String output) {
printLine("\n" +output + "\n");
}
private void createHostsharingPerson() { private void createHostsharingPerson() {
jpaAttempt.transacted(() -> jpaAttempt.transacted(() ->
{ {
@ -100,7 +108,7 @@ public abstract class UseCaseTest extends ContextBasedTest {
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")); print("## Testcase: " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
} }
@SneakyThrows @SneakyThrows

View File

@ -0,0 +1,59 @@
package net.hostsharing.hsadminng.hs.office.usecases.subscription;
import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.hs.office.usecases.UseCase;
import net.hostsharing.hsadminng.hs.office.usecases.UseCaseTest;
import org.springframework.http.HttpStatus;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.CREATED;
public class AddRepresentativeToPartner extends UseCase<AddRepresentativeToPartner> {
public AddRepresentativeToPartner(final UseCaseTest testSuite) {
super(testSuite);
}
@Override
protected HttpResponse run() {
keep("Person: %{representativeGivenName} %{representativeFamilyName}", () ->
httpPost("/api/hs/office/persons", usingJsonBody("""
{
"personType": "NATURAL_PERSON",
"familyName": ${representativeFamilyName},
"givenName": ${representativeGivenName}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
);
printPara("Please check first if that person already exists, if so, use it's UUID below.");
print("**HINT**: A representative is always a natural person and represents a non-natural-person.");
keep("Contact: %{representativeGivenName} %{representativeFamilyName}", () ->
httpPost("/api/hs/office/contacts", usingJsonBody("""
{
"caption": "%{representativeGivenName} %{representativeFamilyName}",
"postalAddress": ${representativePostalAddress},
"phoneNumbers": {
"main": ${representativePhoneNumber}
},
"emailAddresses": {
"main": ${representativeEMailAddress}
}
}
"""))
.expecting(CREATED).expecting(JSON)
);
printPara("Please check first if that contact already exists, if so, use it's UUID below.");
return httpPost("/api/hs/office/relations", usingJsonBody("""
{
"type": "REPRESENTATIVE",
"anchorUuid": ${partnerPersonUuid},
"holderUuid": ${Person: %{representativeGivenName} %{representativeFamilyName}},
"contactUuid": ${Contact: %{representativeGivenName} %{representativeFamilyName}}
}
"""))
.expecting(CREATED).expecting(JSON);
}
}