Skip to content

Commit

Permalink
PI-2249 update message handler (#4022)
Browse files Browse the repository at this point in the history
* PI-2249 update message handler

* Update projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/PomCaseMessageHandler.kt

Co-authored-by: Marcus Aspin <maspin@unilink.com>

---------

Co-authored-by: Marcus Aspin <maspin@unilink.com>
  • Loading branch information
achimber-moj and marcus-bcl authored Jul 11, 2024
1 parent 559f1b6 commit c8b11de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.message.PersonIdentifier
import uk.gov.justice.digital.hmpps.message.PersonReference
import uk.gov.justice.digital.hmpps.messaging.Notifier.Companion.BULK_HANDOVER_DATE_UPDATE
import uk.gov.justice.digital.hmpps.services.HandoverDatesChanged
import uk.gov.justice.digital.hmpps.services.PomAllocated
import uk.gov.justice.digital.hmpps.telemetry.TelemetryMessagingExtensions.notificationReceived
Expand Down Expand Up @@ -58,7 +59,7 @@ class PomCaseMessageHandler(
)
)

"offender-management.allocation.changed" -> pomAllocated.process(message)
"offender-management.allocation.changed", BULK_HANDOVER_DATE_UPDATE -> pomAllocated.process(message)
else -> throw NotImplementedError("Unhandled message type received: ${notification.eventType}")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package uk.gov.justice.digital.hmpps.messaging

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.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.*
import uk.gov.justice.digital.hmpps.data.generator.MessageGenerator
import uk.gov.justice.digital.hmpps.integrations.delius.person.entity.PersonRepository
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.MessageAttributes
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.messaging.Notifier.Companion.BULK_HANDOVER_DATE_UPDATE
import uk.gov.justice.digital.hmpps.services.HandoverDatesChanged
import uk.gov.justice.digital.hmpps.services.PomAllocated
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
Expand All @@ -35,8 +39,8 @@ internal class HandlerTest {

lateinit var handler: PomCaseMessageHandler

@Test
fun `handles unexpected event type`() {
@BeforeEach
fun setUp() {
handler = PomCaseMessageHandler(
"localhost",
converter,
Expand All @@ -45,6 +49,10 @@ internal class HandlerTest {
telemetryService,
personRepository
)
}

@Test
fun `handles unexpected event type`() {
val exception = assertThrows<NotImplementedError> {
handler.handle(
Notification(
Expand All @@ -55,4 +63,21 @@ internal class HandlerTest {
}
assertThat(exception.message, equalTo("Unexpected offender event type: UNKNOWN"))
}

@Test
fun `handles internal event type`() {
doNothing().whenever(pomAllocated).process(any<HmppsDomainEvent>())
handler.handle(
Notification(
message = HmppsDomainEvent(
eventType = BULK_HANDOVER_DATE_UPDATE,
version = 1
),
attributes = MessageAttributes(eventType = BULK_HANDOVER_DATE_UPDATE)
)
)

verify(pomAllocated, times(1)).process(any<HmppsDomainEvent>())
verifyNoMoreInteractions(pomAllocated)
}
}

0 comments on commit c8b11de

Please sign in to comment.