Compare commits

..

No commits in common. "2b21c742f03906046b8e08f39f523920448d8cf1" and "963bf89841256ac4c91037a4342a09f5a5fd97e1" have entirely different histories.

8 changed files with 50 additions and 151 deletions

View File

@ -112,7 +112,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
}
},
"debitorNumber": 1000111,
"debitorNumberSuffix": "11",
"debitorNumberSuffix": 11,
"partner": {
"partnerNumber": 10001,
"partnerRel": {
@ -167,7 +167,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
}
},
"debitorNumber": 1000212,
"debitorNumberSuffix": "12",
"debitorNumberSuffix": 12,
"partner": {
"partnerNumber": 10002,
"partnerRel": {
@ -201,7 +201,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
}
},
"debitorNumber": 1000313,
"debitorNumberSuffix": "13",
"debitorNumberSuffix": 13,
"partner": {
"partnerNumber": 10003,
"partnerRel": {
@ -469,7 +469,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
}
},
"debitorNumber": 1000111,
"debitorNumberSuffix": "11",
"debitorNumberSuffix": 11,
"partner": {
"partnerNumber": 10001,
"partnerRel": {
@ -581,7 +581,7 @@ class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanu
"contact": { "caption": "fourth contact" }
},
"debitorNumber": 10004${debitorNumberSuffix},
"debitorNumberSuffix": "${debitorNumberSuffix}",
"debitorNumberSuffix": ${debitorNumberSuffix},
"partner": {
"partnerNumber": 10004,
"partnerRel": {

View File

@ -1,29 +1,28 @@
package net.hostsharing.hsadminng.hs.office.usecases;
import static io.restassured.http.ContentType.JSON;
import static org.springframework.http.HttpStatus.CREATED;
import org.springframework.http.HttpStatus;
import static io.restassured.http.Method.POST;
class HsOfficeDebitorUseCase extends UseCase {
public HsOfficeDebitorUseCase(final UseCaseTest testSuite) {
super(testSuite);
requires("person:Test AG.uuid", () -> new HsOfficeCreatePartnerUseCase(testSuite));
}
@Override
HttpResponse run() {
httpPost("/api/hs/office/bankaccounts", usingJsonBody("""
void shouldCreateSelfDebitorForPartner() {
http(POST, "/api/hs/office/bankaccounts", usingJsonBody("""
{
"holder": "Test AG - refund bank account",
"iban": "DE88100900001234567892",
"bic": "BEVODEBB"
}
"""))
.expecting(CREATED).expecting(JSON)
.expecting(HttpStatus.CREATED)
.keepingAs("bankaccount:Test AG - refund bank account.uuid");
httpPost("/api/hs/office/contacts", usingJsonBody("""
http(POST, "/api/hs/office/contacts", usingJsonBody("""
{
"caption": "Test AG - billing department",
"emailAddresses": {
@ -31,10 +30,10 @@ class HsOfficeDebitorUseCase extends UseCase {
}
}
"""))
.expecting(CREATED).expecting(JSON)
.expecting(HttpStatus.CREATED)
.keepingAs("contact:Test AG - billing department.uuid");
httpPost("/api/hs/office/debitors", usingJsonBody("""
http(POST, "/api/hs/office/debitors", usingJsonBody("""
{
"debitorRel": {
"type": "DEBITOR", // FIXME: should be defaulted to DEBITOR
@ -52,8 +51,7 @@ class HsOfficeDebitorUseCase extends UseCase {
"defaultPrefix": "tst"
}
"""))
.expecting(CREATED).expecting(JSON)
.expecting(HttpStatus.CREATED)
.keepingAs("debitor:Test AG - Hauptdebitor.uuid");
return null;
}
}

View File

@ -1,19 +0,0 @@
package net.hostsharing.hsadminng.hs.office.usecases;
import org.springframework.http.HttpStatus;
class HsOfficeDeletePartnerUseCase extends UseCase {
public HsOfficeDeletePartnerUseCase(final UseCaseTest testSuite) {
super(testSuite);
requires("partner:Test AG for deletetion:uuid", () -> new HsOfficeCreatePartnerUseCase(testSuite));
}
@Override
HttpResponse run() {
httpDelete("/api/hs/office/partners/" + uuid("partner:Test AG.uuid"))
.expecting(HttpStatus.NO_CONTENT);
return null;
}
}

View File

@ -1,26 +0,0 @@
package net.hostsharing.hsadminng.hs.office.usecases;
import io.restassured.http.ContentType;
import org.springframework.http.HttpStatus;
class HsOfficeMembershipUseCase extends UseCase {
public HsOfficeMembershipUseCase(final UseCaseTest testSuite) {
super(testSuite);
}
@Override
HttpResponse run() {
httpPost("/api/hs/office/memberships", usingJsonBody("""
{
"partnerUuid": "${partner:Test AG.uuid}",
"memberNumberSuffix": "00",
"validFrom": "2024-10-15",
"membershipFeeBillable": "true"
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
.keepingAs("membership:Test AG 00.uuid");
return null;
}
}

View File

@ -1,27 +1,27 @@
package net.hostsharing.hsadminng.hs.office.usecases;
import io.restassured.http.ContentType;
import org.springframework.http.HttpStatus;
class HsOfficeCreatePartnerUseCase extends UseCase {
import static io.restassured.http.Method.POST;
public HsOfficeCreatePartnerUseCase(final UseCaseTest testSuite) {
class HsOfficePartnerUseCase extends UseCase {
public HsOfficePartnerUseCase(final UseCaseTest testSuite) {
super(testSuite);
}
@Override
HttpResponse run() {
void shouldCreatePartner() {
httpPost("/api/hs/office/persons", usingJsonBody("""
http(POST, "/api/hs/office/persons", usingJsonBody("""
{
"personType": "LEGAL_PERSON",
"tradeName": "Test AG"
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
.expecting(HttpStatus.CREATED)
.keepingAs("person:Test AG.uuid");
httpPost("/api/hs/office/contacts", usingJsonBody("""
http(POST, "/api/hs/office/contacts", usingJsonBody("""
{
"caption": "Test AG - Bord of Directors",
"emailAddresses": {
@ -29,10 +29,10 @@ class HsOfficeCreatePartnerUseCase extends UseCase {
}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON)
.expecting(HttpStatus.CREATED)
.keepingAs("contact:Test AG - Bord of Directors.uuid");
return httpPost("/api/hs/office/partners", usingJsonBody("""
http(POST, "/api/hs/office/partners", usingJsonBody("""
{
"partnerNumber": "30003",
"partnerRel": {
@ -46,6 +46,7 @@ class HsOfficeCreatePartnerUseCase extends UseCase {
}
}
"""))
.expecting(HttpStatus.CREATED).expecting(ContentType.JSON);
.expecting(HttpStatus.CREATED)
.keepingAs("partner:Test AG.uuid");
}
}

View File

@ -2,12 +2,11 @@ package net.hostsharing.hsadminng.hs.office.usecases;
import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.ClassOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.TestClassOrder;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(
@ -15,32 +14,18 @@ import org.springframework.boot.test.context.SpringBootTest;
classes = { HsadminNgApplication.class, JpaAttempt.class }
)
@Tag("useCaseTest")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ExtendWith(OrderedDependedTestsExtension.class)
@TestClassOrder(ClassOrderer.OrderAnnotation.class)
class HsOfficeUseCasesTest extends UseCaseTest {
@Test
@Order(1010)
void shouldCreatePartner() {
new HsOfficeCreatePartnerUseCase(this).run()
.keepingAs("partner:Test AG.uuid");
}
@Test
@Order(1011)
void shouldDeletePartner() {
new HsOfficeDeletePartnerUseCase(this).run();
new HsOfficePartnerUseCase(this).shouldCreatePartner();
}
@Test
@Order(1020)
void shouldCreateSelfDebitorForPartner() {
new HsOfficeDebitorUseCase(this).run();
}
@Test
@Order(1030)
void shouldCreateMembershipForPartner() {
new HsOfficeMembershipUseCase(this).run();
new HsOfficeDebitorUseCase(this).shouldCreateSelfDebitorForPartner();
}
}

View File

@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.office.usecases;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import org.springframework.http.HttpStatus;
@ -10,13 +11,12 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.startsWith;
public abstract class UseCase {
public class UseCase {
private final UseCaseTest testSuite;
@ -24,40 +24,24 @@ public abstract class UseCase {
this.testSuite = testSuite;
}
void requires(final String alias, final Supplier<UseCase> useCaseSupplier) {
if ( !UseCaseTest.aliases.containsKey(alias) ) {
useCaseSupplier.get().run().keepingAs(alias);
}
}
abstract HttpResponse run();
JsonTemplate usingJsonBody(final String jsonTemplate) {
return new JsonTemplate(jsonTemplate);
}
HttpResponse httpPost(final String uriPath, final JsonTemplate bodyJsonTemplate) {
final var response = RestAssured.given()
HttpResponse http(final Method method, final String uriPath, final JsonTemplate bodyJsonTemplate) {
final var request = RestAssured.given()
.header("current-subject", UseCaseTest.RUN_AS_USER)
.contentType(ContentType.JSON)
.body(bodyJsonTemplate.with(UseCaseTest.aliases))
.port(testSuite.port)
.when().post("http://localhost" + uriPath);
.port(testSuite.port);
final var response =
switch (method) {
case POST -> request.when().post("http://localhost" + uriPath);
default -> throw new IllegalStateException("HTTP method not implemented yet: " + method);
};
return new HttpResponse(response);
}
HttpResponse httpDelete(final String uriPath) {
final var response = RestAssured.given()
.header("current-subject", UseCaseTest.RUN_AS_USER)
.port(testSuite.port)
.when().delete("http://localhost" + uriPath);
return new HttpResponse(response);
}
UUID uuid(final String alias) {
return testSuite.aliases.get(alias);
}
static class JsonTemplate {
private final String template;
@ -66,10 +50,10 @@ public abstract class UseCase {
this.template = jsonTemplate;
}
String with(final Map<String, UUID> aliases) {
String with(final Map<String, String> aliases) {
var partiallyResolved = new AtomicReference<>(template);
aliases.forEach((k, v) ->
partiallyResolved.set(partiallyResolved.get().replace("${" + k + "}", v.toString())));
partiallyResolved.set(partiallyResolved.get().replace("${" + k + "}", v)));
verifyAllPlaceholdersResolved(partiallyResolved.get());
return partiallyResolved.get();
}
@ -96,12 +80,8 @@ public abstract class UseCase {
}
HttpResponse expecting(final HttpStatus httpStatus) {
response.statusCode(httpStatus.value());
return this;
}
HttpResponse expecting(final ContentType contentType) {
response.contentType(contentType);
response.statusCode(httpStatus.value())
.contentType(ContentType.JSON);
return this;
}
@ -111,7 +91,7 @@ public abstract class UseCase {
final var newSubjectUuid = UUID.fromString(
location.substring(location.lastIndexOf('/') + 1));
assertThat(newSubjectUuid).isNotNull();
UseCaseTest.aliases.put(uuidAliasName, newSubjectUuid);
UseCaseTest.aliases.put(uuidAliasName, newSubjectUuid.toString());
}
}
}

View File

@ -6,23 +6,17 @@ import net.hostsharing.hsadminng.lambda.Reducer;
import net.hostsharing.hsadminng.rbac.context.ContextBasedTest;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.web.server.LocalServerPort;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.assertj.core.api.Assumptions.assumeThat;
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 Map<String, UUID> aliases = new HashMap<>();
final static Map<String, String> aliases = new HashMap<>();
@LocalServerPort
Integer port;
@ -43,23 +37,9 @@ public abstract class UseCaseTest extends ContextBasedTest {
personRepo.findPersonByOptionalNameLike("Hostsharing eG")
.stream()
.map(HsOfficePersonEntity::getUuid)
.map(Object::toString)
.reduce(Reducer::toSingleElement).orElseThrow());
}
);
}
}
class OrderedDependedTestsExtension implements TestWatcher, BeforeEachCallback {
private static boolean previousTestsPassed = true;
@Override
public void testFailed(final ExtensionContext context, final Throwable cause) {
previousTestsPassed = false;
}
@Override
public void beforeEach(final ExtensionContext extensionContext) {
assumeThat(previousTestsPassed).isTrue();
}
}