add representative test
This commit is contained in:
parent
adfa95bf0e
commit
fe7b515b11
@ -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.debitor.DeleteDebitor;
|
||||
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.UnsubscribeFromMailinglist;
|
||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||
@ -44,6 +45,25 @@ class HsOfficeUseCasesTest extends UseCaseTest {
|
||||
|
||||
@Test
|
||||
@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() {
|
||||
new DeletePartner(this)
|
||||
.given("partnerNumber", 31020)
|
||||
|
@ -109,6 +109,7 @@ public class TemplateResolver {
|
||||
return switch (value) {
|
||||
case Boolean bool -> bool.toString();
|
||||
case Number number -> number.toString();
|
||||
case String string -> "\"" + string.replace("\n", "\\n") + "\"";
|
||||
default -> "\"" + value + "\"";
|
||||
};
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
this.testSuite = testSuite;
|
||||
this.resultAlias = resultAlias;
|
||||
if (resultAlias != null) {
|
||||
log("### UseCase " + resultAlias);
|
||||
log("");
|
||||
printLine("### UseCase: " + resultAlias);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,13 +50,13 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
|
||||
public final HttpResponse doRun() {
|
||||
log("### Given Properties\n");
|
||||
log("""
|
||||
printLine("### Given Properties");
|
||||
printLine("""
|
||||
| name | value |
|
||||
|------|-------|
|
||||
""".trim());
|
||||
givenProperties.forEach((key, value) -> log("| " + key + " | " + value + " |"));
|
||||
log("");
|
||||
givenProperties.forEach((key, value) -> printLine("| " + key + " | " + value.toString().replace("\n", "<br>") + " |"));
|
||||
printLine("");
|
||||
requirements.forEach((alias, factory) -> factory.apply(alias).run().keep());
|
||||
|
||||
// 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) {
|
||||
log("\n### " + nextTitle + "\n");
|
||||
print("\n### " + nextTitle + "\n");
|
||||
} else if (resultAlias != null) {
|
||||
log("\n### " + resultAlias + "\n");
|
||||
print("\n### " + resultAlias + "\n");
|
||||
}
|
||||
log("```");
|
||||
log(httpMethod.name() + " " + uri);
|
||||
log(requestBody + "=> status: " + status + " " +
|
||||
print("```");
|
||||
print(httpMethod.name() + " " + uri);
|
||||
print(requestBody + "=> status: " + status + " " +
|
||||
(locationUuid != null ? locationUuid : ""));
|
||||
if (!status.is2xxSuccessful()) {
|
||||
log(response.getBody().prettyPrint());
|
||||
print(response.getBody().prettyPrint());
|
||||
}
|
||||
log("```");
|
||||
log("");
|
||||
print("```");
|
||||
print("");
|
||||
}
|
||||
|
||||
public HttpResponse expecting(final HttpStatus httpStatus) {
|
||||
@ -187,8 +186,16 @@ public abstract class UseCase<T extends UseCase<?>> {
|
||||
}
|
||||
}
|
||||
|
||||
void log(final String output) {
|
||||
testSuite.log(output);
|
||||
public void print(final String 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() {
|
||||
|
@ -72,13 +72,21 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
void log(final String output) {
|
||||
void print(final String output) {
|
||||
// for tests executed due to @Requires/@Produces there is no markdownFile yet
|
||||
if (markdownFile != null) {
|
||||
markdownFile.println(output);
|
||||
}
|
||||
}
|
||||
|
||||
void printLine(final String output) {
|
||||
print(output + "\n");
|
||||
}
|
||||
|
||||
void printPara(final String output) {
|
||||
printLine("\n" +output + "\n");
|
||||
}
|
||||
|
||||
private void createHostsharingPerson() {
|
||||
jpaAttempt.transacted(() ->
|
||||
{
|
||||
@ -100,7 +108,7 @@ public abstract class UseCaseTest extends ContextBasedTest {
|
||||
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"));
|
||||
print("## Testcase: " + testMethodName.replaceAll("([a-z])([A-Z]+)", "$1 $2"));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user