Compare commits
3 Commits
8c8b82461e
...
ea05773e26
Author | SHA1 | Date | |
---|---|---|---|
|
ea05773e26 | ||
|
7f16a5c39f | ||
|
07accbb47d |
@ -1,11 +1,3 @@
|
|||||||
rollback;
|
|
||||||
drop table if exists hs_hosting_asset_versions;
|
|
||||||
drop view if exists hs_hosting_asset_hv;
|
|
||||||
drop table if exists hs_hosting_asset_ex;
|
|
||||||
drop procedure if exists tx_create_historicization;
|
|
||||||
drop trigger if exists hs_hosting_asset_tx_historicize_tg on hs_hosting_asset;
|
|
||||||
drop function if exists tx_historicize_tf();
|
|
||||||
drop type if exists tx_operation;
|
|
||||||
|
|
||||||
-- ========================================================
|
-- ========================================================
|
||||||
-- Historization twiddle
|
-- Historization twiddle
|
||||||
|
@ -20,3 +20,10 @@ create table if not exists hs_booking_project
|
|||||||
|
|
||||||
call create_journal('hs_booking_project');
|
call create_journal('hs_booking_project');
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
--changeset hs-booking-project-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--//
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
call tx_create_historicization('hs_booking_project');
|
||||||
|
--//
|
||||||
|
@ -36,3 +36,11 @@ create table if not exists hs_booking_item
|
|||||||
|
|
||||||
call create_journal('hs_booking_item');
|
call create_journal('hs_booking_item');
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
--changeset hs-booking-item-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--//
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
call tx_create_historicization('hs_booking_item');
|
||||||
|
--//
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ import org.springframework.orm.jpa.JpaSystemException;
|
|||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import jakarta.persistence.PersistenceContext;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -70,6 +72,50 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
@MockBean
|
@MockBean
|
||||||
HttpServletRequest request;
|
HttpServletRequest request;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void auditJournalLogIsAvailable() {
|
||||||
|
// given
|
||||||
|
final var query = em.createNativeQuery("""
|
||||||
|
select currentTask, targetTable, targetOp
|
||||||
|
from tx_journal_v
|
||||||
|
where targettable = 'hs_hosting_asset';
|
||||||
|
""");
|
||||||
|
|
||||||
|
// when
|
||||||
|
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(customerLogEntries).map(Arrays::toString).contains(
|
||||||
|
"[creating hosting-asset test-data D-1000111 default project, hs_hosting_asset, INSERT]",
|
||||||
|
"[creating hosting-asset test-data D-1000212 default project, hs_hosting_asset, INSERT]",
|
||||||
|
"[creating hosting-asset test-data D-1000313 default project, hs_hosting_asset, INSERT]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void historizationIsAvailable() {
|
||||||
|
// given
|
||||||
|
final String nativeQuerySql = """
|
||||||
|
select count(*)
|
||||||
|
from hs_hosting_asset_hv ha;
|
||||||
|
""";
|
||||||
|
|
||||||
|
// when
|
||||||
|
historicalContext(Timestamp.from(ZonedDateTime.now().minusHours(1).toInstant()));
|
||||||
|
final var query = em.createNativeQuery(nativeQuerySql, Integer.class);
|
||||||
|
@SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(countBefore).as("hs_hosting_asset_hv should not contain rows for a timestamp in the past").isEqualTo(0);
|
||||||
|
|
||||||
|
// and when
|
||||||
|
historicalContext(Timestamp.from(ZonedDateTime.now().plusHours(1).toInstant()));
|
||||||
|
em.createNativeQuery(nativeQuerySql, Integer.class);
|
||||||
|
@SuppressWarnings("unchecked") final var countAfter = (Integer) query.getSingleResult();
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(countAfter).as("hs_hosting_asset_hv should contain rows for a timestamp in the future").isGreaterThan(1);
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class CreateAsset {
|
class CreateAsset {
|
||||||
|
|
||||||
@ -391,25 +437,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void auditJournalLogIsAvailable() {
|
|
||||||
// given
|
|
||||||
final var query = em.createNativeQuery("""
|
|
||||||
select currentTask, targetTable, targetOp
|
|
||||||
from tx_journal_v
|
|
||||||
where targettable = 'hs_hosting_asset';
|
|
||||||
""");
|
|
||||||
|
|
||||||
// when
|
|
||||||
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
|
|
||||||
|
|
||||||
// then
|
|
||||||
assertThat(customerLogEntries).map(Arrays::toString).contains(
|
|
||||||
"[creating hosting-asset test-data D-1000111 default project, hs_hosting_asset, INSERT]",
|
|
||||||
"[creating hosting-asset test-data D-1000212 default project, hs_hosting_asset, INSERT]",
|
|
||||||
"[creating hosting-asset test-data D-1000313 default project, hs_hosting_asset, INSERT]");
|
|
||||||
}
|
|
||||||
|
|
||||||
private HsHostingAssetRealEntity givenSomeTemporaryAsset(final String projectCaption, final String identifier) {
|
private HsHostingAssetRealEntity givenSomeTemporaryAsset(final String projectCaption, final String identifier) {
|
||||||
return jpaAttempt.transacted(() -> {
|
return jpaAttempt.transacted(() -> {
|
||||||
context("superuser-alex@hostsharing.net"); // needed to determine creator
|
context("superuser-alex@hostsharing.net"); // needed to determine creator
|
||||||
|
@ -9,6 +9,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.PersistenceContext;
|
import jakarta.persistence.PersistenceContext;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
@Import(RbacGrantsDiagramService.class)
|
@Import(RbacGrantsDiagramService.class)
|
||||||
public abstract class ContextBasedTest {
|
public abstract class ContextBasedTest {
|
||||||
@ -47,4 +48,21 @@ public abstract class ContextBasedTest {
|
|||||||
protected void context(final String currentUser) {
|
protected void context(final String currentUser) {
|
||||||
context(currentUser, null);
|
context(currentUser, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void historicalContext(final Long txId) {
|
||||||
|
final var query = em.createNativeQuery("""
|
||||||
|
set local hsadminng.tx_history_txid to ':txid';
|
||||||
|
""".replace(":txid", txId.toString()));
|
||||||
|
query.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void historicalContext(final Timestamp txTimestamp) {
|
||||||
|
// set local cannot be used with query parameters
|
||||||
|
final var query = em.createNativeQuery("""
|
||||||
|
set local hsadminng.tx_history_timestamp to ':timestamp';
|
||||||
|
""".replace(":timestamp", txTimestamp.toString()));
|
||||||
|
query.executeUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user