Skip to content

Commit

Permalink
PI-1957 - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-britton-moj committed Mar 8, 2024
1 parent 7fe979a commit 9529553
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Order
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestMethodOrder
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
Expand Down Expand Up @@ -67,7 +64,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("SuccessfulMatch"))
assertThat(
Expand All @@ -77,7 +74,8 @@ internal class NomsNumberIntegrationTest {
"existingNomsId" to "E1234XS",
"custodialEvents" to "1",
"matchedNomsId" to "E1234XS",
"matchedBookingNumber" to "76543A"
"matchedBookingNumber" to "76543A",
"dryRun" to "true"
)
)
)
Expand All @@ -94,7 +92,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("SuccessfulMatch"))
assertThat(
Expand All @@ -105,7 +103,8 @@ internal class NomsNumberIntegrationTest {
"matchedNomsId" to "G5541UN",
"matchedBookingNumber" to "13831A",
"matchedSentenceDate" to "2022-12-12",
"sentenceDate" to "2022-12-12"
"sentenceDate" to "2022-12-12",
"dryRun" to "false"
)
)
)
Expand All @@ -122,7 +121,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("SuccessfulMatch"))
assertThat(
Expand All @@ -133,13 +132,11 @@ internal class NomsNumberIntegrationTest {
"matchedNomsId" to "G5541WW",
"matchedBookingNumber" to "13831A",
"matchedSentenceDate" to "2022-12-12",
"sentenceDate" to "2022-12-12"
"sentenceDate" to "2022-12-12",
"dryRun" to "true"
)
)
)

verify(personRepository, never()).save(any())
verify(custodyRepository, never()).save(any())
}

@Test
Expand All @@ -154,7 +151,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("SuccessfulMatch"))
assertThat(
Expand All @@ -165,7 +162,8 @@ internal class NomsNumberIntegrationTest {
"matchedNomsId" to "G5541WW",
"matchedBookingNumber" to "13831A",
"matchedSentenceDate" to "2022-12-12",
"sentenceDate" to "2022-12-12"
"sentenceDate" to "2022-12-12",
"dryRun" to "false"
)
)
)
Expand All @@ -185,7 +183,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("UnsuccessfulMatch"))
assertThat(
Expand All @@ -194,8 +192,9 @@ internal class NomsNumberIntegrationTest {
"crn" to "A000004",
"custodialEvents" to "1",
"sentenceDates" to "2022-12-12",
"G5541WW" to "DateOfBirth:NONE",
"A1234YZ" to "Name:PARTIAL, DateOfBirth:NONE"
"G5541WW" to "DateOfBirth:INCONCLUSIVE",
"A1234YZ" to "Name:PARTIAL, DateOfBirth:INCONCLUSIVE",
"dryRun" to "true"
)
)
)
Expand All @@ -212,7 +211,7 @@ internal class NomsNumberIntegrationTest {

val nameCapture = argumentCaptor<String>()
val propertyCaptor = argumentCaptor<Map<String, String>>()
verify(telemetryService).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())
verify(telemetryService, timeout(5000)).trackEvent(nameCapture.capture(), propertyCaptor.capture(), any())

assertThat(nameCapture.firstValue, equalTo("SuccessfulMatch"))
assertThat(
Expand All @@ -223,7 +222,8 @@ internal class NomsNumberIntegrationTest {
"matchedNomsId" to "G5541UN",
"matchedBookingNumber" to "13831A",
"matchedSentenceDate" to "2022-12-12",
"sentenceDate" to "2022-12-12"
"sentenceDate" to "2022-12-12",
"dryRun" to "true"
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ class MatchingController(private val matchingService: MatchingService) {
fun populateNomsNumbers(
@RequestParam(defaultValue = "true") trialOnly: Boolean,
@Size(min = 1, max = 500, message = "Please provide between 1 and 500 crns") @RequestBody crns: List<String>?
) = matchingService.matchWithPrisonData(crns ?: listOf(), trialOnly)
) {
Thread.ofVirtual().start { matchingService.matchWithPrisonData(crns ?: listOf(), trialOnly) }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package uk.gov.justice.digital.hmpps.sevice

import jakarta.persistence.EntityManager
import jakarta.persistence.EntityManagerFactory
import org.hibernate.SessionFactory
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.integrations.delius.entity.Custody
import uk.gov.justice.digital.hmpps.integrations.delius.entity.PersonRepository
Expand All @@ -16,7 +19,8 @@ class MatchingService(
private val personRepository: PersonRepository,
private val matcher: Matcher,
private val matchWriter: MatchWriter,
private val telemetryService: TelemetryService
private val telemetryService: TelemetryService,
private val entityManager: EntityManager
) {

fun matchWithPrisonData(crns: List<String>, trialOnly: Boolean) {
Expand All @@ -41,6 +45,8 @@ class MatchingService(
val matchingSentence = personMatch.person.events.filter {
it.disposal?.custody != null && matchedPrisoner?.sentenceStartDate?.withinDays(it.disposal.startDate) == true
}
// temporary for testing memory issue
entityManager.clear()
return when {
matchedPrisoner != null -> CompletedMatch.Successful(
personMatch,
Expand Down

0 comments on commit 9529553

Please sign in to comment.