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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b250b0a
commit 5eb2bbc
Showing
31 changed files
with
650 additions
and
0 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
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
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
13 changes: 13 additions & 0 deletions
13
...rc/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/BusinessInteractionGenerator.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,13 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.audit.BusinessInteraction | ||
import uk.gov.justice.digital.hmpps.integrations.delius.audit.BusinessInteractionCode | ||
import java.time.ZonedDateTime | ||
|
||
object BusinessInteractionGenerator { | ||
val UPDATE_CONTACT = BusinessInteraction( | ||
IdGenerator.getAndIncrement(), | ||
BusinessInteractionCode.UPDATE_CONTACT.code, | ||
ZonedDateTime.now().minusMonths(6) | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ContactTypeGenerator.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,11 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.CaseNoteType | ||
|
||
object ContactTypeGenerator { | ||
val CONTACT_TYPE = CaseNoteType( | ||
IdGenerator.getAndIncrement(), | ||
"C294", | ||
false | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteGenerator.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,20 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.CaseNote | ||
import java.time.ZonedDateTime | ||
|
||
object CourtCaseNoteGenerator { | ||
val CASE_NOTE = CaseNote( | ||
IdGenerator.getAndIncrement(), | ||
"2222", | ||
PersonGenerator.CURRENTLY_MANAGED.id, | ||
ContactTypeGenerator.CONTACT_TYPE, | ||
"Existing notes", | ||
ZonedDateTime.now(), | ||
ZonedDateTime.now(), | ||
StaffGenerator.ALLOCATED.id, | ||
StaffGenerator.ALLOCATED.id, | ||
1, | ||
1 | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
...c/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/CourtCaseNoteMessageGenerator.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,10 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent | ||
import uk.gov.justice.digital.hmpps.resourceloader.ResourceLoader | ||
|
||
object CourtCaseNoteMessageGenerator { | ||
val EXISTS: HmppsDomainEvent = ResourceLoader.message("existing-court-case-note") | ||
val NEW: HmppsDomainEvent = ResourceLoader.message("new-court-case-note") | ||
val NOT_FOUND: HmppsDomainEvent = ResourceLoader.message("court-case-note-not-found") | ||
} |
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
12 changes: 12 additions & 0 deletions
12
projects/court-case-and-delius/src/dev/resources/messages/court-case-note-not-found.json
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,12 @@ | ||
{ | ||
"MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", | ||
"Type": "Notification", | ||
"Timestamp": "2019-10-21T14:01:18.500Z", | ||
"Message": "{\"eventType\":\"court-case-note.published\",\"version\":1,\"description\":\"A court case note has been created or amended\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/court-case-notes/3333\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"AA123456\"}]}}", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "court-case-note.published" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/court-case-and-delius/src/dev/resources/messages/existing-court-case-note.json
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,12 @@ | ||
{ | ||
"MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", | ||
"Type": "Notification", | ||
"Timestamp": "2019-10-21T14:01:18.500Z", | ||
"Message": "{\"eventType\":\"court-case-note.published\",\"version\":1,\"description\":\"A court case note has been created or amended\",\"occurredAt\":\"2023-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/court-case-notes/2222\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"C123456\"}]}}", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "court-case-note.published" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/court-case-and-delius/src/dev/resources/messages/new-court-case-note.json
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,12 @@ | ||
{ | ||
"MessageId": "ae06c49e-1f41-4b9f-b2f2-dcca610d02cd", | ||
"Type": "Notification", | ||
"Timestamp": "2019-10-21T14:01:18.500Z", | ||
"Message": "{\"eventType\":\"court-case-note.published\",\"version\":1,\"description\":\"A court case note has been created or amended\",\"occurredAt\":\"2022-10-18T08:19:19.451579+01:00\",\"detailUrl\":\"http://localhost:{wiremock.port}/court-case-notes/1111\",\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"N123456\"}]}}", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "court-case-note.published" | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...t-case-and-delius/src/dev/resources/simulations/__files/get-existing-court-case-note.json
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,4 @@ | ||
{ | ||
"reference": "2222", | ||
"notes": "Overwritten the existing notes about the court case." | ||
} |
4 changes: 4 additions & 0 deletions
4
.../court-case-and-delius/src/dev/resources/simulations/__files/get-new-court-case-note.json
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,4 @@ | ||
{ | ||
"reference": "1111", | ||
"notes": "Some new notes about the court case." | ||
} |
48 changes: 48 additions & 0 deletions
48
...cts/court-case-and-delius/src/dev/resources/simulations/mappings/get-court-case-note.json
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,48 @@ | ||
{ | ||
"mappings": [ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/court-case-notes/1111" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200, | ||
"bodyFileName": "get-new-court-case-note.json" | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/court-case-notes/2222" | ||
}, | ||
"response": { | ||
"headers": { | ||
"Accept": "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200, | ||
"bodyFileName": "get-existing-court-case-note.json" | ||
} | ||
}, | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/court-case-notes/3333" | ||
}, | ||
"response": { | ||
"status": 404, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"status": 404, | ||
"userMessage": "Resource with id [3333] not found.", | ||
"developerMessage": "Resource with id [3333] not found." | ||
} | ||
} | ||
} | ||
] | ||
} |
81 changes: 81 additions & 0 deletions
81
.../src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/CourtCaseNotesIntegrationTest.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,81 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.MatcherAssert | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.ArgumentMatchers.anyMap | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.verify | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.boot.test.mock.mockito.SpyBean | ||
import uk.gov.justice.digital.hmpps.audit.repository.AuditedInteractionRepository | ||
import uk.gov.justice.digital.hmpps.data.generator.CourtCaseNoteMessageGenerator | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.delius.repository.CaseNoteRepository | ||
import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
import java.time.ZonedDateTime | ||
|
||
const val COURT_CASE_NOTE_MERGED = "CourtCaseNoteMerged" | ||
|
||
@SpringBootTest | ||
class CaseNotesIntegrationTest { | ||
|
||
@Value("\${messaging.consumer.queue}") | ||
private lateinit var queueName: String | ||
|
||
@Autowired | ||
private lateinit var channelManager: HmppsChannelManager | ||
|
||
@Autowired | ||
private lateinit var caseNoteRepository: CaseNoteRepository | ||
|
||
@MockBean | ||
private lateinit var telemetryService: TelemetryService | ||
|
||
@Autowired | ||
lateinit var wireMockserver: WireMockServer | ||
|
||
@SpyBean | ||
lateinit var air: AuditedInteractionRepository | ||
|
||
@Test | ||
fun `create a new court case note succesfully`() { | ||
channelManager.getChannel(queueName).publishAndWait( | ||
prepMessage(CourtCaseNoteMessageGenerator.NEW, wireMockserver.port()) | ||
) | ||
|
||
val caseNote = caseNoteRepository.findByExternalReferenceAndOffenderIdAndSoftDeletedIsFalse("1111", PersonGenerator.NEW_TO_PROBATION.id) | ||
MatcherAssert.assertThat(caseNote!!.notes, Matchers.equalTo("Some new notes about the court case.")) | ||
|
||
verify(telemetryService).trackEvent(eq(COURT_CASE_NOTE_MERGED), anyMap(), anyMap()) | ||
} | ||
|
||
@Test | ||
fun `replace a court case note succesfully`() { | ||
val message = CourtCaseNoteMessageGenerator.EXISTS.copy(occurredAt = ZonedDateTime.now()) | ||
|
||
channelManager.getChannel(queueName).publishAndWait( | ||
prepMessage(message, wireMockserver.port()) | ||
) | ||
|
||
val caseNote = caseNoteRepository.findByExternalReferenceAndOffenderIdAndSoftDeletedIsFalse("2222", PersonGenerator.CURRENTLY_MANAGED.id) | ||
MatcherAssert.assertThat(caseNote!!.notes, Matchers.equalTo("Overwritten the existing notes about the court case.")) | ||
|
||
verify(telemetryService).trackEvent(eq(COURT_CASE_NOTE_MERGED), anyMap(), anyMap()) | ||
} | ||
|
||
@Test | ||
fun `court case note not found - noop`() { | ||
channelManager.getChannel(queueName).publishAndWait( | ||
prepMessage(CourtCaseNoteMessageGenerator.NOT_FOUND, wireMockserver.port()) | ||
) | ||
|
||
verify(telemetryService, never()).trackEvent(eq(COURT_CASE_NOTE_MERGED), anyMap(), anyMap()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...nd-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/api/config/CourtCaseFeignConfig.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,15 @@ | ||
package uk.gov.justice.digital.hmpps.api.config | ||
|
||
import org.springframework.cloud.openfeign.EnableFeignClients | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager | ||
import uk.gov.justice.digital.hmpps.config.feign.FeignConfig | ||
import uk.gov.justice.digital.hmpps.integrations.courtcase.CourtCaseClient | ||
|
||
@Configuration | ||
@EnableFeignClients(clients = [CourtCaseClient::class]) | ||
class CourtCaseFeignConfig( | ||
authorizedClientManager: OAuth2AuthorizedClientManager | ||
) : FeignConfig(authorizedClientManager) { | ||
override fun registrationId() = "court-case-and-delius" | ||
} |
11 changes: 11 additions & 0 deletions
11
...us/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/courtcase/CourtCaseClient.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,11 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.courtcase | ||
|
||
import org.springframework.cloud.openfeign.FeignClient | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import java.net.URI | ||
|
||
@FeignClient(name = "court-case", url = "https://dummy-url/to/be/overridden") | ||
interface CourtCaseClient { | ||
@GetMapping | ||
fun getCourtCaseNote(baseUrl: URI): CourtCaseNote? | ||
} |
6 changes: 6 additions & 0 deletions
6
...lius/src/main/kotlin/uk/gov/justice/digital/hmpps/integrations/courtcase/CourtCaseNote.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,6 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.courtcase | ||
|
||
data class CourtCaseNote( | ||
val reference: String, | ||
val notes: String | ||
) |
7 changes: 7 additions & 0 deletions
7
.../kotlin/uk/gov/justice/digital/hmpps/integrations/delius/audit/BusinessInteractionCode.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,7 @@ | ||
package uk.gov.justice.digital.hmpps.integrations.delius.audit | ||
|
||
import uk.gov.justice.digital.hmpps.audit.InteractionCode | ||
|
||
enum class BusinessInteractionCode(override val code: String) : InteractionCode { | ||
UPDATE_CONTACT("CLBI007") | ||
} |
Oops, something went wrong.