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.
- Loading branch information
1 parent
b4db13e
commit 7d6f2f3
Showing
24 changed files
with
864 additions
and
173 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
8 changes: 0 additions & 8 deletions
8
...and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/MessageGenerator.kt
This file was deleted.
Oops, something went wrong.
25 changes: 23 additions & 2 deletions
25
...-and-delius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/PersonGenerator.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 |
---|---|---|
@@ -1,11 +1,32 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.Event | ||
import uk.gov.justice.digital.hmpps.integrations.delius.Person | ||
import uk.gov.justice.digital.hmpps.integrations.delius.PersonManager | ||
|
||
object PersonGenerator { | ||
val DEFAULT_PERSON = generatePerson("A000001") | ||
val PERSON_OPD_NEW = generatePerson("A000001") | ||
val PERSON_MANAGER = generatePersonManager(PERSON_OPD_NEW) | ||
fun generatePerson( | ||
crn: String, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Person(id, crn) | ||
) = Person(crn, softDeleted, id) | ||
|
||
fun generatePersonManager( | ||
person: Person, | ||
providerId: Long = IdGenerator.getAndIncrement(), | ||
teamId: Long = IdGenerator.getAndIncrement(), | ||
staffId: Long = IdGenerator.getAndIncrement(), | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = PersonManager(person, providerId, teamId, staffId, active, softDeleted, id) | ||
|
||
fun generateEvent( | ||
person: Person, | ||
active: Boolean = true, | ||
softDeleted: Boolean = false, | ||
id: Long = IdGenerator.getAndIncrement() | ||
) = Event(person, active, softDeleted, id) | ||
} |
32 changes: 32 additions & 0 deletions
32
...lius/src/dev/kotlin/uk/gov/justice/digital/hmpps/data/generator/ReferenceDataGenerator.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,32 @@ | ||
package uk.gov.justice.digital.hmpps.data.generator | ||
|
||
import uk.gov.justice.digital.hmpps.integrations.delius.Dataset | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiStatus | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiSubType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType | ||
|
||
object ReferenceDataGenerator { | ||
val DS_NSI_SUB_TYPE = generateDataset(Dataset.NSI_SUB_TYPE) | ||
val CONTACT_TYPES = ContactType.Code.entries.map { generateContactType(it.value) }.associateBy { it.code } | ||
val NSI_TYPES = NsiType.Code.entries.map { generateType(it.value) }.associateBy { it.code } | ||
val NSI_SUBTYPES = NsiSubType.Code.entries.map { generateSubType(it.value) }.associateBy { it.code } | ||
val NSI_STATUSES = NsiStatus.Code.entries.map { sc -> | ||
generateStatus( | ||
sc.value, | ||
sc.contactTypeCode?.value?.let { CONTACT_TYPES[it] } | ||
) | ||
}.associateBy { it.code } | ||
|
||
fun generateDataset(code: String, id: Long = IdGenerator.getAndIncrement()) = Dataset(code, id) | ||
fun generateContactType(code: String, id: Long = IdGenerator.getAndIncrement()) = ContactType(code, id) | ||
fun generateType(code: String, id: Long = IdGenerator.getAndIncrement()) = NsiType(code, id) | ||
fun generateSubType(code: String, id: Long = IdGenerator.getAndIncrement()) = | ||
NsiSubType(code, DS_NSI_SUB_TYPE.id, id) | ||
|
||
fun generateStatus(code: String, contactType: ContactType?, id: Long = IdGenerator.getAndIncrement()) = | ||
NsiStatus(code, contactType, id) | ||
|
||
fun all() = | ||
listOf(DS_NSI_SUB_TYPE) + CONTACT_TYPES.values + NSI_TYPES.values + NSI_SUBTYPES.values + NSI_STATUSES.values | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/opd-and-delius/src/dev/resources/messages/opd-assessment-new.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 @@ | ||
{ | ||
"Type": "Notification", | ||
"MessageId": "f39059e7-a62d-4157-929a-fb049015c993", | ||
"Message": "{\"eventType\":\"opd.produced\",\"version\":\"2\",\"description\":\"OPD Assessment\",\"occurredAt\":\"2023-10-30T16:42:25+00:00\",\"detailUrl\":null,\"additionalInformation\":{\"dateCompleted\":\"2023-10-30T16:42:25+00:00\", \"opdResult\":\"SCREENED IN\", \"opdScreenOutOverride\": \"\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"A000001\"}]}}", | ||
"Timestamp": "2023-10-30T16:42:25+00:00", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "opd.produced" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
projects/opd-and-delius/src/dev/resources/messages/opd-assessment-update.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,13 @@ | ||
{ | ||
"Type": "Notification", | ||
"MessageId": "f39059e7-a62d-4157-929a-fb049015c993", | ||
"TopicArn": "arn:aws:sns:eu-west-2:000000000000:hmpps-domain", | ||
"Message": "{\"eventType\":\"opd.produced\",\"version\":\"2\",\"description\":\"OPD Assessment\",\"occurredAt\":\"2023-10-31T13:42:25+01:00\",\"detailUrl\":null,\"additionalInformation\":{\"dateCompleted\":\"2023-10-31T13:42:25+01:00\", \"opdResult\":\"SCREENED IN\", \"opdScreenOutOverride\": \"YES\"},\"personReference\":{\"identifiers\":[{\"type\":\"CRN\",\"value\":\"A000001\"}]}}", | ||
"Timestamp": "2023-10-31T13:42:25Z", | ||
"MessageAttributes": { | ||
"eventType": { | ||
"Type": "String", | ||
"Value": "opd.produced" | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
projects/opd-and-delius/src/dev/resources/messages/opd-assessment.json
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
projects/opd-and-delius/src/dev/resources/simulations/__files/get-opd-assessment.json
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
projects/opd-and-delius/src/dev/resources/simulations/mappings/opdAssessment.json
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
...opd-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt
This file was deleted.
Oops, something went wrong.
143 changes: 143 additions & 0 deletions
143
...-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/OpdIntegrationTest.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,143 @@ | ||
package uk.gov.justice.digital.hmpps | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.containsString | ||
import org.hamcrest.Matchers.equalTo | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
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.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 uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.delius.EventRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiStatus | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiSubType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.NsiType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.PersonManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.contact.entity.ContactType | ||
import uk.gov.justice.digital.hmpps.integrations.delius.getByCrn | ||
import uk.gov.justice.digital.hmpps.messaging.HmppsChannelManager | ||
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService | ||
import uk.gov.justice.digital.hmpps.test.CustomMatchers.isCloseTo | ||
import java.time.ZonedDateTime | ||
|
||
@SpringBootTest | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation::class) | ||
internal class OpdIntegrationTest { | ||
@Value("\${messaging.consumer.queue}") | ||
lateinit var queueName: String | ||
|
||
@Autowired | ||
lateinit var channelManager: HmppsChannelManager | ||
|
||
@MockBean | ||
lateinit var telemetryService: TelemetryService | ||
|
||
@Autowired | ||
lateinit var wireMockServer: WireMockServer | ||
|
||
@Autowired | ||
lateinit var personManagerRepository: PersonManagerRepository | ||
|
||
@Autowired | ||
lateinit var nsiRepository: NsiRepository | ||
|
||
@Autowired | ||
lateinit var nsiManagerRepository: NsiManagerRepository | ||
|
||
@Autowired | ||
lateinit var contactRepository: ContactRepository | ||
|
||
@Autowired | ||
lateinit var eventRepository: EventRepository | ||
|
||
@Order(1) | ||
@Test | ||
fun `process opd assessment`() { | ||
val message = prepMessage("opd-assessment-new", wireMockServer.port()) | ||
|
||
channelManager.getChannel(queueName).publishAndWait(message) | ||
|
||
val com = personManagerRepository.getByCrn(PersonGenerator.PERSON_OPD_NEW.crn) | ||
val nsi = nsiRepository.findNsiByPersonIdAndTypeCode(com.person.id, NsiType.Code.OPD_COMMUNITY_PATHWAY.value) | ||
assertNotNull(nsi!!) | ||
assertThat(nsi.type.code, equalTo(NsiType.Code.OPD_COMMUNITY_PATHWAY.value)) | ||
assertThat(nsi.subType?.code, equalTo(NsiSubType.Code.COMMUNITY_PATHWAY.value)) | ||
assertThat(nsi.status.code, equalTo(NsiStatus.Code.READY_FOR_SERVICE.value)) | ||
|
||
val nsiManager = nsiManagerRepository.findAll().firstOrNull { it.nsi.id == nsi.id } | ||
assertNotNull(nsiManager!!) | ||
assertThat(nsiManager.teamId, equalTo(com.teamId)) | ||
assertThat(nsiManager.staffId, equalTo(com.staffId)) | ||
|
||
val opdContact = contactRepository.findAll() | ||
.firstOrNull { it.personId == com.person.id && it.type.code == ContactType.Code.READY_FOR_SERVICES.value } | ||
assertNotNull(opdContact!!) | ||
|
||
verify(telemetryService).trackEvent( | ||
"OpdAssessmentScreenedIn", | ||
mapOf( | ||
"crn" to PersonGenerator.PERSON_OPD_NEW.crn, | ||
"date" to "30/10/2023 16:42:25", | ||
"result" to "Screened In" | ||
) | ||
) | ||
} | ||
|
||
@Order(2) | ||
@Test | ||
fun `process update to opd assessment`() { | ||
val message = prepMessage("opd-assessment-update", wireMockServer.port()) | ||
|
||
channelManager.getChannel(queueName).publishAndWait(message) | ||
|
||
val com = personManagerRepository.getByCrn(PersonGenerator.PERSON_OPD_NEW.crn) | ||
val nsi = nsiRepository.findNsiByPersonIdAndTypeCode(com.person.id, NsiType.Code.OPD_COMMUNITY_PATHWAY.value) | ||
assertNotNull(nsi!!) | ||
assertThat( | ||
nsi.notes, | ||
containsString( | ||
""" | ||
|OPD Assessment Date: 31/10/2023 13:42:25 | ||
|OPD Result: Screened In - with override | ||
|This note was automatically created by the system | ||
""".trimMargin() | ||
) | ||
) | ||
|
||
val opdContact = contactRepository.findAll() | ||
.firstOrNull { it.personId == com.person.id && it.type.code == ContactType.Code.READY_FOR_SERVICES.value } | ||
assertNotNull(opdContact!!) | ||
} | ||
|
||
@Order(3) | ||
@Test | ||
fun `end opd assessment if event terminated`() { | ||
val com = personManagerRepository.getByCrn(PersonGenerator.PERSON_OPD_NEW.crn) | ||
|
||
// create terminated event for this test and remove existing active one | ||
val event = eventRepository.findAll().firstOrNull { it.person.id == com.person.id }!! | ||
eventRepository.deleteById(event.id) | ||
eventRepository.save(PersonGenerator.generateEvent(com.person, active = false)) | ||
|
||
val message = prepMessage("opd-assessment-update", wireMockServer.port()) | ||
|
||
channelManager.getChannel(queueName).publishAndWait(message) | ||
|
||
val nsi = nsiRepository.findNsiByPersonIdAndTypeCode(com.person.id, NsiType.Code.OPD_COMMUNITY_PATHWAY.value) | ||
assertNotNull(nsi!!) | ||
assertThat( | ||
nsi.actualEndDate!!, | ||
isCloseTo(ZonedDateTime.now()) | ||
) | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
...s/opd-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/config/FeignOAuth2Config.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.