historic-view #92

Merged
hsh-michaelhoennig merged 19 commits from historic-view into master 2024-08-29 17:00:20 +02:00
2 changed files with 57 additions and 25 deletions
Showing only changes of commit 19033e15bc - Show all commits

View File

@ -20,6 +20,8 @@ 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;
@ -57,6 +59,50 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
@MockBean
HttpServletRequest request;
@Test
public void auditJournalLogIsAvailable() {
// given
final var query = em.createNativeQuery("""
select currentTask, targetTable, targetOp
from tx_journal_v
where targettable = 'hs_booking_project';
""");
// when
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating booking-project test-data 1000111, hs_booking_project, INSERT]",
"[creating booking-project test-data 1000212, hs_booking_project, INSERT]",
"[creating booking-project test-data 1000313, hs_booking_project, INSERT]");
}
@Test
public void historizationIsAvailable() {
// given
final String nativeQuerySql = """
select count(*)
from hs_booking_project_hv ha;
""";
// when
historicalContext(Timestamp.from(ZonedDateTime.now().minusDays(1).toInstant()));
final var query = em.createNativeQuery(nativeQuerySql, Integer.class);
@SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult();
// then
assertThat(countBefore).as("hs_booking_project_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_booking_project_hv should contain rows for a timestamp in the future").isGreaterThan(1);
}
@Nested
class CreateBookingProject {
@ -283,25 +329,6 @@ class HsBookingProjectRepositoryIntegrationTest extends ContextBasedTestWithClea
}
}
@Test
public void auditJournalLogIsAvailable() {
// given
final var query = em.createNativeQuery("""
select currentTask, targetTable, targetOp
from tx_journal_v
where targettable = 'hs_booking_project';
""");
// when
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating booking-project test-data 1000111, hs_booking_project, INSERT]",
"[creating booking-project test-data 1000212, hs_booking_project, INSERT]",
"[creating booking-project test-data 1000313, hs_booking_project, INSERT]");
}
private HsBookingProjectRealEntity givenSomeTemporaryBookingProject(final int debitorNumber) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");

View File

@ -50,19 +50,24 @@ public abstract class ContextBasedTest {
}
protected void historicalContext(final Long txId) {
final var query = em.createNativeQuery("""
// set local cannot be used with query parameters
em.createNativeQuery("""
set local hsadminng.tx_history_txid to ':txid';
""".replace(":txid", txId.toString()));
query.executeUpdate();
""".replace(":txid", txId.toString())).executeUpdate();
em.createNativeQuery("""
set local hsadminng.tx_history_timestamp to '';
""").executeUpdate();
}
protected void historicalContext(final Timestamp txTimestamp) {
// set local cannot be used with query parameters
final var query = em.createNativeQuery("""
em.createNativeQuery("""
set local hsadminng.tx_history_timestamp to ':timestamp';
""".replace(":timestamp", txTimestamp.toString()));
query.executeUpdate();
""".replace(":timestamp", txTimestamp.toString())).executeUpdate();
em.createNativeQuery("""
set local hsadminng.tx_history_txid to '';
""").executeUpdate();
}
}