historic-view #92

Merged
hsh-michaelhoennig merged 19 commits from historic-view into master 2024-08-29 17:00:20 +02:00
3 changed files with 49 additions and 20 deletions
Showing only changes of commit 7bb5e14d01 - Show all commits

View File

@ -20,7 +20,9 @@ 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.LocalDate;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -62,6 +64,50 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
@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_item';
""");
// when
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating booking-item test-data 1000111, hs_booking_item, INSERT]",
"[creating booking-item test-data 1000212, hs_booking_item, INSERT]",
"[creating booking-item test-data 1000313, hs_booking_item, INSERT]");
}
@Test
public void historizationIsAvailable() {
// given
final String nativeQuerySql = """
select count(*)
from hs_booking_item_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_item 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_item should contain rows for a timestamp in the future").isGreaterThan(1);
}
@Nested
class CreateBookingItem {
@ -304,25 +350,6 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
}
}
@Test
public void auditJournalLogIsAvailable() {
// given
final var query = em.createNativeQuery("""
select currentTask, targetTable, targetOp
from tx_journal_v
where targettable = 'hs_booking_item';
""");
// when
@SuppressWarnings("unchecked") final List<Object[]> customerLogEntries = query.getResultList();
// then
assertThat(customerLogEntries).map(Arrays::toString).contains(
"[creating booking-item test-data 1000111, hs_booking_item, INSERT]",
"[creating booking-item test-data 1000212, hs_booking_item, INSERT]",
"[creating booking-item test-data 1000313, hs_booking_item, INSERT]");
}
private HsBookingItem givenSomeTemporaryBookingItem(final String projectCaption) {
return jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");

View File

@ -100,7 +100,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
""";
// when
historicalContext(Timestamp.from(ZonedDateTime.now().minusHours(1).toInstant()));
historicalContext(Timestamp.from(ZonedDateTime.now().minusDays(1).toInstant()));
final var query = em.createNativeQuery(nativeQuerySql, Integer.class);
@SuppressWarnings("unchecked") final var countBefore = (Integer) query.getSingleResult();

View File

@ -251,7 +251,9 @@ public class CsvDataImport extends ContextBasedTest {
em.createNativeQuery("delete from hs_hosting_asset where true").executeUpdate();
em.createNativeQuery("delete from hs_hosting_asset_ex where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_item where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_item_ex where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_project where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_project_ex where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopsharestransaction where true").executeUpdate();