From 2a2cc091dde23c8bf7534f89941733e094ba6f43 Mon Sep 17 00:00:00 2001 From: Marcus Aspin Date: Thu, 2 Nov 2023 13:55:17 +0000 Subject: [PATCH] Added test --- .../audit/service/OptimisationTablesTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libs/audit/src/test/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTablesTest.kt diff --git a/libs/audit/src/test/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTablesTest.kt b/libs/audit/src/test/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTablesTest.kt new file mode 100644 index 0000000000..704cf4196e --- /dev/null +++ b/libs/audit/src/test/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTablesTest.kt @@ -0,0 +1,29 @@ +package uk.gov.justice.digital.hmpps.audit.service + +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.hasSize +import org.junit.jupiter.api.Assertions.assertDoesNotThrow +import org.junit.jupiter.api.Test +import org.mockito.Mockito.mock +import org.mockito.Mockito.verify +import org.springframework.jdbc.core.JdbcTemplate +import org.springframework.transaction.support.TransactionSynchronizationManager + +class OptimisationTablesTest { + @Test + fun `handles non-Oracle database`() { + assertDoesNotThrow { OptimisationTables(null).rebuild(123) } + } + + @Test + fun `creates afterCommit hook`() { + val jdbcTemplate = mock(JdbcTemplate::class.java) + TransactionSynchronizationManager.initSynchronization() + + OptimisationTables(OptimisationTablesRebuild(jdbcTemplate)).rebuild(123) + + assertThat(TransactionSynchronizationManager.getSynchronizations(), hasSize(1)) + TransactionSynchronizationManager.getSynchronizations()[0].afterCommit() + verify(jdbcTemplate).execute("call PKG_TRIGGERSUPPORT.PROCREBUILDOPTTABLES(123)") + } +}