Skip to content

Commit 478fe04

Browse files
committed
PI-2517 - add integration test
1 parent b93c9e4 commit 478fe04

File tree

9 files changed

+291
-32
lines changed

9 files changed

+291
-32
lines changed

Dockerfile.prism

+9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
FROM stoplight/prism:5
22

3+
4+
RUN apk add --no-cache jq
5+
RUN npm install -g @apidevtools/swagger-cli
36
COPY src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/prismMocks /prismMocks
47
ADD https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/external-api-and-delius/api-docs.json /prismMocks/ndelius.json
58
ADD https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/effective-proposal-framework-and-delius/api-docs.json /prismMocks/probation-integration-epf.json
69
ADD https://dev.moic.service.justice.gov.uk/v3/api-docs.json /prismMocks/manage-pom-case-api.json
10+
ADD https://prison-api-dev.prison.service.justice.gov.uk/v3/api-docs /prismMocks/prison-api.json
11+
ADD https://probation-offender-search-dev.hmpps.service.justice.gov.uk/v3/api-docs /prismMocks/probation-offender-search.json
12+
13+
ADD https://prisoner-search-dev.prison.service.justice.gov.uk/v3/api-docs /tmp/prisoner-offender-search-tmp.json
14+
RUN jq 'del(.components.schemas.Query.properties.subQueries)' /tmp/prisoner-offender-search-tmp.json > prisoner-offender-search-tmp1.json
15+
RUN swagger-cli bundle -r -o /prismMocks/prisoner-offender-search.json prisoner-offender-search-tmp1.json
716

817
RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/prisoner-offender-search.json
918

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ unit-test:
2626
smoke-test: serve
2727
./gradlew smokeTest --warning-mode all
2828

29+
integration-test:
30+
./gradlew integrationTest
31+
2932
heartbeat:
3033
./scripts/heartbeat.sh
3134

build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tasks {
4242
register<Test>("unitTest") {
4343
filter {
4444
excludeTestsMatching("uk.gov.justice.digital.hmpps.hmppsintegrationapi.smoke*")
45+
excludeTestsMatching("uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration*")
4546
}
4647
}
4748

@@ -51,6 +52,12 @@ tasks {
5152
}
5253
}
5354

55+
register<Test>("integrationTest") {
56+
filter {
57+
includeTestsMatching("uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration*")
58+
}
59+
}
60+
5461
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
5562
kotlinOptions {
5663
jvmTarget = "21"

gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
#
77
# To stop the dps-gradle-spring-boot project from overwriting any project specific customisations here, remove the
88
# warning at the top of this file.
9-
kotlin.incremental.useClasspathSnapshot=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
server:
2+
shutdown: immediate
3+
4+
management.endpoint:
5+
health.cache.time-to-live: 0
6+
info.cache.time-to-live: 0
7+
8+
services:
9+
prison-api:
10+
base-url: http://localhost:4000
11+
hmpps-auth:
12+
base-url: http://localhost:9090
13+
prisoner-offender-search:
14+
base-url: http://localhost:4017
15+
probation-offender-search:
16+
base-url: http://localhost:4019
17+
ndelius:
18+
base-url: http://localhost:4003
19+
assess-risks-and-needs:
20+
base-url: http://localhost:4004
21+
probation-integration-epf:
22+
base-url: http://localhost:4005
23+
adjudications:
24+
base-url: http://localhost:4006
25+
create-and-vary-licence:
26+
base-url: http://localhost:4007
27+
case-notes:
28+
base-url: http://localhost:4008
29+
manage-pom-case-api:
30+
base-url: http://localhost:4009
31+
32+
hmpps.sqs:
33+
provider: localstack
34+
queues:
35+
audit:
36+
queueName: "audit"
37+
38+
authorisation:
39+
consumers:
40+
automated-test-client:
41+
- "/v1/persons"
42+
- "/v1/persons/[^/]*$"
43+
- "/v1/persons/.*/images"
44+
- "/v1/persons/.*/name"
45+
- "/v1/images/[^/]*$"
46+
- "/v1/persons/.*/addresses"
47+
- "/v1/persons/.*/offences"
48+
- "/v1/persons/.*/alerts"
49+
- "/v1/persons/.*/alerts/pnd"
50+
- "/v1/persons/.*/sentences"
51+
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
52+
- "/v1/persons/.*/risks/scores"
53+
- "/v1/persons/.*/needs"
54+
- "/v1/persons/.*/risks/serious-harm"
55+
- "/v1/persons/.*/reported-adjudications"
56+
- "/v1/persons/.*/adjudications"
57+
- "/v1/persons/.*/licences/conditions"
58+
- "/v1/persons/.*/protected-characteristics"
59+
- "/v1/persons/.*/risks/mappadetail"
60+
- "/v1/persons/.*/risks/categories"
61+
- "/v1/persons/.*/status-information"
62+
- "/v1/persons/.*/risks/dynamic"
63+
- "/v1/persons/.*/case-notes"
64+
- "/v1/persons/.*/person-responsible-officer"
65+
- "/v1/persons/.*/risk-management-plan"
66+
- "/v1/persons/.*/cell-location"
67+
- "/v1/epf/person-details/.*/[^/]*$"
68+
- "/v1/hmpps-id/nomis-number/[^/]*$"
69+
- "/health"
70+
- "/health/ping"
71+
- "/health/readiness"
72+
- "/health/liveness"
73+
- "/info"
74+
config-test:
75+
- "/v1/config/authorisation"
76+
all-access:
77+
- "/.*"
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,23 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
22

3-
import org.junit.jupiter.api.AfterAll
4-
import org.junit.jupiter.api.BeforeAll
53
import org.springframework.beans.factory.annotation.Autowired
4+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
65
import org.springframework.boot.test.context.SpringBootTest
76
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
7+
import org.springframework.http.HttpHeaders
88
import org.springframework.test.context.ActiveProfiles
9-
import org.springframework.test.web.reactive.server.WebTestClient
10-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.HmppsAuthMockServer
11-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.NomisApiMockServer
12-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.PrisonerOffenderSearchApiMockServer
9+
import org.springframework.test.web.servlet.MockMvc
1310

14-
@ActiveProfiles("test")
11+
@ActiveProfiles("integration-test")
12+
@AutoConfigureMockMvc
1513
@SpringBootTest(webEnvironment = RANDOM_PORT)
1614
abstract class IntegrationTestBase {
17-
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
1815
@Autowired
19-
lateinit var webTestClient: WebTestClient
16+
lateinit var mockMvc: MockMvc
2017

21-
companion object {
22-
private val nomisApiMockServer = NomisApiMockServer()
23-
private val prisonerOffenderSearchApiMockServer = PrisonerOffenderSearchApiMockServer()
24-
private val hmppsAuthMockServer = HmppsAuthMockServer()
25-
26-
@BeforeAll
27-
@JvmStatic
28-
fun startMockServers() {
29-
nomisApiMockServer.start()
30-
hmppsAuthMockServer.start()
31-
prisonerOffenderSearchApiMockServer.start()
32-
33-
hmppsAuthMockServer.stubGetOAuthToken("client", "client-secret")
34-
}
35-
36-
@AfterAll
37-
@JvmStatic
38-
fun stopMockServers() {
39-
nomisApiMockServer.stop()
40-
hmppsAuthMockServer.stop()
41-
prisonerOffenderSearchApiMockServer.stop()
42-
}
18+
fun getAuthHeader(): HttpHeaders {
19+
val headers = HttpHeaders()
20+
headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client")
21+
return headers
4322
}
4423
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
2+
3+
import org.junit.jupiter.api.Test
4+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
5+
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
6+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
7+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
8+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
9+
import java.io.File
10+
import java.net.URLEncoder
11+
import java.nio.charset.StandardCharsets
12+
13+
internal class PersonIntegrationTest : IntegrationTestBase() {
14+
val basePath = "/v1/persons"
15+
final val hmppsId = "2004/13116M"
16+
val encodedHmppsId = URLEncoder.encode(hmppsId, StandardCharsets.UTF_8)
17+
18+
@Test
19+
fun `returns a list of persons using first name and last name as search parameters`() {
20+
val firstName = "Example_First_Name"
21+
val lastName = "Example_Last_Name"
22+
val queryParams = "first_name=$firstName&last_name=$lastName"
23+
24+
val expectedResponse = File("./src/test/resources/expected-responses/person-name-search-response").readText(Charsets.UTF_8).removeWhitespaceAndNewlines()
25+
26+
mockMvc.perform(
27+
get("$basePath?$queryParams").headers(getAuthHeader()),
28+
)
29+
.andExpect(status().isOk)
30+
.andDo(print())
31+
.andExpect(content().json(expectedResponse))
32+
}
33+
34+
@Test
35+
fun `returns a person from Prisoner Offender Search and Probation Offender Search`() {
36+
val expectedResponse = File("./src/test/resources/expected-responses/person-offender-and-probation-search-response").readText(Charsets.UTF_8).removeWhitespaceAndNewlines()
37+
38+
mockMvc.perform(
39+
get("$basePath/$encodedHmppsId").headers(getAuthHeader()),
40+
)
41+
.andExpect(status().isOk)
42+
.andDo(print())
43+
.andExpect(content().json(expectedResponse))
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"data": [
3+
{
4+
"firstName": "Robert",
5+
"lastName": "Larsen",
6+
"middleName": "John James",
7+
"dateOfBirth": "1975-04-02",
8+
"gender": "Female",
9+
"ethnicity": "White: Eng./Welsh/Scot./N.Irish/British",
10+
"aliases": [
11+
{
12+
"firstName": "Robert",
13+
"lastName": "Lorsen",
14+
"middleName": "Trevor",
15+
"dateOfBirth": "1975-04-02",
16+
"gender": "Male",
17+
"ethnicity": "White : Irish"
18+
}
19+
],
20+
"identifiers": {
21+
"nomisNumber": "A1234AA",
22+
"croNumber": "29906/12J",
23+
"deliusCrn": null
24+
},
25+
"pncId": "12/394773H",
26+
"hmppsId": null,
27+
"contactDetails": null
28+
},
29+
{
30+
"firstName": "string",
31+
"lastName": "string",
32+
"middleName": "string",
33+
"dateOfBirth": "2019-08-24",
34+
"gender": "string",
35+
"ethnicity": "string",
36+
"aliases": [
37+
{
38+
"firstName": "string",
39+
"lastName": "string",
40+
"middleName": "string",
41+
"dateOfBirth": "2019-08-24",
42+
"gender": "string",
43+
"ethnicity": null
44+
}
45+
],
46+
"identifiers": {
47+
"nomisNumber": "G5555TT",
48+
"croNumber": "123456/24A",
49+
"deliusCrn": "A123456"
50+
},
51+
"pncId": "2012/0052494Q",
52+
"hmppsId": "A123456",
53+
"contactDetails": {
54+
"phoneNumbers": [
55+
{
56+
"number": "string",
57+
"type": "TELEPHONE"
58+
}
59+
],
60+
"emails": [
61+
"string"
62+
]
63+
}
64+
}
65+
],
66+
"pagination": {
67+
"isLastPage": true,
68+
"count": 2,
69+
"page": 1,
70+
"perPage": 10,
71+
"totalCount": 2,
72+
"totalPages": 1
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"data": {
3+
"prisonerOffenderSearch": {
4+
"firstName": "Robert",
5+
"lastName": "Larsen",
6+
"middleName": "John James",
7+
"dateOfBirth": "1975-04-02",
8+
"gender": "Female",
9+
"ethnicity": "White: Eng./Welsh/Scot./N.Irish/British",
10+
"aliases": [
11+
{
12+
"firstName": "Robert",
13+
"lastName": "Lorsen",
14+
"middleName": "Trevor",
15+
"dateOfBirth": "1975-04-02",
16+
"gender": "Male",
17+
"ethnicity": "White : Irish"
18+
}
19+
],
20+
"identifiers": {
21+
"nomisNumber": "A1234AA",
22+
"croNumber": "29906/12J",
23+
"deliusCrn": null
24+
},
25+
"pncId": "12/394773H",
26+
"hmppsId": null,
27+
"contactDetails": null
28+
},
29+
"probationOffenderSearch": {
30+
"firstName": "string",
31+
"lastName": "string",
32+
"middleName": "string",
33+
"dateOfBirth": "2019-08-24",
34+
"gender": "string",
35+
"ethnicity": "string",
36+
"aliases": [
37+
{
38+
"firstName": "string",
39+
"lastName": "string",
40+
"middleName": "string",
41+
"dateOfBirth": "2019-08-24",
42+
"gender": "string",
43+
"ethnicity": null
44+
}
45+
],
46+
"identifiers": {
47+
"nomisNumber": "G5555TT",
48+
"croNumber": "123456/24A",
49+
"deliusCrn": "A123456"
50+
},
51+
"pncId": "2012/0052494Q",
52+
"hmppsId": "A123456",
53+
"contactDetails": {
54+
"phoneNumbers": [
55+
{
56+
"number": "string",
57+
"type": "TELEPHONE"
58+
}
59+
],
60+
"emails": [
61+
"string"
62+
]
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)