Compare commits
No commits in common. "ea05773e2663c6e975059c21d99a8cdc866d9026" and "8c8b82461effcdce00ecb1e89a24c56f269e6e77" have entirely different histories.
ea05773e26
...
8c8b82461e
@ -1,3 +1,11 @@
|
||||
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
|
||||
|
@ -20,10 +20,3 @@ create table if not exists 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,11 +36,3 @@ create table if not exists 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,8 +23,6 @@ import org.springframework.orm.jpa.JpaSystemException;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -72,50 +70,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
@MockBean
|
||||
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
|
||||
class CreateAsset {
|
||||
|
||||
@ -437,6 +391,25 @@ 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) {
|
||||
return jpaAttempt.transacted(() -> {
|
||||
context("superuser-alex@hostsharing.net"); // needed to determine creator
|
||||
|
@ -9,7 +9,6 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
@Import(RbacGrantsDiagramService.class)
|
||||
public abstract class ContextBasedTest {
|
||||
@ -48,21 +47,4 @@ public abstract class ContextBasedTest {
|
||||
protected void context(final String currentUser) {
|
||||
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