Compare commits

..

No commits in common. "572061b3cfa4fb9c69211ac58a53ff4978c72ded" and "ebb94969e7fc7ac2dbddeb9cce0a4e329f654a5f" have entirely different histories.

27 changed files with 298 additions and 377 deletions

View File

@ -53,7 +53,7 @@ To be able to build and run the Java Spring Boot application, you need the follo
- Docker 20.x (on MacOS you also need *Docker Desktop* or similar) or Podman - Docker 20.x (on MacOS you also need *Docker Desktop* or similar) or Podman
- optionally: PostgreSQL Server 15.5-bookworm - optionally: PostgreSQL Server 15.5-bookworm
(see instructions below to install and run in Docker) (see instructions below to install and run in Docker)
- The matching Java JDK at will be automatically installed by Gradle toolchain support to `~/.gradle/jdks/`. - The matching Java JDK at will be automatically installed by Gradle toolchain support.
- You also might need an IDE (e.g. *IntelliJ IDEA* or *Eclipse* or *VS Code* with *[STS](https://spring.io/tools)* and a GUI Frontend for *PostgreSQL* like *Postbird*. - You also might need an IDE (e.g. *IntelliJ IDEA* or *Eclipse* or *VS Code* with *[STS](https://spring.io/tools)* and a GUI Frontend for *PostgreSQL* like *Postbird*.
If you have at least Docker and the Java JDK installed in appropriate versions and in your `PATH`, then you can start like this: If you have at least Docker and the Java JDK installed in appropriate versions and in your `PATH`, then you can start like this:

View File

@ -19,7 +19,7 @@ public interface HsOfficeBankAccountRepository extends Repository<HsOfficeBankAc
""") """)
List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder); List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder);
List<HsOfficeBankAccountEntity> findByIbanOrderByIbanAsc(String iban); List<HsOfficeBankAccountEntity> findByIbanOrderByIban(String iban);
<S extends HsOfficeBankAccountEntity> S save(S entity); <S extends HsOfficeBankAccountEntity> S save(S entity);

View File

@ -8,12 +8,9 @@ import java.util.UUID;
public interface RbacRoleRepository extends Repository<RbacRoleEntity, UUID> { public interface RbacRoleRepository extends Repository<RbacRoleEntity, UUID> {
/** /**
* @return the number of persistent RbacRoleEntity instances, mostly for testing purposes. * Returns all instances of the type.
*/ *
long count(); * @return all entities
/**
* @return all persistent RbacRoleEntity instances, mostly for testing purposes.
*/ */
List<RbacRoleEntity> findAll(); List<RbacRoleEntity> findAll();

View File

@ -32,7 +32,7 @@ call create_journal('hs_office_partner_details');
create table hs_office_partner create table hs_office_partner
( (
uuid uuid unique references RbacObject (uuid) initially deferred, uuid uuid unique references RbacObject (uuid) initially deferred,
partnerNumber numeric(5) unique not null, partnerNumber numeric(5),
partnerRoleUuid uuid not null references hs_office_relationship(uuid) on delete cascade, partnerRoleUuid uuid not null references hs_office_relationship(uuid) on delete cascade,
personUuid uuid not null references hs_office_person(uuid), -- TODO: remove, replaced by partnerRoleUuid personUuid uuid not null references hs_office_person(uuid), -- TODO: remove, replaced by partnerRoleUuid
contactUuid uuid not null references hs_office_contact(uuid), -- TODO: remove, replaced by partnerRoleUuid contactUuid uuid not null references hs_office_contact(uuid), -- TODO: remove, replaced by partnerRoleUuid

View File

@ -120,14 +120,14 @@ begin
if OLD.partnerRoleUuid <> NEW.partnerRoleUuid then if OLD.partnerRoleUuid <> NEW.partnerRoleUuid then
select * from hs_office_relationship as r where r.uuid = OLD.partnerRoleUuid into oldPartnerRole; select * from hs_office_relationship as r where r.uuid = OLD.partnerRoleUuid into oldPartnerRole;
call revokeRoleFromRole(hsOfficeRelationshipTenant(oldPartnerRole), hsOfficePartnerAdmin(OLD)); call revokeRoleFromRole(hsOfficeRelationshipTenant(oldPerson), hsOfficePartnerAdmin(OLD));
call grantRoleToRole(hsOfficeRelationshipTenant(newPartnerRole), hsOfficePartnerAdmin(NEW)); call grantRoleToRole(hsOfficeRelationshipTenant(newPerson), hsOfficePartnerAdmin(NEW));
call revokeRoleFromRole(hsOfficePartnerAgent(OLD), hsOfficeRelationshipAdmin(oldPartnerRole)); call revokeRoleFromRole(hsOfficePartnerAgent(OLD), hsOfficeRelationshipAdmin(oldPerson));
call grantRoleToRole(hsOfficePartnerAgent(NEW), hsOfficeRelationshipAdmin(newPartnerRole)); call grantRoleToRole(hsOfficePartnerAgent(NEW), hsOfficeRelationshipAdmin(newPerson));
call revokeRoleFromRole(hsOfficeRelationshipGuest(oldPartnerRole), hsOfficePartnerTenant(OLD)); call revokeRoleFromRole(hsOfficeRelationshipGuest(oldPerson), hsOfficePartnerTenant(OLD));
call grantRoleToRole(hsOfficeRelationshipGuest(newPartnerRole), hsOfficePartnerTenant(NEW)); call grantRoleToRole(hsOfficeRelationshipGuest(newPerson), hsOfficePartnerTenant(NEW));
end if; end if;
if OLD.personUuid <> NEW.personUuid then if OLD.personUuid <> NEW.personUuid then
@ -204,6 +204,7 @@ call generateRbacRestrictedView('hs_office_partner',
personUuid = new.personUuid, personUuid = new.personUuid,
contactUuid = new.contactUuid contactUuid = new.contactUuid
$updates$); $updates$);
-- partnerRoleUuid = new.partnerRoleUuid,
--// --//

View File

@ -63,7 +63,7 @@ begin
else else
insert insert
into hs_office_partner_details (uuid, registrationOffice, registrationNumber) into hs_office_partner_details (uuid, registrationOffice, registrationNumber)
values (uuid_generate_v4(), 'Hamburg', 'RegNo123456789') values (uuid_generate_v4(), 'Hamburg', '12345')
returning uuid into relatedDetailsUuid; returning uuid into relatedDetailsUuid;
end if; end if;

View File

@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public abstract class ContextBasedTest { public abstract class ContextBasedTest {
@Autowired @Autowired
protected Context context; Context context;
TestInfo test; TestInfo test;

View File

@ -4,7 +4,6 @@ import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
@ -30,7 +29,7 @@ import static org.hamcrest.Matchers.startsWith;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeBankAccountControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;

View File

@ -1,12 +1,14 @@
package net.hostsharing.hsadminng.hs.office.bankaccount; package net.hostsharing.hsadminng.hs.office.bankaccount;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -29,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import({ Context.class, JpaAttempt.class }) @Import({ Context.class, JpaAttempt.class })
class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeBankAccountRepository bankAccountRepo; HsOfficeBankAccountRepository bankAccountRepo;
@ -59,8 +61,8 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
final var count = bankAccountRepo.count(); final var count = bankAccountRepo.count();
// when // when
final var result = attempt(em, () -> toCleanup(bankAccountRepo.save( final var result = attempt(em, () -> bankAccountRepo.save(
hsOfficeBankAccount("some temp acc A", "DE37500105177419788228", "")))); hsOfficeBankAccount("some temp acc A", "DE37500105177419788228", "")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -76,8 +78,8 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
final var count = bankAccountRepo.count(); final var count = bankAccountRepo.count();
// when // when
final var result = attempt(em, () -> toCleanup(bankAccountRepo.save( final var result = attempt(em, () -> bankAccountRepo.save(
hsOfficeBankAccount("some temp acc B", "DE49500105174516484892", "INGDDEFFXXX")))); hsOfficeBankAccount("some temp acc B", "DE49500105174516484892", "INGDDEFFXXX")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -94,8 +96,8 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()); final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll());
// when // when
attempt(em, () -> toCleanup(bankAccountRepo.save( attempt(em, () -> bankAccountRepo.save(
hsOfficeBankAccount("some temp acc C", "DE25500105176934832579", "INGDDEFFXXX"))) hsOfficeBankAccount("some temp acc C", "DE25500105176934832579", "INGDDEFFXXX"))
).assertSuccessful(); ).assertSuccessful();
// then // then
@ -172,7 +174,7 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
context("superuser-alex@hostsharing.net", null); context("superuser-alex@hostsharing.net", null);
// when // when
final var result = bankAccountRepo.findByIbanOrderByIbanAsc("DE02120300000000202051"); final var result = bankAccountRepo.findByIbanOrderByIban("DE02120300000000202051");
// then // then
exactlyTheseBankAccountsAreReturned(result, "First GmbH"); exactlyTheseBankAccountsAreReturned(result, "First GmbH");
@ -185,7 +187,7 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
// when: // when:
context("selfregistered-user-drew@hostsharing.org"); context("selfregistered-user-drew@hostsharing.org");
final var result = bankAccountRepo.findByIbanOrderByIbanAsc(givenBankAccount.getIban()); final var result = bankAccountRepo.findByIbanOrderByIban(givenBankAccount.getIban());
// then: // then:
exactlyTheseBankAccountsAreReturned(result, givenBankAccount.getHolder()); exactlyTheseBankAccountsAreReturned(result, givenBankAccount.getHolder());
@ -269,7 +271,7 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
Supplier<HsOfficeBankAccountEntity> entitySupplier) { Supplier<HsOfficeBankAccountEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return toCleanup(bankAccountRepo.save(entitySupplier.get())); return bankAccountRepo.save(entitySupplier.get());
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
@ -291,6 +293,17 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
"[creating bankaccount test-data Second e.K., hs_office_bankaccount, INSERT]"); "[creating bankaccount test-data Second e.K., hs_office_bankaccount, INSERT]");
} }
@BeforeEach
@AfterEach
void cleanup() {
context("superuser-alex@hostsharing.net", null);
final var result = bankAccountRepo.findByOptionalHolderLike("some temp acc");
result.forEach(tempPerson -> {
System.out.println("DELETING temporary bankaccount: " + tempPerson.getHolder());
bankAccountRepo.deleteByUuid(tempPerson.getUuid());
});
}
private HsOfficeBankAccountEntity givenSomeTemporaryBankAccount(final String createdByUser) { private HsOfficeBankAccountEntity givenSomeTemporaryBankAccount(final String createdByUser) {
final var random = RandomStringUtils.randomAlphabetic(3); final var random = RandomStringUtils.randomAlphabetic(3);
return givenSomeTemporaryBankAccount(createdByUser, () -> return givenSomeTemporaryBankAccount(createdByUser, () ->

View File

@ -4,7 +4,6 @@ import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
@ -33,7 +32,7 @@ import static org.hamcrest.Matchers.startsWith;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeContactControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeContactControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;

View File

@ -1,12 +1,14 @@
package net.hostsharing.hsadminng.hs.office.contact; package net.hostsharing.hsadminng.hs.office.contact;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -29,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeContactRepository contactRepo; HsOfficeContactRepository contactRepo;
@ -60,8 +62,8 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = attempt(em, () -> toCleanup(contactRepo.save( final var result = attempt(em, () -> contactRepo.save(
hsOfficeContact("a new contact", "contact-admin@www.example.com")))); hsOfficeContact("a new contact", "contact-admin@www.example.com")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -77,8 +79,8 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
final var count = contactRepo.count(); final var count = contactRepo.count();
// when // when
final var result = attempt(em, () -> toCleanup(contactRepo.save( final var result = attempt(em, () -> contactRepo.save(
hsOfficeContact("another new contact", "another-new-contact@example.com")))); hsOfficeContact("another new contact", "another-new-contact@example.com")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -95,8 +97,8 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()); final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll());
// when // when
attempt(em, () -> toCleanup(contactRepo.save( attempt(em, () -> contactRepo.save(
hsOfficeContact("another new contact", "another-new-contact@example.com"))) hsOfficeContact("another new contact", "another-new-contact@example.com"))
).assumeSuccessful(); ).assumeSuccessful();
// then // then
@ -276,10 +278,21 @@ class HsOfficeContactRepositoryIntegrationTest extends ContextBasedTestWithClean
Supplier<HsOfficeContactEntity> entitySupplier) { Supplier<HsOfficeContactEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return toCleanup(contactRepo.save(entitySupplier.get())); return contactRepo.save(entitySupplier.get());
}).assumeSuccessful().returnedValue(); }).assumeSuccessful().returnedValue();
} }
@BeforeEach
@AfterEach
void cleanup() {
context("superuser-alex@hostsharing.net", null);
final var result = contactRepo.findContactByOptionalLabelLike("some temporary contact");
result.forEach(tempPerson -> {
System.out.println("DELETING temporary contact: " + tempPerson.getLabel());
contactRepo.deleteByUuid(tempPerson.getUuid());
});
}
private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) { private HsOfficeContactEntity givenSomeTemporaryContact(final String createdByUser) {
final var random = RandomStringUtils.randomAlphabetic(12); final var random = RandomStringUtils.randomAlphabetic(12);
return givenSomeTemporaryContact(createdByUser, () -> return givenSomeTemporaryContact(createdByUser, () ->

View File

@ -5,7 +5,6 @@ import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -33,7 +32,7 @@ import static org.hamcrest.Matchers.startsWith;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeCoopAssetsTransactionControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeCoopAssetsTransactionControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
Integer port; Integer port;

View File

@ -1,8 +1,8 @@
package net.hostsharing.hsadminng.hs.office.coopassets; package net.hostsharing.hsadminng.hs.office.coopassets;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeCoopAssetsTransactionRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo; HsOfficeCoopAssetsTransactionRepository coopAssetsTransactionRepo;

View File

@ -5,7 +5,6 @@ import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
@ -30,7 +29,7 @@ import static org.hamcrest.Matchers.startsWith;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {HsadminNgApplication.class, JpaAttempt.class}) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {HsadminNgApplication.class, JpaAttempt.class})
@Transactional @Transactional
class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeCoopSharesTransactionControllerAcceptanceTest {
@Autowired @Autowired
Context context; Context context;

View File

@ -1,8 +1,8 @@
package net.hostsharing.hsadminng.hs.office.coopshares; package net.hostsharing.hsadminng.hs.office.coopshares;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository; import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeCoopSharesTransactionRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeCoopSharesTransactionRepository coopSharesTransactionRepo; HsOfficeCoopSharesTransactionRepository coopSharesTransactionRepo;

View File

@ -7,7 +7,6 @@ import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.json.JSONException; import org.json.JSONException;
@ -34,7 +33,7 @@ import static org.hamcrest.Matchers.*;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeDebitorControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeDebitorControllerAcceptanceTest {
private static final int LOWEST_TEMP_DEBITOR_SUFFIX = 90; private static final int LOWEST_TEMP_DEBITOR_SUFFIX = 90;
private static byte nextDebitorSuffix = LOWEST_TEMP_DEBITOR_SUFFIX; private static byte nextDebitorSuffix = LOWEST_TEMP_DEBITOR_SUFFIX;

View File

@ -7,7 +7,6 @@ import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.json.JSONException; import org.json.JSONException;
@ -35,7 +34,7 @@ import static org.hamcrest.Matchers.*;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeMembershipControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeMembershipControllerAcceptanceTest {
private static String TEMP_MEMBER_NUMBER_SUFFIX = "90"; private static String TEMP_MEMBER_NUMBER_SUFFIX = "90";

View File

@ -2,9 +2,9 @@ package net.hostsharing.hsadminng.hs.office.membership;
import com.vladmihalcea.hibernate.type.range.Range; import com.vladmihalcea.hibernate.type.range.Range;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository; import net.hostsharing.hsadminng.hs.office.partner.HsOfficePartnerRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeMembershipRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeMembershipRepository membershipRepo; HsOfficeMembershipRepository membershipRepo;

View File

@ -1179,7 +1179,7 @@ class OrderedDependedTestsExtension implements TestWatcher, BeforeEachCallback {
} }
@Override @Override
public void beforeEach(final ExtensionContext extensionContext) { public void beforeEach(final ExtensionContext extensionContext) throws Exception {
assumeThat(previousTestsPassed).isTrue(); assumeThat(previousTestsPassed).isTrue();
} }
} }

View File

@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.office.partner;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntity;
@ -10,7 +11,6 @@ import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.*; import org.junit.jupiter.api.*;
@ -19,6 +19,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid; import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
@ -30,13 +33,19 @@ import static org.hamcrest.Matchers.*;
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficePartnerControllerAcceptanceTest {
private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); private static final UUID GIVEN_NON_EXISTING_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@Autowired
Context context;
@Autowired
Context contextMock;
@Autowired @Autowired
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@ -52,6 +61,10 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
@PersistenceContext
EntityManager em;
private long relationshipCountBefore;
@Nested @Nested
@Accepts({ "Partner:F(Find)" }) @Accepts({ "Partner:F(Find)" })
@Transactional @Transactional
@ -69,15 +82,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.then().log().all().assertThat() .then().log().all().assertThat()
.statusCode(200) .statusCode(200)
.contentType("application/json") .contentType("application/json")
.body("", lenientlyEquals(""" .body("", hasSize(5));
[
{ partnerNumber: 10001 },
{ partnerNumber: 10002 },
{ partnerNumber: 10003 },
{ partnerNumber: 10004 },
{ partnerNumber: 10010 }
]
"""));
// @formatter:on // @formatter:on
} }
} }
@ -101,7 +106,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(""" .body("""
{ {
"partnerNumber": "20002", "partnerNumber": "12345",
"partnerRole": { "partnerRole": {
"relAnchorUuid": "%s", "relAnchorUuid": "%s",
"relHolderUuid": "%s", "relHolderUuid": "%s",
@ -127,7 +132,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.statusCode(201) .statusCode(201)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body("uuid", isUuidValid()) .body("uuid", isUuidValid())
.body("partnerNumber", is(20002))
.body("details.registrationOffice", is("Temp Registergericht Aurich")) .body("details.registrationOffice", is("Temp Registergericht Aurich"))
.body("details.registrationNumber", is("111111")) .body("details.registrationNumber", is("111111"))
.body("contact.label", is(givenContact.getLabel())) .body("contact.label", is(givenContact.getLabel()))
@ -154,7 +158,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(""" .body("""
{ {
"partnerNumber": "20003", "partnerNumber": "12345",
"partnerRole": { "partnerRole": {
"relAnchorUuid": "%s", "relAnchorUuid": "%s",
"relHolderUuid": "%s", "relHolderUuid": "%s",
@ -192,7 +196,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(""" .body("""
{ {
"partnerNumber": "20004", "partnerNumber": "12345",
"partnerRole": { "partnerRole": {
"relAnchorUuid": "%s", "relAnchorUuid": "%s",
"relHolderUuid": "%s", "relHolderUuid": "%s",
@ -294,17 +298,17 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
void globalAdmin_withoutAssumedRole_canPatchAllPropertiesOfArbitraryPartner() { void globalAdmin_withoutAssumedRole_canPatchAllPropertiesOfArbitraryPartner() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20011); final var givenPartner = givenSomeTemporaryPartnerBessler();
final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").get(0); final var givenPerson = personRepo.findPersonByOptionalNameLike("Third").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("fourth").get(0);
RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
.header("current-user", "superuser-alex@hostsharing.net") .header("current-user", "superuser-alex@hostsharing.net")
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(""" .body("""
{ {
"partnerNumber": "20011", "partnerNumber": "12345",
"contactUuid": "%s", "contactUuid": "%s",
"personUuid": "%s", "personUuid": "%s",
"details": { "details": {
@ -322,8 +326,8 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
.then().assertThat() .then().assertThat()
.statusCode(200) .statusCode(200)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body("uuid", is(givenPartner.getUuid().toString())) // not patched! .body("uuid", isUuidValid())
.body("partnerNumber", is(givenPartner.getPartnerNumber())) // not patched! .body("partnerNumber", is(givenPartner.getPartnerNumber()))
.body("details.registrationNumber", is("222222")) .body("details.registrationNumber", is("222222"))
.body("contact.label", is(givenContact.getLabel())) .body("contact.label", is(givenContact.getLabel()))
.body("person.tradeName", is(givenPerson.getTradeName())); .body("person.tradeName", is(givenPerson.getTradeName()));
@ -332,15 +336,14 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
// finally, the partner is actually updated // finally, the partner is actually updated
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get() assertThat(partnerRepo.findByUuid(givenPartner.getUuid())).isPresent().get()
.matches(partner -> { .matches(person -> {
assertThat(partner.getPartnerNumber()).isEqualTo(givenPartner.getPartnerNumber()); assertThat(person.getPerson().getTradeName()).isEqualTo("Third OHG");
assertThat(partner.getPerson().getTradeName()).isEqualTo("Third OHG"); assertThat(person.getContact().getLabel()).isEqualTo("fourth contact");
assertThat(partner.getContact().getLabel()).isEqualTo("fourth contact"); assertThat(person.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Aurich");
assertThat(partner.getDetails().getRegistrationOffice()).isEqualTo("Temp Registergericht Aurich"); assertThat(person.getDetails().getRegistrationNumber()).isEqualTo("222222");
assertThat(partner.getDetails().getRegistrationNumber()).isEqualTo("222222"); assertThat(person.getDetails().getBirthName()).isEqualTo("Maja Schmidt");
assertThat(partner.getDetails().getBirthName()).isEqualTo("Maja Schmidt"); assertThat(person.getDetails().getBirthday()).isEqualTo("1938-04-08");
assertThat(partner.getDetails().getBirthday()).isEqualTo("1938-04-08"); assertThat(person.getDetails().getDateOfDeath()).isEqualTo("2022-01-12");
assertThat(partner.getDetails().getDateOfDeath()).isEqualTo("2022-01-12");
return true; return true;
}); });
} }
@ -349,7 +352,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
void globalAdmin_withoutAssumedRole_canPatchPartialPropertiesOfArbitraryPartner() { void globalAdmin_withoutAssumedRole_canPatchPartialPropertiesOfArbitraryPartner() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20012); final var givenPartner = givenSomeTemporaryPartnerBessler();
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -400,7 +403,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Test @Test
void globalAdmin_withoutAssumedRole_canDeleteArbitraryPartner() { void globalAdmin_withoutAssumedRole_canDeleteArbitraryPartner() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20013); final var givenPartner = givenSomeTemporaryPartnerBessler();
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()
@ -420,7 +423,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Accepts({ "Partner:X(Access Control)" }) @Accepts({ "Partner:X(Access Control)" })
void contactAdminUser_canNotDeleteRelatedPartner() { void contactAdminUser_canNotDeleteRelatedPartner() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20014); final var givenPartner = givenSomeTemporaryPartnerBessler();
assertThat(givenPartner.getContact().getLabel()).isEqualTo("fourth contact"); assertThat(givenPartner.getContact().getLabel()).isEqualTo("fourth contact");
RestAssured // @formatter:off RestAssured // @formatter:off
@ -440,7 +443,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
@Accepts({ "Partner:X(Access Control)" }) @Accepts({ "Partner:X(Access Control)" })
void normalUser_canNotDeleteUnrelatedPartner() { void normalUser_canNotDeleteUnrelatedPartner() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20015); final var givenPartner = givenSomeTemporaryPartnerBessler();
assertThat(givenPartner.getContact().getLabel()).isEqualTo("fourth contact"); assertThat(givenPartner.getContact().getLabel()).isEqualTo("fourth contact");
RestAssured // @formatter:off RestAssured // @formatter:off
@ -457,7 +460,7 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
} }
} }
private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler(final Integer partnerNumber) { private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler() {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0); final var givenMandantPerson = personRepo.findPersonByOptionalNameLike("Hostsharing eG").get(0);
@ -474,7 +477,6 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
final var newPartner = HsOfficePartnerEntity.builder() final var newPartner = HsOfficePartnerEntity.builder()
.partnerRole(partnerRole) .partnerRole(partnerRole)
.partnerNumber(partnerNumber)
.person(givenPerson) .person(givenPerson)
.contact(givenContact) .contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder() .details(HsOfficePartnerDetailsEntity.builder()
@ -487,10 +489,43 @@ class HsOfficePartnerControllerAcceptanceTest extends ContextBasedTestWithCleanu
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
@BeforeEach
void countRelationships() {
context.define("superuser-alex@hostsharing.net", null);
relationshipCountBefore = relationshipRepository.count();
}
@AfterEach @AfterEach
@SuppressWarnings("unchecked")
void cleanup() { void cleanup() {
cleanupAllNew(HsOfficePartnerEntity.class); final var deleted = jpaAttempt.transacted(() -> {
cleanupAllNew(HsOfficePartnerDetailsEntity.class); context.define("superuser-alex@hostsharing.net", null);
cleanupAllNew(HsOfficeRelationshipEntity.class); final var tempPartnerUuids = (List<UUID>)em.createNativeQuery("""
select uuid from hs_office_partner p
where p.detailsuuid in (
select d.uuid from hs_office_partner_details d
where d.registrationoffice like 'Temp %')
""")
.getResultList();
tempPartnerUuids.forEach(partnerUuid -> {
final var tempPartner = partnerRepo.findByUuid(partnerUuid).orElseThrow();
em.remove(tempPartner);
em.remove(tempPartner.getPartnerRole());
});
}).assertSuccessful().returnedValue();
final var remaining = jpaAttempt.transacted(() -> {
em.createNativeQuery("""
select count(p) from hs_office_partner p
where p.detailsuuid in (
select d.uuid from hs_office_partner_details d
where d.registrationoffice like 'Temp %')
""")
.getSingleResult();
}).assertSuccessful().returnedValue();
System.err.println("@AfterEach" + ": " + deleted + " records deleted, " + remaining + " remaining");
context.define("superuser-alex@hostsharing.net", null);
assertThat(relationshipRepository.count()).as("not all relationships got cleaned up").isEqualTo(relationshipCountBefore);
} }
} }

View File

@ -1,12 +1,12 @@
package net.hostsharing.hsadminng.hs.office.partner; package net.hostsharing.hsadminng.hs.office.partner;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipEntity;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipRepository;
import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType; import net.hostsharing.hsadminng.hs.office.relationship.HsOfficeRelationshipType;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficePartnerRepository partnerRepo; HsOfficePartnerRepository partnerRepo;
@ -88,14 +88,13 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
// when // when
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newPartner = HsOfficePartnerEntity.builder() final var newPartner = toCleanup(HsOfficePartnerEntity.builder()
.partnerNumber(20031)
.partnerRole(partnerRole) .partnerRole(partnerRole)
.person(givenPartnerPerson) .person(givenPartnerPerson)
.contact(givenContact) .contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder() .details(HsOfficePartnerDetailsEntity.builder()
.build()) .build())
.build(); .build());
return partnerRepo.save(newPartner); return partnerRepo.save(newPartner);
}); });
@ -131,13 +130,13 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.build(); .build();
relationshipRepo.save(newRelationship); relationshipRepo.save(newRelationship);
final var newPartner = HsOfficePartnerEntity.builder() final var newPartner = toCleanup(HsOfficePartnerEntity.builder()
.partnerNumber(20032) .partnerNumber(22222)
.partnerRole(newRelationship) .partnerRole(newRelationship)
.person(givenPartnerPerson) .person(givenPartnerPerson)
.contact(givenContact) .contact(givenContact)
.details(HsOfficePartnerDetailsEntity.builder().build()) .details(HsOfficePartnerDetailsEntity.builder().build())
.build(); .build());
return partnerRepo.save(newPartner); return partnerRepo.save(newPartner);
}).assertSuccessful(); }).assertSuccessful();
@ -147,11 +146,11 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin", "hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.admin",
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner", "hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.owner",
"hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant", "hs_office_relationship#HostsharingeG-with-PARTNER-ErbenBesslerMelBessler.tenant",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.admin", "hs_office_partner#22222:ErbenBesslerMelBessler-fourthcontact.admin",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.agent", "hs_office_partner#22222:ErbenBesslerMelBessler-fourthcontact.agent",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.owner", "hs_office_partner#22222:ErbenBesslerMelBessler-fourthcontact.owner",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.tenant", "hs_office_partner#22222:ErbenBesslerMelBessler-fourthcontact.tenant",
"hs_office_partner#20032:ErbenBesslerMelBessler-fourthcontact.guest")); "hs_office_partner#22222:ErbenBesslerMelBessler-fourthcontact.guest"));
assertThat(grantDisplaysOf(rawGrantRepo.findAll())) assertThat(grantDisplaysOf(rawGrantRepo.findAll()))
.map(s -> s.replace("ErbenBesslerMelBessler", "EBess")) .map(s -> s.replace("ErbenBesslerMelBessler", "EBess"))
.map(s -> s.replace("fourthcontact", "4th")) .map(s -> s.replace("fourthcontact", "4th"))
@ -159,11 +158,9 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.containsExactlyInAnyOrder(Array.fromFormatted( .containsExactlyInAnyOrder(Array.fromFormatted(
initialGrantNames, initialGrantNames,
// relationship - TODO: check and cleanup // relationship - TODO: check and cleanup
"{ grant role person#HostsharingeG.tenant to role person#EBess.admin by system and assume }", "{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#22222:EBess-4th.admin by system and assume }",
"{ grant role person#EBess.tenant to role person#HostsharingeG.admin by system and assume }", "{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#22222:EBess-4th.tenant by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.admin by system and assume }", "{ grant role partner#22222:EBess-4th.agent to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role partner#20032:EBess-4th.tenant by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role relationship#HostsharingeG-with-PARTNER-EBess.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }", "{ grant role relationship#HostsharingeG-with-PARTNER-EBess.owner to role global#global.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }", "{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role contact#4th.admin by system and assume }",
"{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }", "{ grant role relationship#HostsharingeG-with-PARTNER-EBess.tenant to role person#EBess.admin by system and assume }",
@ -179,31 +176,31 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
"{ grant role person#HostsharingeG.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }", "{ grant role person#HostsharingeG.tenant to role relationship#HostsharingeG-with-PARTNER-EBess.tenant by system and assume }",
// owner // owner
"{ grant perm * on partner#20032:EBess-4th to role partner#20032:EBess-4th.owner by system and assume }", "{ grant perm * on partner#22222:EBess-4th to role partner#22222:EBess-4th.owner by system and assume }",
"{ grant perm * on partner_details#20032:EBess-4th-details to role partner#20032:EBess-4th.owner by system and assume }", "{ grant perm * on partner_details#22222:EBess-4th-details to role partner#22222:EBess-4th.owner by system and assume }",
"{ grant role partner#20032:EBess-4th.owner to role global#global.admin by system and assume }", "{ grant role partner#22222:EBess-4th.owner to role global#global.admin by system and assume }",
// admin // admin
"{ grant perm edit on partner#20032:EBess-4th to role partner#20032:EBess-4th.admin by system and assume }", "{ grant perm edit on partner#22222:EBess-4th to role partner#22222:EBess-4th.admin by system and assume }",
"{ grant perm edit on partner_details#20032:EBess-4th-details to role partner#20032:EBess-4th.admin by system and assume }", "{ grant perm edit on partner_details#22222:EBess-4th-details to role partner#22222:EBess-4th.admin by system and assume }",
"{ grant role partner#20032:EBess-4th.admin to role partner#20032:EBess-4th.owner by system and assume }", "{ grant role partner#22222:EBess-4th.admin to role partner#22222:EBess-4th.owner by system and assume }",
"{ grant role person#EBess.tenant to role partner#20032:EBess-4th.admin by system and assume }", "{ grant role person#EBess.tenant to role partner#22222:EBess-4th.admin by system and assume }",
"{ grant role contact#4th.tenant to role partner#20032:EBess-4th.admin by system and assume }", "{ grant role contact#4th.tenant to role partner#22222:EBess-4th.admin by system and assume }",
// agent // agent
"{ grant perm view on partner_details#20032:EBess-4th-details to role partner#20032:EBess-4th.agent by system and assume }", "{ grant perm view on partner_details#22222:EBess-4th-details to role partner#22222:EBess-4th.agent by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role partner#20032:EBess-4th.admin by system and assume }", "{ grant role partner#22222:EBess-4th.agent to role partner#22222:EBess-4th.admin by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role person#EBess.admin by system and assume }", "{ grant role partner#22222:EBess-4th.agent to role person#EBess.admin by system and assume }",
"{ grant role partner#20032:EBess-4th.agent to role contact#4th.admin by system and assume }", "{ grant role partner#22222:EBess-4th.agent to role contact#4th.admin by system and assume }",
// tenant // tenant
"{ grant role partner#20032:EBess-4th.tenant to role partner#20032:EBess-4th.agent by system and assume }", "{ grant role partner#22222:EBess-4th.tenant to role partner#22222:EBess-4th.agent by system and assume }",
"{ grant role person#EBess.guest to role partner#20032:EBess-4th.tenant by system and assume }", "{ grant role person#EBess.guest to role partner#22222:EBess-4th.tenant by system and assume }",
"{ grant role contact#4th.guest to role partner#20032:EBess-4th.tenant by system and assume }", "{ grant role contact#4th.guest to role partner#22222:EBess-4th.tenant by system and assume }",
// guest // guest
"{ grant perm view on partner#20032:EBess-4th to role partner#20032:EBess-4th.guest by system and assume }", "{ grant perm view on partner#22222:EBess-4th to role partner#22222:EBess-4th.guest by system and assume }",
"{ grant role partner#20032:EBess-4th.guest to role partner#20032:EBess-4th.tenant by system and assume }", "{ grant role partner#22222:EBess-4th.guest to role partner#22222:EBess-4th.tenant by system and assume }",
null)); null));
} }
@ -288,10 +285,10 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
public void hostsharingAdmin_withoutAssumedRole_canUpdateArbitraryPartner() { public void hostsharingAdmin_withoutAssumedRole_canUpdateArbitraryPartner() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20032, "Erben Bessler", "fifth contact"); final var givenPartner = givenSomeTemporaryPartnerBessler(22222, "Erben Bessler", "fifth contact");
assertThatPartnerIsVisibleForUserWithRole( assertThatPartnerIsVisibleForUserWithRole(
givenPartner, givenPartner,
"hs_office_partner#20032:ErbenBesslerMelBessler-fifthcontact.admin"); "hs_office_partner#22222:ErbenBesslerMelBessler-fifthcontact.admin");
assertThatPartnerActuallyInDatabase(givenPartner); assertThatPartnerActuallyInDatabase(givenPartner);
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenNewPerson = personRepo.findPersonByOptionalNameLike("Third OHG").get(0); final var givenNewPerson = personRepo.findPersonByOptionalNameLike("Third OHG").get(0);
@ -302,7 +299,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
givenPartner.setContact(givenNewContact); givenPartner.setContact(givenNewContact);
givenPartner.setPerson(givenNewPerson); givenPartner.setPerson(givenNewPerson);
return partnerRepo.save(givenPartner); return toCleanup(partnerRepo.save(givenPartner));
}); });
// then // then
@ -324,20 +321,20 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
public void partnerAgent_canNotUpdateRelatedPartner() { public void partnerAgent_canNotUpdateRelatedPartner() {
// given // given
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var givenPartner = givenSomeTemporaryPartnerBessler(20032, "Erben Bessler", "ninth"); final var givenPartner = givenSomeTemporaryPartnerBessler(22222, "Erben Bessler", "ninth");
final var newPartnerRole = em.createNativeQuery( final var newPartnerRole = em.createNativeQuery(
"select uuid from hs_office_relationship where uuid=:partnerRoleUuid") "select uuid from hs_office_relationship where uuid=:partnerRoleUuid")
.setParameter("partnerRoleUuid", givenPartner.getPartnerRole().getUuid()) .setParameter("partnerRoleUuid", givenPartner.getPartnerRole().getUuid())
.getSingleResult(); .getSingleResult();
assertThatPartnerIsVisibleForUserWithRole( assertThatPartnerIsVisibleForUserWithRole(
givenPartner, givenPartner,
"hs_office_partner#20032:ErbenBesslerMelBessler-ninthcontact.agent"); "hs_office_partner#22222:ErbenBesslerMelBessler-ninthcontact.agent");
assertThatPartnerActuallyInDatabase(givenPartner); assertThatPartnerActuallyInDatabase(givenPartner);
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net", context("superuser-alex@hostsharing.net",
"hs_office_partner#20032:ErbenBesslerMelBessler-ninthcontact.agent"); "hs_office_partner#22222:ErbenBesslerMelBessler-ninthcontact.agent");
givenPartner.getDetails().setBirthName("new birthname"); givenPartner.getDetails().setBirthName("new birthname");
return partnerRepo.save(givenPartner); return partnerRepo.save(givenPartner);
}); });
@ -379,7 +376,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
public void globalAdmin_withoutAssumedRole_canDeleteAnyPartner() { public void globalAdmin_withoutAssumedRole_canDeleteAnyPartner() {
// given // given
context("superuser-alex@hostsharing.net", null); context("superuser-alex@hostsharing.net", null);
final var givenPartner = givenSomeTemporaryPartnerBessler(20032, "Erben Bessler", "tenth"); final var givenPartner = givenSomeTemporaryPartnerBessler(22222, "Erben Bessler", "tenth");
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
@ -399,7 +396,7 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
public void nonGlobalAdmin_canNotDeleteTheirRelatedPartner() { public void nonGlobalAdmin_canNotDeleteTheirRelatedPartner() {
// given // given
context("superuser-alex@hostsharing.net", null); context("superuser-alex@hostsharing.net", null);
final var givenPartner = givenSomeTemporaryPartnerBessler(20032, "Erben Bessler", "eleventh"); final var givenPartner = givenSomeTemporaryPartnerBessler(22222, "Erben Bessler", "eleventh");
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
@ -425,20 +422,18 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
final var initialRoleNames = Array.from(roleNamesOf(rawRoleRepo.findAll())); final var initialRoleNames = Array.from(roleNamesOf(rawRoleRepo.findAll()));
final var initialGrantNames = Array.from(grantDisplaysOf(rawGrantRepo.findAll())); final var initialGrantNames = Array.from(grantDisplaysOf(rawGrantRepo.findAll()));
final var givenPartner = givenSomeTemporaryPartnerBessler(20032, "Erben Bessler", "twelfth"); final var givenPartner = givenSomeTemporaryPartnerBessler(22222, "Erben Bessler", "twelfth");
// when // when
final var result = jpaAttempt.transacted(() -> { final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
// TODO: should deleting a partner automatically delete the PARTNER relationship? (same for debitor) return relationshipRepo.deleteByUuid(givenPartner.getPartnerRole().getUuid());
// TODO: why did the test cleanup check does not notice this, if missing? // return partnerRepo.deleteByUuid(givenPartner.getUuid());
return partnerRepo.deleteByUuid(givenPartner.getUuid()) +
relationshipRepo.deleteByUuid(givenPartner.getPartnerRole().getUuid());
}); });
// then // then
result.assertSuccessful(); result.assertSuccessful();
assertThat(result.returnedValue()).isEqualTo(2); // partner+relationship assertThat(result.returnedValue()).isEqualTo(1);
assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(initialRoleNames); assertThat(roleNamesOf(rawRoleRepo.findAll())).containsExactlyInAnyOrder(initialRoleNames);
assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(initialGrantNames); assertThat(grantDisplaysOf(rawGrantRepo.findAll())).containsExactlyInAnyOrder(initialGrantNames);
} }
@ -462,6 +457,16 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
"[creating partner test-data Seconde.K.-secondcontact, hs_office_partner, INSERT]"); "[creating partner test-data Seconde.K.-secondcontact, hs_office_partner, INSERT]");
} }
@AfterEach
void cleanup() {
context("superuser-alex@hostsharing.net", null);
tempPartners.forEach(tempPartner -> {
System.out.println("DELETING temporary partner: " + tempPartner.toString());
relationshipRepo.deleteByUuid(tempPartner.getPartnerRole().getUuid());
partnerRepo.deleteByUuid(tempPartner.getUuid());
});
}
private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler( private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler(
final Integer partnerNumber, final String person, final String contact) { final Integer partnerNumber, final String person, final String contact) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
@ -487,10 +492,17 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.details(HsOfficePartnerDetailsEntity.builder().build()) .details(HsOfficePartnerDetailsEntity.builder().build())
.build(); .build();
toCleanup(newPartner);
return partnerRepo.save(newPartner); return partnerRepo.save(newPartner);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private HsOfficePartnerEntity toCleanup(final HsOfficePartnerEntity tempPartner) {
tempPartners.add(tempPartner);
return tempPartner;
}
void exactlyThesePartnersAreReturned(final List<HsOfficePartnerEntity> actualResult, final String... partnerNames) { void exactlyThesePartnersAreReturned(final List<HsOfficePartnerEntity> actualResult, final String... partnerNames) {
assertThat(actualResult) assertThat(actualResult)
.extracting(partnerEntity -> partnerEntity.toString()) .extracting(partnerEntity -> partnerEntity.toString())
@ -502,11 +514,4 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTestWithClean
.extracting(partnerEntity -> partnerEntity.toString()) .extracting(partnerEntity -> partnerEntity.toString())
.contains(partnerNames); .contains(partnerNames);
} }
@AfterEach
void cleanup() {
cleanupAllNew(HsOfficePartnerEntity.class);
cleanupAllNew(HsOfficePartnerDetailsEntity.class);
cleanupAllNew(HsOfficeRelationshipEntity.class);
}
} }

View File

@ -4,10 +4,10 @@ import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.json.JSONException;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.*;
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficePersonControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@ -54,7 +54,7 @@ class HsOfficePersonControllerAcceptanceTest extends ContextBasedTestWithCleanup
class ListPersons { class ListPersons {
@Test @Test
void globalAdmin_withoutAssumedRoles_canViewAllPersons_ifNoCriteriaGiven() { void globalAdmin_withoutAssumedRoles_canViewAllPersons_ifNoCriteriaGiven() throws JSONException {
RestAssured // @formatter:off RestAssured // @formatter:off
.given() .given()

View File

@ -1,12 +1,13 @@
package net.hostsharing.hsadminng.hs.office.person; package net.hostsharing.hsadminng.hs.office.person;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -29,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import( { Context.class, JpaAttempt.class }) @Import( { Context.class, JpaAttempt.class })
class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficePersonRepository personRepo; HsOfficePersonRepository personRepo;
@ -60,8 +61,8 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
// when // when
final var result = attempt(em, () -> toCleanup(personRepo.save( final var result = attempt(em, () -> personRepo.save(
hsOfficePerson("a new person")))); hsOfficePerson("a new person")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -77,8 +78,8 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
final var count = personRepo.count(); final var count = personRepo.count();
// when // when
final var result = attempt(em, () -> toCleanup(personRepo.save( final var result = attempt(em, () -> personRepo.save(
hsOfficePerson("another new person")))); hsOfficePerson("another new person")));
// then // then
result.assertSuccessful(); result.assertSuccessful();
@ -96,8 +97,8 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll()); final var initialGrantNames = grantDisplaysOf(rawGrantRepo.findAll());
// when // when
attempt(em, () -> toCleanup(personRepo.save( attempt(em, () -> personRepo.save(
hsOfficePerson("another new person"))) hsOfficePerson("another new person"))
).assumeSuccessful(); ).assumeSuccessful();
// then // then
@ -275,12 +276,22 @@ class HsOfficePersonRepositoryIntegrationTest extends ContextBasedTestWithCleanu
"[creating person test-data Second e.K., Smith, Peter, hs_office_person, INSERT]"); "[creating person test-data Second e.K., Smith, Peter, hs_office_person, INSERT]");
} }
@AfterEach
void cleanup() {
context("superuser-alex@hostsharing.net", null);
final var result = personRepo.findPersonByOptionalNameLike("some temporary person");
result.forEach(tempPerson -> {
System.out.println("DELETING temporary person: " + tempPerson.toShortString());
personRepo.deleteByUuid(tempPerson.getUuid());
});
}
private HsOfficePersonEntity givenSomeTemporaryPerson( private HsOfficePersonEntity givenSomeTemporaryPerson(
final String createdByUser, final String createdByUser,
Supplier<HsOfficePersonEntity> entitySupplier) { Supplier<HsOfficePersonEntity> entitySupplier) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context(createdByUser); context(createdByUser);
return toCleanup(personRepo.save(entitySupplier.get())); return personRepo.save(entitySupplier.get());
}).assumeSuccessful().returnedValue(); }).assumeSuccessful().returnedValue();
} }

View File

@ -2,7 +2,6 @@ package net.hostsharing.hsadminng.hs.office.relationship;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
@ -11,6 +10,7 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeRelati
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository; import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonRepository;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.json.JSONException; import org.json.JSONException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +18,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid; import static net.hostsharing.test.IsValidUuidMatcher.isUuidValid;
@ -31,7 +33,7 @@ import static org.hamcrest.Matchers.startsWith;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeRelationshipControllerAcceptanceTest {
public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); public static final UUID GIVEN_NON_EXISTING_HOLDER_PERSON_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
@LocalServerPort @LocalServerPort
@ -55,6 +57,8 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
@Autowired @Autowired
JpaAttempt jpaAttempt; JpaAttempt jpaAttempt;
Set<UUID> tempRelationshipUuids = new HashSet<>();
@Nested @Nested
@Accepts({ "Relationship:F(Find)" }) @Accepts({ "Relationship:F(Find)" })
class ListRelationships { class ListRelationships {
@ -161,7 +165,7 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
.extract().header("Location"); // @formatter:on .extract().header("Location"); // @formatter:on
// finally, the new relationship can be accessed under the generated UUID // finally, the new relationship can be accessed under the generated UUID
final var newUserUuid = toCleanup(HsOfficeRelationshipEntity.class, UUID.fromString( final var newUserUuid = toCleanup(UUID.fromString(
location.substring(location.lastIndexOf('/') + 1))); location.substring(location.lastIndexOf('/') + 1)));
assertThat(newUserUuid).isNotNull(); assertThat(newUserUuid).isNotNull();
} }
@ -464,16 +468,34 @@ class HsOfficeRelationshipControllerAcceptanceTest extends ContextBasedTestWithC
final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0); final var givenHolderPerson = personRepo.findPersonByOptionalNameLike("Winkler").get(0);
final var givenContact = contactRepo.findContactByOptionalLabelLike("seventh contact").get(0); final var givenContact = contactRepo.findContactByOptionalLabelLike("seventh contact").get(0);
final var newRelationship = HsOfficeRelationshipEntity.builder() final var newRelationship = HsOfficeRelationshipEntity.builder()
.uuid(UUID.randomUUID())
.relType(HsOfficeRelationshipType.REPRESENTATIVE) .relType(HsOfficeRelationshipType.REPRESENTATIVE)
.relAnchor(givenAnchorPerson) .relAnchor(givenAnchorPerson)
.relHolder(givenHolderPerson) .relHolder(givenHolderPerson)
.contact(givenContact) .contact(givenContact)
.build(); .build();
assertThat(toCleanup(relationshipRepo.save(newRelationship))).isEqualTo(newRelationship); toCleanup(newRelationship.getUuid());
return newRelationship; return relationshipRepo.save(newRelationship);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }
private UUID toCleanup(final UUID tempRelationshipUuid) {
tempRelationshipUuids.add(tempRelationshipUuid);
return tempRelationshipUuid;
}
@AfterEach
void cleanup() {
tempRelationshipUuids.forEach(uuid -> {
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
System.out.println("DELETING temporary relationship: " + uuid);
final var count = relationshipRepo.deleteByUuid(uuid);
System.out.println("DELETED temporary relationship: " + uuid + (count > 0 ? " successful" : " failed"));
});
});
}
} }

View File

@ -4,9 +4,9 @@ import com.vladmihalcea.hibernate.type.range.Range;
import io.restassured.RestAssured; import io.restassured.RestAssured;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.HsadminNgApplication;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.test.Accepts; import net.hostsharing.test.Accepts;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.json.JSONException; import org.json.JSONException;
@ -34,11 +34,17 @@ import static org.hamcrest.Matchers.*;
classes = { HsadminNgApplication.class, JpaAttempt.class } classes = { HsadminNgApplication.class, JpaAttempt.class }
) )
@Transactional @Transactional
class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCleanup { class HsOfficeSepaMandateControllerAcceptanceTest {
@LocalServerPort @LocalServerPort
private Integer port; private Integer port;
@Autowired
Context context;
@Autowired
Context contextMock;
@Autowired @Autowired
HsOfficeSepaMandateRepository sepaMandateRepo; HsOfficeSepaMandateRepository sepaMandateRepo;
@ -117,7 +123,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc("DE02200505501015871393").get(0); final var givenBankAccount = bankAccountRepo.findByIbanOrderByIban("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -159,7 +165,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc("DE02200505501015871393").get(0); final var givenBankAccount = bankAccountRepo.findByIbanOrderByIban("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()
@ -214,7 +220,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitorUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var givenDebitorUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
final var givenBankAccount = bankAccountRepo.findByIbanOrderByIbanAsc("DE02200505501015871393").get(0); final var givenBankAccount = bankAccountRepo.findByIbanOrderByIban("DE02200505501015871393").get(0);
final var location = RestAssured // @formatter:off final var location = RestAssured // @formatter:off
.given() .given()

View File

@ -2,13 +2,15 @@ package net.hostsharing.hsadminng.hs.office.sepamandate;
import com.vladmihalcea.hibernate.type.range.Range; import com.vladmihalcea.hibernate.type.range.Range;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository; import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountRepository;
import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository;
import net.hostsharing.hsadminng.hs.office.test.ContextBasedTestWithCleanup;
import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository; import net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository; import net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleRepository;
import net.hostsharing.test.Array; import net.hostsharing.test.Array;
import net.hostsharing.test.JpaAttempt; import net.hostsharing.test.JpaAttempt;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,6 +18,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.JpaSystemException; import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.transaction.annotation.Transactional;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContext;
@ -31,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DataJpaTest @DataJpaTest
@Import({ Context.class, JpaAttempt.class }) @Import({ Context.class, JpaAttempt.class })
class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithCleanup { class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTest {
@Autowired @Autowired
HsOfficeSepaMandateRepository sepaMandateRepo; HsOfficeSepaMandateRepository sepaMandateRepo;
@ -78,7 +81,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
.validity(Range.closedOpen( .validity(Range.closedOpen(
LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01"))) LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01")))
.build(); .build();
return toCleanup(sepaMandateRepo.save(newSepaMandate)); return sepaMandateRepo.save(newSepaMandate);
}); });
// then // then
@ -111,7 +114,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
.validity(Range.closedOpen( .validity(Range.closedOpen(
LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01"))) LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01")))
.build(); .build();
return toCleanup(sepaMandateRepo.save(newSepaMandate)); return sepaMandateRepo.save(newSepaMandate);
}); });
// then // then
@ -248,7 +251,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
givenSepaMandate.setAgreement(LocalDate.parse("2019-05-13")); givenSepaMandate.setAgreement(LocalDate.parse("2019-05-13"));
givenSepaMandate.setValidity(Range.closedOpen( givenSepaMandate.setValidity(Range.closedOpen(
LocalDate.parse("2019-05-17"), LocalDate.parse("2023-01-01"))); LocalDate.parse("2019-05-17"), LocalDate.parse("2023-01-01")));
return toCleanup(sepaMandateRepo.save(givenSepaMandate)); return sepaMandateRepo.save(givenSepaMandate);
}); });
// then // then
@ -276,7 +279,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
context("superuser-alex@hostsharing.net", "hs_office_bankaccount#AnitaBessler.admin"); context("superuser-alex@hostsharing.net", "hs_office_bankaccount#AnitaBessler.admin");
givenSepaMandate.setValidity(Range.closedOpen( givenSepaMandate.setValidity(Range.closedOpen(
givenSepaMandate.getValidity().lower(), newValidityEnd)); givenSepaMandate.getValidity().lower(), newValidityEnd));
return toCleanup(sepaMandateRepo.save(givenSepaMandate)); return sepaMandateRepo.save(givenSepaMandate);
}); });
// then // then
@ -401,6 +404,14 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
"[creating SEPA-mandate test-data Seconde.K., hs_office_sepamandate, INSERT]"); "[creating SEPA-mandate test-data Seconde.K., hs_office_sepamandate, INSERT]");
} }
@BeforeEach
@AfterEach
@Transactional
void cleanup() {
context("superuser-alex@hostsharing.net", null);
em.createQuery("DELETE FROM HsOfficeSepaMandateEntity WHERE reference like 'temp ref%'").executeUpdate();
}
private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandateBessler(final String bankAccountHolder) { private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandateBessler(final String bankAccountHolder) {
return jpaAttempt.transacted(() -> { return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net"); context("superuser-alex@hostsharing.net");
@ -415,7 +426,7 @@ class HsOfficeSepaMandateRepositoryIntegrationTest extends ContextBasedTestWithC
LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01"))) LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01")))
.build(); .build();
return toCleanup(sepaMandateRepo.save(newSepaMandate)); return sepaMandateRepo.save(newSepaMandate);
}).assertSuccessful().returnedValue(); }).assertSuccessful().returnedValue();
} }

View File

@ -1,187 +0,0 @@
package net.hostsharing.hsadminng.hs.office.test;
import net.hostsharing.hsadminng.context.ContextBasedTest;
import net.hostsharing.hsadminng.hs.office.migration.HasUuid;
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantEntity;
import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantRepository;
import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleEntity;
import net.hostsharing.hsadminng.rbac.rbacrole.RbacRoleRepository;
import net.hostsharing.test.JpaAttempt;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.Repository;
import jakarta.persistence.*;
import java.util.*;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.collections4.SetUtils.difference;
import static org.apache.commons.collections4.SetUtils.emptySet;
import static org.assertj.core.api.Assertions.assertThat;
public abstract class ContextBasedTestWithCleanup extends ContextBasedTest {
private static final boolean SLOW_DETAILED_DEBUG_MODE = true;
@PersistenceContext
protected EntityManager em;
@Autowired
RbacGrantRepository rbacGrantRepo;
@Autowired
RbacRoleRepository rbacRoleRepo;
@Autowired
RbacObjectRepository rbacObjectRepo;
@Autowired
JpaAttempt jpaAttempt;
private TreeMap<UUID, Class<? extends HasUuid>> entitiesToCleanup = new TreeMap<>();
private static Long objectCountBefore = null;
private Set<String> rbacObjectsBefore;
private Set<String> rbacRolesBefore;
private Set<String> rbacGrantsBefore;
public UUID toCleanup(final Class<? extends HasUuid> entityClass, final UUID uuidToCleanup) {
System.out.println("toCleanup(" + entityClass.getSimpleName() + ", " + uuidToCleanup);
entitiesToCleanup.put(uuidToCleanup, entityClass);
return uuidToCleanup;
}
public <E extends HasUuid> E toCleanup(final E entity) {
System.out.println("toCleanup(" + entity.getClass() + ", " + entity.getUuid());
entitiesToCleanup.put(entity.getUuid(), entity.getClass());
return entity;
}
protected void cleanupAllNew(final Class<? extends HasUuid> entityClass) {
final var tableName = entityClass.getAnnotation(Table.class).name();
final var rvTableName = tableName.endsWith("_rv")
? tableName.substring(0, tableName.length()-"_rv".length())
: tableName;
allRbacObjects().stream()
.filter(o -> o.startsWith(rvTableName+":"))
.filter(o -> !rbacObjectsBefore.contains(o))
.forEach(o ->
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
final UUID uuid = UUID.fromString(o.split(":")[1]);
System.out.println("DELETING new " + entityClass.getSimpleName() + "#" + uuid);
em.remove(em.getReference(entityClass, uuid));
})); //.assertSuccessful());
}
@BeforeEach
//@Transactional -- TODO: check why this does not work but jpaAttempt.transacted does work
void retrieveExistingData() {
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
if ( objectCountBefore != null ) {
assertThat(objectCountBefore = rbacObjectRepo.count())
.as("not all business objects got cleaned up by the previous test")
.isEqualTo(objectCountBefore);
} else {
objectCountBefore = rbacObjectRepo.count();
}
rbacObjectsBefore = allRbacObjects();
rbacRolesBefore = allRbacRoles();
rbacGrantsBefore = allRbacGrants();
});
System.out.println("TOTAL OBJECT COUNT (before): " + objectCountBefore);
}
@AfterEach
void cleanup() {
entitiesToCleanup.forEach((uuid, entityClass) -> {
final var caughtException = jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
System.out.println("DELETING temporary " + entityClass.getSimpleName() + "#" + uuid);
em.remove(em.getReference(entityClass, uuid));
}).caughtException();
if (caughtException != null) {
System.out.println(
"FAILED DELETING temporary " + entityClass.getSimpleName() + "#" + uuid + ": " + caughtException);
}
});
jpaAttempt.transacted(() -> {
context.define("superuser-alex@hostsharing.net", null);
if (SLOW_DETAILED_DEBUG_MODE) {
assertEqual(rbacObjectsBefore, allRbacObjects());
assertEqual(rbacRolesBefore, allRbacRoles());
assertEqual(rbacGrantsBefore, allRbacGrants());
}
assertThat(rbacObjectRepo.count()).as("not all business objects got cleaned up (by current test)")
.isEqualTo(objectCountBefore);
}); //.assertSuccessful();
}
private void assertEqual(final Set<String> before, final Set<String> after) {
assertThat(difference(before, after)).as("missing entities (deleted initial test data)").isEmpty();
assertThat(difference(after, before)).as("spurious entities (temporary test data not cleaned up)").isEmpty();
}
@NotNull
private Set<String> allRbacGrants() {
if (SLOW_DETAILED_DEBUG_MODE) {
return rbacGrantRepo.findAll().stream()
.map(RbacGrantEntity::toDisplay)
.collect(toSet());
}
return emptySet();
}
@NotNull
private Set<String> allRbacRoles() {
if (SLOW_DETAILED_DEBUG_MODE) {
return rbacRoleRepo.findAll().stream()
.map(RbacRoleEntity::getRoleName)
.collect(toSet());
}
return emptySet();
}
@NotNull
private Set<String> allRbacObjects() {
if (SLOW_DETAILED_DEBUG_MODE) {
return rbacObjectRepo.findAll().stream()
.map(Object::toString)
.collect(toSet());
}
return emptySet();
}
}
interface RbacObjectRepository extends Repository<RbacObjectEntity, UUID> {
long count();
List<RbacObjectEntity> findAll();
}
@Entity
@Table(name = "rbacobject")
class RbacObjectEntity {
@Id
@GeneratedValue
private UUID uuid;
@Column(name = "objecttable")
private String objectTable;
@Override
public String toString() {
return objectTable + ":" + uuid;
}
}