diff --git a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
index e12e71acf9..f298633c71 100644
--- a/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
+++ b/projects/approved-premises-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
@@ -27,8 +27,8 @@ class Handler(
Message(name = "approved-premises/application-assessed"),
Message(name = "approved-premises/application-withdrawn"),
Message(name = "approved-premises/booking-made"),
- Message(name = "approved-premises/booking-changed"),
Message(name = "approved-premises/booking-cancelled"),
+ Message(messageId = "approved-premises.booking.changed", payload = Schema(HmppsDomainEvent::class)),
Message(messageId = "approved-premises.person.not-arrived", payload = Schema(HmppsDomainEvent::class)),
Message(messageId = "approved-premises.person.arrived", payload = Schema(HmppsDomainEvent::class)),
Message(messageId = "approved-premises.person.departed", payload = Schema(HmppsDomainEvent::class)),
diff --git a/projects/create-and-vary-a-licence-and-delius/tech-docs/source/asyncapi-reference.html.md.erb b/projects/create-and-vary-a-licence-and-delius/tech-docs/source/asyncapi-reference.html.md.erb
index 6b53c29244..ce7cb5de93 100644
--- a/projects/create-and-vary-a-licence-and-delius/tech-docs/source/asyncapi-reference.html.md.erb
+++ b/projects/create-and-vary-a-licence-and-delius/tech-docs/source/asyncapi-reference.html.md.erb
@@ -1,12 +1,12 @@
---
title: AsyncAPI Reference
-source_url: 'https://github.com/ministryofjustice/hmpps-probation-integration-services/blob/main/projects/court-case-and-delius/tech-docs/source/asyncapi-reference.html.md.erb'
+source_url: 'https://github.com/ministryofjustice/hmpps-probation-integration-services/blob/main/projects/create-and-vary-a-licence-and-delius/tech-docs/source/asyncapi-reference.html.md.erb'
weight: 30
---
# AsyncAPI Reference
-
+
diff --git a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt
index 2fe6bb9c66..b6fd237161 100644
--- a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt
+++ b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/DataLoader.kt
@@ -6,16 +6,12 @@ import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
-import uk.gov.justice.digital.hmpps.data.generator.ContactTypeGenerator
-import uk.gov.justice.digital.hmpps.data.generator.KeyDateGenerator
-import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator
-import uk.gov.justice.digital.hmpps.data.generator.ReferenceDataGenerator
+import uk.gov.justice.digital.hmpps.data.generator.*
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.DEFAULT_CUSTODY
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.generateCustodialSentence
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.generateDisposal
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.generateEvent
import uk.gov.justice.digital.hmpps.data.generator.SentenceGenerator.generateOrderManager
-import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
import uk.gov.justice.digital.hmpps.data.repository.DatasetRepository
import uk.gov.justice.digital.hmpps.data.repository.DisposalRepository
import uk.gov.justice.digital.hmpps.data.repository.EventRepository
@@ -90,6 +86,8 @@ class DataLoader(
)
)
createPersonWithKeyDates(PersonGenerator.PERSON_WITH_KEYDATES, "38340A")
+
+ createPersonWithKeyDates(PersonGenerator.PERSON_WITH_KEYDATES_BY_CRN, "48340A")
}
private fun createPersonWithKeyDates(personRef: Person, bookingRef: String): Custody {
diff --git a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
index 92894ad276..92c1a4c3df 100644
--- a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
+++ b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
@@ -1,8 +1,10 @@
package uk.gov.justice.digital.hmpps.data.generator
import uk.gov.justice.digital.hmpps.messaging.CustodyDateChanged
+import uk.gov.justice.digital.hmpps.messaging.ProbationOffenderEvent
import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader
object MessageGenerator {
val SENTENCE_DATE_CHANGED = ResourceLoader.message("sentence-date-changed")
+ val SENTENCE_CHANGED = ResourceLoader.message("sentence-changed")
}
diff --git a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt
index ee27a22605..304a789c1e 100644
--- a/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt
+++ b/projects/custody-key-dates-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.kt
@@ -3,6 +3,7 @@ package uk.gov.justice.digital.hmpps.data.generator
import uk.gov.justice.digital.hmpps.integrations.delius.person.Person
object PersonGenerator {
- val DEFAULT = Person(IdGenerator.getAndIncrement(), "A5089DY")
- val PERSON_WITH_KEYDATES = Person(IdGenerator.getAndIncrement(), "A0001DY")
+ val DEFAULT = Person(IdGenerator.getAndIncrement(), "A500000", "A5089DY")
+ val PERSON_WITH_KEYDATES = Person(IdGenerator.getAndIncrement(), "A000001", "A0001DY")
+ val PERSON_WITH_KEYDATES_BY_CRN = Person(IdGenerator.getAndIncrement(), "A000002", "A0002DY")
}
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/messages/sentence-changed.json b/projects/custody-key-dates-and-delius/src/dev/resources/messages/sentence-changed.json
new file mode 100644
index 0000000000..8d1d957f14
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/messages/sentence-changed.json
@@ -0,0 +1,29 @@
+{
+ "Type": "Notification",
+ "MessageId": "20e13002-d1be-56e7-be8c-66cdd7e23341",
+ "TopicArn": "arn:aws:sns:eu-west-2:754256621582:cloud-platform-Digital-Prison-Services-f221e27fcfcf78f6ab4f4c3cc165eee7",
+ "Message": "{\"eventType\":\"SENTENCE_CHANGED\",\"eventDatetime\":\"2020-02-25T11:24:32.935401\",\"offenderId\":1,\"crn\":\"A000002\",\"sourceId\":\"2500974056\"}",
+ "Timestamp": "2020-02-25T11:25:16.169Z",
+ "SignatureVersion": "1",
+ "Signature": "h5p3FnnbsSHxj53RFePh8HR40cbVvgEZa6XUVTlYs/yuqfDsi17MPA+bX4ijKmmTT2l6xG2xYhcmRAbJWQ4wrwncTBm2azgiwSO5keRNWYVdiC0rI484KLZboP1SDsE+Y7hOU/R0dz49q7+0yd+QIocPteKB/8xG7/6kjGStAZKf3cEdlxOwLhN+7RU1Yk2ENuwAJjVRtvlAa76yKB3xvL2hId7P7ZLmHGlzZDNZNYxbg9C8HGxteOzZ9ZeeQsWDf9jmZ+5+7dKXQoW9LeqwHxEAq2vuwSZ8uwM5JljXbtS5w1P0psXPYNoin2gU1F5MDK8RPzjUtIvjINx08rmEOA==",
+ "SigningCertURL": "https://sns.eu-west-2.amazonaws.com/SimpleNotificationService-a86cb10b4e1f29c941702d737128f7b6.pem",
+ "UnsubscribeURL": "https://sns.eu-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-2:754256621582:cloud-platform-Digital-Prison-Services-f221e27fcfcf78f6ab4f4c3cc165eee7:92545cfe-de5d-43e1-8339-c366bf0172aa",
+ "MessageAttributes": {
+ "eventType": {
+ "Type": "String",
+ "Value": "SENTENCE_CHANGED"
+ },
+ "id": {
+ "Type": "String",
+ "Value": "cb4645f2-d0c1-4677-806a-8036ed54bf69"
+ },
+ "contentType": {
+ "Type": "String",
+ "Value": "text/plain;charset=UTF-8"
+ },
+ "timestamp": {
+ "Type": "Number.java.lang.Long",
+ "Value": "1582629916147"
+ }
+ }
+}
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_1200837.json b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_1200837.json
new file mode 100644
index 0000000000..66589b3f45
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_1200837.json
@@ -0,0 +1,10 @@
+{
+ "bookingId": 1200837,
+ "bookingNo": "48340A",
+ "offenderNo": "A0002DY",
+ "firstName": "Jim",
+ "lastName": "Smith",
+ "agencyId": "MDI",
+ "activeFlag": true,
+ "dateOfBirth": "1970-01-01"
+}
\ No newline at end of file
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_noms_A0002DY.json b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_noms_A0002DY.json
new file mode 100644
index 0000000000..0dc73a2d0c
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/booking_noms_A0002DY.json
@@ -0,0 +1,6 @@
+{
+ "bookingId": 1200837,
+ "bookingNo": "48340A",
+ "offenderNo": "A0002DY",
+ "active": true
+}
\ No newline at end of file
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/sentence_detail_1200837.json b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/sentence_detail_1200837.json
new file mode 100644
index 0000000000..09e064a2db
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/__files/sentence_detail_1200837.json
@@ -0,0 +1,10 @@
+{
+ "bookingId": 1200837,
+ "sentenceExpiryDate": "2025-09-10",
+ "conditionalReleaseDate": "2022-11-25",
+ "conditionalReleaseOverrideDate": "2022-11-26",
+ "licenceExpiryDate": "2025-09-11",
+ "releaseDate": "2022-11-26",
+ "confirmedReleaseDate": "2022-11-27",
+ "homeDetentionCurfewEligibilityDate": "2022-10-28"
+}
\ No newline at end of file
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getBooking_1200837.json b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getBooking_1200837.json
new file mode 100644
index 0000000000..693e8d5d27
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getBooking_1200837.json
@@ -0,0 +1,30 @@
+{
+ "mappings": [
+ {
+ "request": {
+ "method": "GET",
+ "urlPath": "/api/bookings/1200837"
+ },
+ "response": {
+ "status": 200,
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "bodyFileName": "booking_1200837.json"
+ }
+ },
+ {
+ "request": {
+ "method": "GET",
+ "urlPath": "/api/bookings/offenderNo/A0002DY"
+ },
+ "response": {
+ "status": 200,
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "bodyFileName": "booking_noms_A0002DY.json"
+ }
+ }
+ ]
+}
diff --git a/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getSentenceDetail_1200837.json b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getSentenceDetail_1200837.json
new file mode 100644
index 0000000000..8e95c31720
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/dev/resources/simulations/mappings/getSentenceDetail_1200837.json
@@ -0,0 +1,13 @@
+{
+ "request": {
+ "method": "GET",
+ "urlPath": "/api/bookings/1200837/sentenceDetail"
+ },
+ "response": {
+ "status": 200,
+ "headers": {
+ "Content-Type": "application/json"
+ },
+ "bodyFileName": "sentence_detail_1200837.json"
+ }
+}
diff --git a/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
index cf09513d64..a12abe6242 100644
--- a/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
+++ b/projects/custody-key-dates-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
@@ -3,7 +3,6 @@ package uk.gov.justice.digital.hmpps
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Assertions.assertNotNull
-import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyMap
import org.mockito.kotlin.check
@@ -21,11 +20,11 @@ import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.Custody
import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.CustodyDateType
import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.CustodyRepository
import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.contact.ContactRepository
+import uk.gov.justice.digital.hmpps.message.MessageAttributes
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
import uk.gov.justice.digital.hmpps.telemetry.notificationReceived
-import java.time.Duration
import java.time.LocalDate
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
@@ -53,10 +52,10 @@ internal class IntegrationTest {
val notification = Notification(message = MessageGenerator.SENTENCE_DATE_CHANGED)
val first = CompletableFuture.runAsync {
- channelManager.getChannel(queueName).publishAndWait(notification, Duration.ofMinutes(3))
+ channelManager.getChannel(queueName).publishAndWait(notification)
}
val second = CompletableFuture.runAsync {
- channelManager.getChannel(queueName).publishAndWait(notification, Duration.ofMinutes(3))
+ channelManager.getChannel(queueName).publishAndWait(notification)
}
CompletableFuture.allOf(first, second).join()
@@ -83,6 +82,44 @@ internal class IntegrationTest {
)
}
+ @Test
+ fun `Custody Key Dates updated from SENTENCE_CHANGED event`() {
+ val notification = Notification(
+ message = MessageGenerator.SENTENCE_CHANGED,
+ attributes = MessageAttributes(eventType = "SENTENCE_CHANGED")
+ )
+
+ val first = CompletableFuture.runAsync {
+ channelManager.getChannel(queueName).publishAndWait(notification)
+ }
+ val second = CompletableFuture.runAsync {
+ channelManager.getChannel(queueName).publishAndWait(notification)
+ }
+
+ CompletableFuture.allOf(first, second).join()
+
+ verify(telemetryService, times(2)).notificationReceived(notification)
+
+ val custodyId =
+ custodyRepository.findCustodyId(PersonGenerator.PERSON_WITH_KEYDATES_BY_CRN.id, "48340A").first()
+ val custody = custodyRepository.findCustodyById(custodyId)
+ verifyUpdatedKeyDates(custody)
+
+ verify(telemetryService).trackEvent(
+ eq("KeyDatesUpdated"),
+ check {
+ assertThat(it[CustodyDateType.SENTENCE_EXPIRY_DATE.code], equalTo("2025-09-10"))
+ },
+ anyMap()
+ )
+
+ verify(telemetryService).trackEvent(
+ eq("KeyDatesUnchanged"),
+ anyMap(),
+ anyMap()
+ )
+ }
+
private fun verifyUpdatedKeyDates(custody: Custody) {
val sed = custody.keyDate(CustodyDateType.SENTENCE_EXPIRY_DATE.code)
val crd = custody.keyDate(CustodyDateType.AUTOMATIC_CONDITIONAL_RELEASE_DATE.code)
diff --git a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/Person.kt b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/Person.kt
index e6ff77110c..d41de5fd94 100644
--- a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/Person.kt
+++ b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/Person.kt
@@ -15,8 +15,11 @@ class Person(
@Column(name = "offender_id")
val id: Long,
+ @Column(columnDefinition = "char(7)")
+ val crn: String,
+
@Column(name = "NOMS_NUMBER", columnDefinition = "char(7)")
- val nomsId: String,
+ val nomsId: String?,
@Column(updatable = false, columnDefinition = "NUMBER")
val softDeleted: Boolean = false
diff --git a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt
index aa8505cb7c..dbcfb5dbe1 100644
--- a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt
+++ b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/person/PersonRepository.kt
@@ -1,7 +1,12 @@
package uk.gov.justice.digital.hmpps.integrations.delius.person
import org.springframework.data.jpa.repository.JpaRepository
+import org.springframework.data.jpa.repository.Query
interface PersonRepository : JpaRepository {
fun findByNomsIdIgnoreCaseAndSoftDeletedIsFalse(nomsId: String): Person?
+
+ @Query("select p.nomsId from Person p where p.crn = :crn and p.softDeleted = false")
+ fun findNomsIdByCrn(crn: String): String?
}
+
diff --git a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
index 69aa5474e9..d549a62049 100644
--- a/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
+++ b/projects/custody-key-dates-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Handler.kt
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.converter.NotificationConverter
import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.CustodyDateUpdateService
+import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent
import uk.gov.justice.digital.hmpps.message.Notification
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
@@ -20,7 +21,8 @@ import uk.gov.justice.digital.hmpps.telemetry.notificationReceived
class Handler(
override val converter: KeyDateChangedEventConverter,
private val cduService: CustodyDateUpdateService,
- private val telemetryService: TelemetryService
+ private val telemetryService: TelemetryService,
+ private val personRepository: PersonRepository
) : NotificationHandler {
@Publish(
messages = [
@@ -30,6 +32,7 @@ class Handler(
Message(messageId = "CONFIRMED_RELEASE_DATE-CHANGED", payload = Schema(CustodyDateChanged::class)),
Message(messageId = "KEY_DATE_ADJUSTMENT_UPSERTED", payload = Schema(CustodyDateChanged::class)),
Message(messageId = "KEY_DATE_ADJUSTMENT_DELETED", payload = Schema(CustodyDateChanged::class)),
+ Message(messageId = "SENTENCE_CHANGED", payload = Schema(ProbationOffenderEvent::class)),
]
)
override fun handle(notification: Notification) {
@@ -39,12 +42,22 @@ class Handler(
?.let { cduService.updateCustodyKeyDates(it) }
is CustodyDateChanged -> cduService.updateCustodyKeyDates(message.bookingId)
+ is ProbationOffenderEvent -> when (notification.eventType) {
+ "SENTENCE_CHANGED",
+ -> personRepository.findNomsIdByCrn(message.crn)?.let { cduService.updateCustodyKeyDates(it) }
+
+ else -> throw IllegalArgumentException("Unexpected offender event type: ${notification.eventType}")
+ }
}
}
}
+@Message
data class CustodyDateChanged(val bookingId: Long)
+@Message
+data class ProbationOffenderEvent(val crn: String)
+
@Primary
@Component
class KeyDateChangedEventConverter(objectMapper: ObjectMapper) : NotificationConverter(objectMapper) {
@@ -59,6 +72,12 @@ class KeyDateChangedEventConverter(objectMapper: ObjectMapper) : NotificationCon
attributes = stringMessage.attributes
)
}
+ if (json.has("crn")) {
+ return Notification(
+ message = objectMapper.readValue(stringMessage.message, ProbationOffenderEvent::class.java),
+ attributes = stringMessage.attributes
+ )
+ }
return Notification(
message = objectMapper.readValue(stringMessage.message, HmppsDomainEvent::class.java),
attributes = stringMessage.attributes
diff --git a/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateServiceTest.kt b/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateServiceTest.kt
index 6fbbb65af1..84b609fdd7 100644
--- a/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateServiceTest.kt
+++ b/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/integrations/delius/custody/date/CustodyDateUpdateServiceTest.kt
@@ -74,7 +74,7 @@ internal class CustodyDateUpdateServiceTest {
@Test
fun `Multiple matching custody logged to telemetry`() {
- val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId)
+ val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId!!)
whenever(prisonApi.getSentenceDetail(booking.id)).thenReturn(SentenceDetail())
whenever(prisonApi.getBooking(booking.id, basicInfo = false, extraInfo = true)).thenReturn(booking)
@@ -93,7 +93,7 @@ internal class CustodyDateUpdateServiceTest {
@Test
fun `No matching custody logged to telemetry`() {
- val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId)
+ val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId!!)
whenever(prisonApi.getSentenceDetail(booking.id)).thenReturn(SentenceDetail())
whenever(prisonApi.getBooking(booking.id, basicInfo = false, extraInfo = true)).thenReturn(booking)
@@ -111,7 +111,7 @@ internal class CustodyDateUpdateServiceTest {
@Test
fun `key date save and delete not called without appropriate key dates`() {
- val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId)
+ val booking = Booking(127, "FG37K", true, PersonGenerator.DEFAULT.nomsId!!)
val custody = SentenceGenerator.generateCustodialSentence(
disposal = SentenceGenerator.generateDisposal(SentenceGenerator.generateEvent()),
bookingRef = booking.bookingNo
diff --git a/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt b/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt
new file mode 100644
index 0000000000..2dbce8cc57
--- /dev/null
+++ b/projects/custody-key-dates-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/HandlerTest.kt
@@ -0,0 +1,47 @@
+package uk.gov.justice.digital.hmpps.messaging
+
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+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 uk.gov.justice.digital.hmpps.data.generator.MessageGenerator
+import uk.gov.justice.digital.hmpps.integrations.delius.custody.date.CustodyDateUpdateService
+import uk.gov.justice.digital.hmpps.integrations.delius.person.PersonRepository
+import uk.gov.justice.digital.hmpps.message.MessageAttributes
+import uk.gov.justice.digital.hmpps.message.Notification
+import uk.gov.justice.digital.hmpps.telemetry.TelemetryService
+
+@ExtendWith(MockitoExtension::class)
+internal class HandlerTest {
+
+ @Mock
+ lateinit var converter: KeyDateChangedEventConverter
+
+ @Mock
+ lateinit var telemetryService: TelemetryService
+
+ @Mock
+ lateinit var personRepository: PersonRepository
+
+ @Mock
+ lateinit var cduService: CustodyDateUpdateService
+
+ lateinit var handler: Handler
+
+ @Test
+ fun `handles unexpected event type`() {
+ handler = Handler(converter, cduService, telemetryService, personRepository)
+ val exception = assertThrows {
+ handler.handle(
+ Notification(
+ message = MessageGenerator.SENTENCE_CHANGED,
+ attributes = MessageAttributes(eventType = "UNKNOWN")
+ )
+ )
+ }
+ assertThat(exception.message, equalTo("Unexpected offender event type: UNKNOWN"))
+ }
+}