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
7480270
commit 7fb7714
Showing
8 changed files
with
259 additions
and
22 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
65 changes: 65 additions & 0 deletions
65
...licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandlerTest.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,65 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
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.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.converter.NotificationConverter | ||
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent | ||
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 CvlHandlerTest { | ||
@Mock | ||
internal lateinit var converter: NotificationConverter<HmppsDomainEvent> | ||
|
||
@Mock | ||
internal lateinit var telemetryService: TelemetryService | ||
|
||
@Mock | ||
internal lateinit var licenceActivatedHandler: LicenceActivatedHandler | ||
|
||
@InjectMocks | ||
internal lateinit var handler: CvlHandler | ||
|
||
@Test | ||
fun `unexpected event types are ignored`() { | ||
val notification = Notification( | ||
HmppsDomainEvent("unknown.type.event-type", 1), | ||
MessageAttributes("unknown.type.event-type") | ||
) | ||
|
||
handler.handle(notification) | ||
|
||
verify(telemetryService).trackEvent( | ||
"UnexpectedEventType", | ||
mapOf("eventType" to "unknown.type.event-type"), | ||
mapOf() | ||
) | ||
} | ||
|
||
@Test | ||
fun `action results with failure throw exception`() { | ||
val notification = Notification( | ||
HmppsDomainEvent(DomainEventType.LicenceActivated.name, 1), | ||
MessageAttributes(DomainEventType.LicenceActivated.name) | ||
) | ||
|
||
whenever(licenceActivatedHandler.licenceActivated(any())) | ||
.thenReturn(listOf(ActionResult.Failure(RuntimeException("Unknown Exception Happened")))) | ||
|
||
val ex = assertThrows<RuntimeException> { | ||
handler.handle(notification) | ||
} | ||
assertThat(ex.message, equalTo("Unknown Exception Happened")) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...elius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceActivatedHandlerTest.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,73 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.equalTo | ||
import org.hamcrest.Matchers.instanceOf | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.exception.NotFoundException | ||
import uk.gov.justice.digital.hmpps.integrations.cvl.CvlClient | ||
import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent | ||
import uk.gov.justice.digital.hmpps.message.PersonIdentifier | ||
import uk.gov.justice.digital.hmpps.message.PersonReference | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
internal class LicenceActivatedHandlerTest { | ||
@Mock | ||
internal lateinit var cvlClient: CvlClient | ||
|
||
@Mock | ||
internal lateinit var lca: LicenceConditionApplier | ||
|
||
@InjectMocks | ||
internal lateinit var lah: LicenceActivatedHandler | ||
|
||
@Test | ||
fun `exception returned when crn not found in message`() { | ||
val event = HmppsDomainEvent(DomainEventType.LicenceActivated.name, 1) | ||
val res = lah.licenceActivated(event).first() | ||
assertThat(res, instanceOf(ActionResult.Failure::class.java)) | ||
val fail = res as ActionResult.Failure | ||
assertThat(fail.exception, instanceOf(IllegalArgumentException::class.java)) | ||
assertThat(fail.exception.message, equalTo("No CRN Provided")) | ||
} | ||
|
||
@Test | ||
fun `exception returned when detail url not found in message`() { | ||
val event = HmppsDomainEvent( | ||
DomainEventType.LicenceActivated.name, | ||
1, | ||
personReference = PersonReference(listOf(PersonIdentifier("CRN", "X123456"))) | ||
) | ||
val res = lah.licenceActivated(event).first() | ||
assertThat(res, instanceOf(ActionResult.Failure::class.java)) | ||
val fail = res as ActionResult.Failure | ||
assertThat(fail.exception, instanceOf(IllegalArgumentException::class.java)) | ||
assertThat(fail.exception.message, equalTo("No Detail Url Provided")) | ||
} | ||
|
||
@Test | ||
fun `exception returned when activated licence not found`() { | ||
val event = HmppsDomainEvent( | ||
DomainEventType.LicenceActivated.name, | ||
1, | ||
detailUrl = "https://cvl.service.co.uk/licence-activated/58eb2a20-6b0e-416b-b91d-5b98b0c1be7f", | ||
personReference = PersonReference(listOf(PersonIdentifier("CRN", "X123456"))) | ||
) | ||
whenever(cvlClient.getActivatedLicence(any())).thenReturn(null) | ||
|
||
val res = lah.licenceActivated(event).first() | ||
assertThat(res, instanceOf(ActionResult.Failure::class.java)) | ||
val fail = res as ActionResult.Failure | ||
assertThat(fail.exception, instanceOf(NotFoundException::class.java)) | ||
assertThat( | ||
fail.exception.message, | ||
equalTo("Activated Licence with detailUrl of https://cvl.service.co.uk/licence-activated/58eb2a20-6b0e-416b-b91d-5b98b0c1be7f not found") | ||
) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...elius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/LicenceConditionApplierTest.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,63 @@ | ||
package uk.gov.justice.digital.hmpps.service | ||
|
||
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.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.whenever | ||
import uk.gov.justice.digital.hmpps.data.generator.PersonGenerator | ||
import uk.gov.justice.digital.hmpps.integrations.cvl.ActivatedLicence | ||
import uk.gov.justice.digital.hmpps.integrations.delius.manager.entity.PersonManagerRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.CvlMappingRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.DisposalRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.LicenceConditionCategoryRepository | ||
import uk.gov.justice.digital.hmpps.integrations.delius.sentence.entity.ReferenceDataRepository | ||
import java.time.LocalDate | ||
import java.time.ZonedDateTime | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
internal class LicenceConditionApplierTest { | ||
@Mock | ||
internal lateinit var disposalRepository: DisposalRepository | ||
|
||
@Mock | ||
internal lateinit var personManagerRepository: PersonManagerRepository | ||
|
||
@Mock | ||
internal lateinit var cvlMappingRepository: CvlMappingRepository | ||
|
||
@Mock | ||
internal lateinit var licenceConditionCategoryRepository: LicenceConditionCategoryRepository | ||
|
||
@Mock | ||
internal lateinit var referenceDataRepository: ReferenceDataRepository | ||
|
||
@Mock | ||
internal lateinit var licenceConditionService: LicenceConditionService | ||
|
||
@Mock | ||
internal lateinit var contactService: ContactService | ||
|
||
@InjectMocks | ||
internal lateinit var licenceConditionApplier: LicenceConditionApplier | ||
|
||
@Test | ||
fun `when no active custodial sentence an error is thrown`() { | ||
val crn = "N678461" | ||
whenever(personManagerRepository.findByPersonCrn(crn)).thenReturn(PersonGenerator.DEFAULT_CM) | ||
whenever(disposalRepository.findCustodialSentences(crn)).thenReturn(listOf()) | ||
|
||
val ex = assertThrows<IllegalStateException> { | ||
licenceConditionApplier.applyLicenceConditions( | ||
crn, | ||
ActivatedLicence(crn, LocalDate.now(), null, null, listOf(), listOf(), listOf()), | ||
ZonedDateTime.now() | ||
) | ||
} | ||
assertThat(ex.message, equalTo("No Custodial Sentences to apply Licence Conditions")) | ||
} | ||
} |