generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added notifier to publish sns messages (probation-case.engagement.created) when insert person is performed
- Loading branch information
1 parent
f378f0d
commit b838293
Showing
8 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...on-platform-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/messaging/Notifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package uk.gov.justice.digital.hmpps.messaging | ||
|
||
import org.openfolder.kotlinasyncapi.annotation.Schema | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Channel | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Message | ||
import org.openfolder.kotlinasyncapi.annotation.channel.Subscribe | ||
import org.springframework.beans.factory.annotation.Qualifier | ||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Person | ||
import uk.gov.justice.digital.hmpps.message.* | ||
import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher | ||
|
||
@Service | ||
@Channel("hmpps-domain-events-topic") | ||
class Notifier( | ||
@Qualifier("topicPublisher") private val topicPublisher: NotificationPublisher, | ||
) { | ||
@Subscribe( | ||
messages = [ | ||
Message(title = "probation-case.engagement.created", payload = Schema(HmppsDomainEvent::class)) | ||
] | ||
) | ||
fun caseCreated(person: Person) { | ||
topicPublisher.publish( | ||
Notification( | ||
message = HmppsDomainEvent( | ||
version = 1, | ||
eventType = "probation-case.engagement.created", | ||
description = "A probation case record for a person has been created in Delius", | ||
personReference = PersonReference( | ||
identifiers = listOf( | ||
PersonIdentifier("CRN", person.crn), | ||
), | ||
), | ||
), | ||
attributes = MessageAttributes("probation-case.engagement.created") | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...latform-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/messaging/NotifierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.gov.justice.digital.hmpps.messaging | ||
|
||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.* | ||
import org.springframework.boot.test.system.CapturedOutput | ||
import org.springframework.boot.test.system.OutputCaptureExtension | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.message.Notification | ||
import uk.gov.justice.digital.hmpps.publisher.NotificationPublisher | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
@ExtendWith(OutputCaptureExtension::class) | ||
class NotifierTest { | ||
@Mock | ||
lateinit var topicPublisher: NotificationPublisher | ||
|
||
lateinit var notifier: Notifier | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
notifier = Notifier(topicPublisher) | ||
} | ||
|
||
@Test | ||
fun `test notification`(output: CapturedOutput) { | ||
doNothing().whenever(topicPublisher).publish(any<Notification<*>>()) | ||
notifier.caseCreated(PersonGenerator.DEFAULT) | ||
verify(topicPublisher, times(1)).publish(any<Notification<*>>()) | ||
verifyNoMoreInteractions(topicPublisher) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters