From f4e41fe888894282b5605c0182e9b292a9ecddf8 Mon Sep 17 00:00:00 2001 From: "Joseph.Dundon" Date: Fri, 6 Dec 2024 11:10:01 +0000 Subject: [PATCH] PI-2667 Common Platform Address records - OS Places API - Added wiremock mappings files - Fixed failing tests --- .../__files/address-lookup-no-results.json | 4 + .../__files/address-lookup-single-result.json | 15 +++ .../mappings/address-lookup-mapping.json | 13 +++ .../mappings/probation-search-mapping.json | 13 +++ .../justice/digital/hmpps/IntegrationTest.kt | 110 +----------------- 5 files changed, 50 insertions(+), 105 deletions(-) create mode 100644 projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-no-results.json create mode 100644 projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-single-result.json create mode 100644 projects/common-platform-and-delius/src/dev/resources/simulations/mappings/address-lookup-mapping.json create mode 100644 projects/common-platform-and-delius/src/dev/resources/simulations/mappings/probation-search-mapping.json diff --git a/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-no-results.json b/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-no-results.json new file mode 100644 index 0000000000..d9e9027a2a --- /dev/null +++ b/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-no-results.json @@ -0,0 +1,4 @@ +{ + "header": { "totalresults": 0 }, + "results": [] +} \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-single-result.json b/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-single-result.json new file mode 100644 index 0000000000..a776ba2ae6 --- /dev/null +++ b/projects/common-platform-and-delius/src/dev/resources/simulations/__files/address-lookup-single-result.json @@ -0,0 +1,15 @@ +{ + "header": { "totalresults": 1 }, + "results": [ + { + "DPA": { + "ADDRESS": "123 Test Street, Test, AB1 2CD", + "POSTCODE": "AB1 2CD", + "BUILDING_NUMBER": "123", + "THOROUGHFARE_NAME": "Test Street", + "POST_TOWN": "Test", + "MATCH": 0.9 + } + } + ] +} \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/address-lookup-mapping.json b/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/address-lookup-mapping.json new file mode 100644 index 0000000000..1fd96c6ba2 --- /dev/null +++ b/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/address-lookup-mapping.json @@ -0,0 +1,13 @@ +{ + "request": { + "method": "GET", + "urlPath": "/address-lookup/search/places/v1/find" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "bodyFileName": "address-lookup-single-result.json" + } +} \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/probation-search-mapping.json b/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/probation-search-mapping.json new file mode 100644 index 0000000000..85f814a949 --- /dev/null +++ b/projects/common-platform-and-delius/src/dev/resources/simulations/mappings/probation-search-mapping.json @@ -0,0 +1,13 @@ +{ + "request": { + "method": "POST", + "urlPath": "/probation-search/match" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json" + }, + "bodyFileName": "probation-search-no-results.json" + } +} \ No newline at end of file diff --git a/projects/common-platform-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt b/projects/common-platform-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt index 9a73489627..54c2d2aa57 100644 --- a/projects/common-platform-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt +++ b/projects/common-platform-and-delius/src/integrationTest/kotlin/uk/gov/justice/digital/hmpps/IntegrationTest.kt @@ -97,16 +97,6 @@ internal class IntegrationTest { @Test fun `When a message with no prosecution cases is found no insert is performed`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NO_CASES) channelManager.getChannel(queueName).publishAndWait(notification) thenNoRecordsAreInserted() @@ -114,16 +104,6 @@ internal class IntegrationTest { @Test fun `When a message without a judicial result of remanded in custody is found`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NO_REMAND) channelManager.getChannel(queueName).publishAndWait(notification) thenNoRecordsAreInserted() @@ -131,16 +111,6 @@ internal class IntegrationTest { @Test fun `When a person under 10 years old is found no insert is performed`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_DOB_ERROR) channelManager.getChannel(queueName).publishAndWait(notification) thenNoRecordsAreInserted() @@ -148,16 +118,6 @@ internal class IntegrationTest { @Test fun `When a probation search match is not detected then a person is inserted`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT) channelManager.getChannel(queueName).publishAndWait(notification) @@ -181,16 +141,6 @@ internal class IntegrationTest { @Test fun `When a hearing message with missing required fields is detected no records are inserted`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_NULL_FIELDS) channelManager.getChannel(queueName).publishAndWait(notification) thenNoRecordsAreInserted() @@ -198,16 +148,6 @@ internal class IntegrationTest { @Test fun `When a hearing with an address is received then an address record is inserted`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT) channelManager.getChannel(queueName).publishAndWait(notification) @@ -236,16 +176,6 @@ internal class IntegrationTest { @Test fun `When a hearing with an empty address is received then an address record is not inserted`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT_BLANK_ADDRESS) channelManager.getChannel(queueName).publishAndWait(notification) @@ -265,16 +195,6 @@ internal class IntegrationTest { @Order(1) @Test fun `engagement created and address created sns messages are published on insert person`() { - wireMockServer.stubFor( - post(urlPathEqualTo("/probation-search/match")) - .willReturn( - aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json") - .withBodyFile("probation-search-no-results.json") - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT) channelManager.getChannel(queueName).publishAndWait(notification) @@ -377,31 +297,6 @@ internal class IntegrationTest { @Test fun `Address lookup api is inserted when result is found`() { - wireMockServer.stubFor( - get(urlPathEqualTo("/address-lookup/search/places/v1/find")) - .willReturn( - okJson( - """ - { - "header": { "totalresults": 1 }, - "results": [ - { - "DPA": { - "address": "123 Test Street, Test, AB1 2CD", - "postcode": "AB1 2CD", - "buildingNumber": "123", - "thoroughfareName": "Test Street", - "postTown": "Test", - "match": 0.9 - } - } - ] - } - """ - ) - ) - ) - val notification = Notification(message = MessageGenerator.COMMON_PLATFORM_EVENT) channelManager.getChannel(queueName).publishAndWait(notification) @@ -429,4 +324,9 @@ internal class IntegrationTest { verify(auditedInteractionService, Mockito.never()) .createAuditedInteraction(any(), any(), eq(AuditedInteraction.Outcome.SUCCESS), any(), anyOrNull()) } + + @AfterEach + fun resetWireMock() { + wireMockServer.resetAll() + } } \ No newline at end of file