From d77d853c800f7f0d32cc08b46febaf031f318805 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 13 Oct 2022 08:34:04 +0200 Subject: [PATCH] add audit journal log for hs_office_partner --- .../db/changelog/220-hs-office-partner.sql | 8 ++++ ...fficePartnerRepositoryIntegrationTest.java | 41 +++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/main/resources/db/changelog/220-hs-office-partner.sql b/src/main/resources/db/changelog/220-hs-office-partner.sql index 04b8f402..9a5a8712 100644 --- a/src/main/resources/db/changelog/220-hs-office-partner.sql +++ b/src/main/resources/db/changelog/220-hs-office-partner.sql @@ -16,3 +16,11 @@ create table if not exists hs_office_partner dateOfDeath date ); --// + + +-- ============================================================================ +--changeset hs-office-partner-MAIN-TABLE-JOURNAL:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +call create_journal('hs_office_partner'); +--// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java index 504d52f3..0417f548 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/partner/HsOfficePartnerRepositoryIntegrationTest.java @@ -21,10 +21,7 @@ import org.springframework.test.annotation.DirtiesContext; import javax.persistence.EntityManager; import javax.servlet.http.HttpServletRequest; import java.time.LocalDate; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.grantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacrole.RawRbacRoleEntity.roleNamesOf; @@ -390,6 +387,33 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest { } } + @Test + public void auditJournalLogIsAvailable() { + // given + final var query = em.createNativeQuery(""" + select c.currenttask, j.targettable, j.targetop + from tx_journal j + join tx_context c on j.txid = c.txid + where targettable = 'hs_office_partner'; + """); + + // when + @SuppressWarnings("unchecked") final List customerLogEntries = query.getResultList(); + + // then + assertThat(customerLogEntries).map(Arrays::toString) + .contains("[creating RBAC test partner FirstGmbH-firstcontact, hs_office_partner, INSERT]"); + } + + @AfterEach + void cleanup() { + context("superuser-alex@hostsharing.net", null); + tempPartners.forEach(tempPartner -> { + System.out.println("DELETING temporary partner: " + tempPartner.toString()); + partnerRepo.deleteByUuid(tempPartner.getUuid()); + }); + } + private HsOfficePartnerEntity givenSomeTemporaryPartnerBessler(final String contact) { return jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); @@ -412,15 +436,6 @@ class HsOfficePartnerRepositoryIntegrationTest extends ContextBasedTest { return tempPartner; } - @AfterEach - void cleanup() { - context("superuser-alex@hostsharing.net", null); - tempPartners.forEach(tempPartner -> { - System.out.println("DELETING temporary partner: " + tempPartner.toString()); - partnerRepo.deleteByUuid(tempPartner.getUuid()); - }); - } - void exactlyThesePartnersAreReturned(final List actualResult, final String... partnerNames) { assertThat(actualResult) .extracting(partnerEntity -> partnerEntity.toString())