Skip to content

Commit

Permalink
PI-1538 dual run offender events with registration domain events (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj authored Oct 5, 2023
1 parent f08936c commit 9bd722d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ internal class IntegrationTest {
OffenderDeltaGenerator.generate(sourceTable = "MANAGEMENT_TIER_EVENT", sourceId = 99),
listOf("OFFENDER_MANAGEMENT_TIER_CALCULATION_REQUIRED")
),
Arguments.of(
OffenderDeltaGenerator.generate(sourceTable = "MANAGEMENT_TIER_EVENT", action = "DELETE", sourceId = 99),
emptyList<String>()
),
Arguments.of(
OffenderDeltaGenerator.generate(sourceTable = "MERGE_HISTORY", sourceId = 99),
listOf("OFFENDER_MERGED")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package uk.gov.justice.digital.hmpps.integrations.delius.offender

import org.springframework.beans.factory.annotation.Value
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import uk.gov.justice.digital.hmpps.integrations.delius.tier.ManagementTierEventRepository
import uk.gov.justice.digital.hmpps.message.MessageAttributes
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher
Expand All @@ -15,7 +13,6 @@ class OffenderDeltaService(
@Value("\${offender-events.batch-size:50}")
private val batchSize: Int,
private val repository: OffenderDeltaRepository,
private val managementTierEventRepository: ManagementTierEventRepository,
private val notificationPublisher: NotificationPublisher
) {
@Transactional
Expand All @@ -33,7 +30,7 @@ class OffenderDeltaService(
"DEREGISTRATION" -> "OFFENDER_REGISTRATION_DEREGISTERED"
"DISPOSAL" -> "SENTENCE_CHANGED"
"EVENT" -> "CONVICTION_CHANGED"
"MANAGEMENT_TIER_EVENT" -> if (managementTierMessageIgnored()) null else "OFFENDER_MANAGEMENT_TIER_CALCULATION_REQUIRED"
"MANAGEMENT_TIER_EVENT" -> "OFFENDER_MANAGEMENT_TIER_CALCULATION_REQUIRED"
"MERGE_HISTORY" -> "OFFENDER_MERGED"
"OFFENDER" -> "OFFENDER_DETAILS_CHANGED"
"OFFICER" -> "OFFENDER_OFFICER_CHANGED"
Expand All @@ -57,7 +54,4 @@ class OffenderDeltaService(
listOf()
}
}

private fun OffenderDelta.managementTierMessageIgnored() = action == "DELETE" ||
managementTierEventRepository.findByIdOrNull(sourceRecordId)?.reason?.code in listOf("ROSH", "MAP", "REG", "DEREG")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@ package uk.gov.justice.digital.hmpps.integrations.delius.offender
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.data.domain.PageImpl
import org.springframework.data.domain.Pageable
import uk.gov.justice.digital.hmpps.data.generator.OffenderDeltaGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.tier.ManagementTierEvent
import uk.gov.justice.digital.hmpps.integrations.delius.tier.ManagementTierEventRepository
import uk.gov.justice.digital.hmpps.integrations.delius.tier.ReferenceData
import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher
import java.util.Optional

@ExtendWith(MockitoExtension::class)
class OffenderDeltaServiceTest {
Expand All @@ -39,7 +33,7 @@ class OffenderDeltaServiceTest {

@BeforeEach
fun setup() {
service = OffenderDeltaService(50, repository, managementTierEventRepository, publisher)
service = OffenderDeltaService(50, repository, publisher)
}

@ParameterizedTest
Expand All @@ -51,18 +45,6 @@ class OffenderDeltaServiceTest {
assertThat(expectedCounts, equalTo(counts))
}

@Test
fun `do not publish registration management tier events`() {
val mteId = 1L
whenever(managementTierEventRepository.findById(mteId))
.thenReturn(Optional.of(ManagementTierEvent(mteId, ReferenceData("REG", 1L))))
val deltas = listOf(OffenderDeltaGenerator.generate(sourceId = mteId, sourceTable = "MANAGEMENT_TIER_EVENT"))
whenever(repository.findAll(any<Pageable>())).thenReturn(PageImpl(deltas))
val counts = service.checkAndSendEvents()
assertThat(counts.first, equalTo(0))
verify(publisher, never()).publish(any())
}

companion object {
@JvmStatic
private fun deltas() = listOf(
Expand Down

0 comments on commit 9bd722d

Please sign in to comment.