From 09a3b58ff366259f27e6a5db8b187bcc92127482 Mon Sep 17 00:00:00 2001 From: Anthony Britton Date: Wed, 18 Oct 2023 16:46:54 +0100 Subject: [PATCH] PI-1441 - add feature flag check --- .../uk/gov/justice/digital/hmpps/service/CvlHandler.kt | 10 +++++++--- .../justice/digital/hmpps/service/CvlHandlerTest.kt | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandler.kt b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandler.kt index 3f45a0884e..476d27d459 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandler.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandler.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service import org.springframework.stereotype.Component import uk.gov.justice.digital.hmpps.converter.NotificationConverter +import uk.gov.justice.digital.hmpps.flags.FeatureFlags import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.Notification import uk.gov.justice.digital.hmpps.messaging.NotificationHandler @@ -11,13 +12,16 @@ import uk.gov.justice.digital.hmpps.telemetry.TelemetryService class CvlHandler( override val converter: NotificationConverter, private val telemetryService: TelemetryService, - private val licenceActivatedHandler: LicenceActivatedHandler + private val licenceActivatedHandler: LicenceActivatedHandler, + private val featureFlags: FeatureFlags ) : NotificationHandler { override fun handle(notification: Notification) { - val eventType = (notification.eventType ?: notification.message.eventType).let { DomainEventType.of(it) } + if (!featureFlags.enabled("cvl-licence-activated")) { + return + } val results = - when (eventType) { + when (val eventType = (notification.eventType ?: notification.message.eventType).let { DomainEventType.of(it) }) { is DomainEventType.LicenceActivated -> licenceActivatedHandler.licenceActivated(notification.message) else -> listOf( ActionResult.Ignored( diff --git a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandlerTest.kt b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandlerTest.kt index 128b7e6bd4..b2b2d97741 100644 --- a/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandlerTest.kt +++ b/projects/create-and-vary-a-licence-and-delius/src/test/kotlin/uk/gov/justice/digital/hmpps/service/CvlHandlerTest.kt @@ -2,6 +2,7 @@ package uk.gov.justice.digital.hmpps.service import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.extension.ExtendWith @@ -12,6 +13,7 @@ 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.flags.FeatureFlags import uk.gov.justice.digital.hmpps.message.HmppsDomainEvent import uk.gov.justice.digital.hmpps.message.MessageAttributes import uk.gov.justice.digital.hmpps.message.Notification @@ -28,9 +30,17 @@ internal class CvlHandlerTest { @Mock internal lateinit var licenceActivatedHandler: LicenceActivatedHandler + @Mock + internal lateinit var featureFlags: FeatureFlags + @InjectMocks internal lateinit var handler: CvlHandler + @BeforeEach + fun setUp() { + whenever(featureFlags.enabled("cvl-licence-activated")).thenReturn(true) + } + @Test fun `unexpected event types are ignored`() { val notification = Notification(