Skip to content

Commit df8b127

Browse files
committed
PI-2377 - add integration tests
1 parent d11090d commit df8b127

File tree

11 files changed

+606
-30
lines changed

11 files changed

+606
-30
lines changed

Dockerfile.prism

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM stoplight/prism:5
22

3+
34
COPY src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/prismMocks /prismMocks
45
ADD https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/external-api-and-delius/api-docs.json /prismMocks/ndelius.json
56
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
67
ADD https://dev.moic.service.justice.gov.uk/v3/api-docs.json /prismMocks/manage-pom-case-api.json
7-
8+
ADD https://prison-api-dev.prison.service.justice.gov.uk/v3/api-docs /prismMocks/prison-api.json
9+
ADD https://probation-offender-search-dev.hmpps.service.justice.gov.uk/v3/api-docs /prismMocks/probation-offender-search.json
810
RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/prisoner-offender-search.json
911

1012
ENTRYPOINT sh -c 'port=4010; for file in $(ls /prismMocks/*.json | sort); do node dist/index.js mock -p $port -h 0.0.0.0 $file & port=$((port + 1)); done; wait'

docker-compose.yml

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
services:
2-
hmpps-integration-api:
3-
build:
4-
context: .
5-
container_name: hmpps-integration-api
6-
healthcheck:
7-
test: [ "CMD", "curl", "-f", "http://localhost:8080/health" ]
8-
depends_on:
9-
hmpps-auth:
10-
condition: service_healthy
11-
ports:
12-
- "8080:8080"
13-
environment:
14-
- SERVER_PORT=8080
15-
- SPRING_PROFILES_ACTIVE=local-docker
16-
- LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=TRACE
2+
# hmpps-integration-api:
3+
# build:
4+
# context: .
5+
# container_name: hmpps-integration-api
6+
# healthcheck:
7+
# test: [ "CMD", "curl", "-f", "http://localhost:8080/health" ]
8+
# depends_on:
9+
# hmpps-auth:
10+
# condition: service_healthy
11+
# ports:
12+
# - "8080:8080"
13+
# environment:
14+
# - SERVER_PORT=8080
15+
# - SPRING_PROFILES_ACTIVE=local-docker
16+
# - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=TRACE
1717

1818
hmpps-auth:
1919
image: quay.io/hmpps/hmpps-auth:latest
@@ -27,6 +27,11 @@ services:
2727
- SPRING_PROFILES_ACTIVE=dev
2828
- LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=TRACE
2929

30+
swagger-editor:
31+
image: swaggerapi/swagger-editor
32+
ports:
33+
- "8081:8080"
34+
3035
prism:
3136
build:
3237
context: .
@@ -41,8 +46,6 @@ services:
4146
- '4015:4015'
4247
- '4016:4016'
4348
- '4017:4017'
44-
- '4018:4018'
45-
- '4019:4019'
4649

4750
local-stack-aws:
4851
image: localstack/localstack:3.0

src/main/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/prismMocks/prisoner-offender-search.json

+69
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,75 @@
128128
}
129129
]
130130
}
131+
},
132+
"/global-search": {
133+
"post": {
134+
"tags": [
135+
"Popular",
136+
"Global search"
137+
],
138+
"summary": "Match prisoners by criteria",
139+
"description": "Requires ROLE_GLOBAL_SEARCH role or ROLE_PRISONER_SEARCH role or PRISONER_SEARCH__PRISONER__RO",
140+
"operationId": "globalFindByCriteria",
141+
"parameters": [
142+
{
143+
"name": "page",
144+
"in": "query",
145+
"description": "Zero-based page index (0..N)",
146+
"required": false,
147+
"schema": {
148+
"minimum": 0,
149+
"type": "integer",
150+
"default": 0
151+
}
152+
},
153+
{
154+
"name": "size",
155+
"in": "query",
156+
"description": "The size of the page to be returned",
157+
"required": false,
158+
"schema": {
159+
"minimum": 1,
160+
"type": "integer",
161+
"default": 10
162+
}
163+
},
164+
{
165+
"name": "sort",
166+
"in": "query",
167+
"description": "Sorting criteria in the format: property,(asc|desc). Default sort order is ascending. Multiple sort criteria are supported.",
168+
"required": false,
169+
"schema": {
170+
"type": "array",
171+
"items": {
172+
"type": "string"
173+
}
174+
}
175+
}
176+
],
177+
"requestBody": {
178+
"content": {
179+
"application/json": {
180+
"schema": {
181+
"$ref": "#/components/schemas/GlobalSearchCriteria"
182+
}
183+
}
184+
},
185+
"required": true
186+
},
187+
"responses": {
188+
"200": {
189+
"description": "OK",
190+
"content": {
191+
"application/json": {
192+
"schema": {
193+
"$ref": "#/components/schemas/PagePrisoner"
194+
}
195+
}
196+
}
197+
}
198+
}
199+
}
131200
}
132201
},
133202
"components": {
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:3000
13+
username: client
14+
password: client-secret
15+
prisoner-offender-search:
16+
base-url: http://localhost:4002
17+
probation-offender-search:
18+
base-url: http://localhost:4002
19+
ndelius:
20+
base-url: http://localhost:4002
21+
assess-risks-and-needs:
22+
base-url: http://localhost:4002
23+
probation-integration-epf:
24+
base-url: http://localhost:4002
25+
adjudications:
26+
base-url: http://localhost:4002
27+
create-and-vary-licence:
28+
base-url: http://localhost:4002
29+
case-notes:
30+
base-url: http://localhost:4002
31+
manage-pom-case-api:
32+
base-url: http://localhost:4009
33+
34+
hmpps.sqs:
35+
provider: localstack
36+
queues:
37+
audit:
38+
queueName: "audit"
39+
40+
authorisation:
41+
consumers:
42+
automated-test-client:
43+
- "/v1/persons"
44+
- "/v1/persons/[^/]*$"
45+
- "/v1/persons/.*/images"
46+
- "/v1/persons/.*/name"
47+
- "/v1/images/[^/]*$"
48+
- "/v1/persons/.*/addresses"
49+
- "/v1/persons/.*/offences"
50+
- "/v1/persons/.*/alerts"
51+
- "/v1/persons/.*/alerts/pnd"
52+
- "/v1/persons/.*/sentences"
53+
- "/v1/persons/.*/sentences/latest-key-dates-and-adjustments"
54+
- "/v1/persons/.*/risks/scores"
55+
- "/v1/persons/.*/needs"
56+
- "/v1/persons/.*/risks/serious-harm"
57+
- "/v1/persons/.*/risks/dynamic"
58+
- "/v1/persons/.*/reported-adjudications"
59+
- "/v1/epf/person-details/.*/[^/]*$"
60+
- "/v1/persons/.*/adjudications"
61+
- "/v1/persons/.*/licences/conditions"
62+
- "/v1/persons/.*/case-notes"
63+
- "/v1/persons/.*/person-responsible-officer"
64+
- "/v1/persons/.*/protected-characteristics"
65+
- "/v1/persons/.*/risks/mappadetail"
66+
- "/v1/persons/.*/risks/categories"
67+
- "/v1/persons/.*/risk-management-plan"
68+
- "/v1/persons/.*/cell-location"
69+
- "/v1/persons/.*/status-information"
70+
- "/v1/hmpps-id/nomis-number/[^/]*$"
71+
- "/health"
72+
- "/health/ping"
73+
- "/health/readiness"
74+
- "/health/liveness"
75+
- "/info"
76+
config-test:
77+
- "/v1/config/authorisation"

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/integration/InfoPageTest.kt

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
22

33
import org.junit.jupiter.api.Test
44
import org.springframework.http.HttpHeaders
5+
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
6+
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
7+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
8+
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
59

610

7-
class InfoPageTest : IntegrationTestBase() {
11+
internal class InfoPageTest : IntegrationTestBase() {
812

913
@Test
1014
fun `Info page is accessible`() {
1115

12-
webTestClient.get()
13-
.uri("/info")
14-
.header("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client")
15-
.exchange()
16-
.expectStatus()
17-
.isOk
16+
mockMvc.perform(
17+
get("/info")
18+
.header("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client"))
19+
.andExpect(status().isOk)
20+
.andDo(MockMvcResultHandlers.print())
1821
}
1922

2023
}
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,79 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
22

3+
import com.github.tomakehurst.wiremock.WireMockServer
4+
import com.github.tomakehurst.wiremock.core.Options
5+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
36
import org.junit.jupiter.api.AfterAll
47
import org.junit.jupiter.api.BeforeAll
58
import org.springframework.beans.factory.annotation.Autowired
9+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
610
import org.springframework.boot.test.context.SpringBootTest
711
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
12+
import org.springframework.http.HttpHeaders
813
import org.springframework.test.context.ActiveProfiles
914
import org.springframework.test.web.reactive.server.WebTestClient
15+
import org.springframework.test.web.servlet.MockMvc
16+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
1017
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.HmppsAuthMockServer
1118
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.NomisApiMockServer
1219
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.PrisonerOffenderSearchApiMockServer
20+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.ProbationOffenderSearchApiMockServer
21+
import java.io.File
1322

1423
@ActiveProfiles("test")
24+
@AutoConfigureMockMvc
1525
@SpringBootTest(webEnvironment = RANDOM_PORT)
1626
abstract class IntegrationTestBase {
17-
@Suppress("SpringJavaInjectionPointsAutowiringInspection")
1827
@Autowired
19-
lateinit var webTestClient: WebTestClient
28+
lateinit var mockMvc: MockMvc
2029

2130
companion object {
22-
private val nomisApiMockServer = NomisApiMockServer()
2331
private val prisonerOffenderSearchApiMockServer = PrisonerOffenderSearchApiMockServer()
2432
private val hmppsAuthMockServer = HmppsAuthMockServer()
33+
// private val probationOffenderSearchApiMockServer = ProbationOffenderSearchApiMockServer()
34+
35+
private val wireMockServer = WireMockServer(options()
36+
.usingFilesUnderClasspath("simulations")
37+
.port(4002))
2538

2639
@BeforeAll
2740
@JvmStatic
2841
fun startMockServers() {
29-
nomisApiMockServer.start()
3042
hmppsAuthMockServer.start()
3143
prisonerOffenderSearchApiMockServer.start()
44+
wireMockServer.start()
45+
// probationOffenderSearchApiMockServer.start()
3246

3347
hmppsAuthMockServer.stubGetOAuthToken("client", "client-secret")
48+
49+
50+
// probationOffenderSearchApiMockServer.stubPostOffenderSearch(
51+
// """
52+
// {
53+
// "firstName": "Example_First_Name",
54+
// "surname": "Example_Last_Name",
55+
// "includeAliases": false
56+
// }
57+
// """.removeWhitespaceAndNewlines(),
58+
// File(
59+
// "src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/gateways/probationoffendersearch/fixtures/GetOffendersResponse.json",
60+
// ).readText(),
61+
// )
3462
}
3563

3664
@AfterAll
3765
@JvmStatic
3866
fun stopMockServers() {
39-
nomisApiMockServer.stop()
4067
hmppsAuthMockServer.stop()
4168
prisonerOffenderSearchApiMockServer.stop()
69+
wireMockServer.stop()
70+
// probationOffenderSearchApiMockServer.stop()
4271
}
4372
}
73+
74+
fun getAuthHeader(): HttpHeaders {
75+
val headers = HttpHeaders()
76+
headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client")
77+
return headers
78+
}
4479
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
2+
3+
import com.github.tomakehurst.wiremock.WireMockServer
4+
import com.github.tomakehurst.wiremock.core.Options
5+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options
6+
import org.junit.jupiter.api.AfterAll
7+
import org.junit.jupiter.api.BeforeAll
8+
import org.springframework.beans.factory.annotation.Autowired
9+
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
10+
import org.springframework.boot.test.context.SpringBootTest
11+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
12+
import org.springframework.http.HttpHeaders
13+
import org.springframework.test.context.ActiveProfiles
14+
import org.springframework.test.web.reactive.server.WebTestClient
15+
import org.springframework.test.web.servlet.MockMvc
16+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
17+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.HmppsAuthMockServer
18+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.NomisApiMockServer
19+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.PrisonerOffenderSearchApiMockServer
20+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.ProbationOffenderSearchApiMockServer
21+
import java.io.File
22+
23+
@ActiveProfiles("integration-wiremock-test")
24+
@AutoConfigureMockMvc
25+
@SpringBootTest(webEnvironment = RANDOM_PORT)
26+
abstract class IntegrationWiremockTestBase {
27+
@Autowired
28+
lateinit var mockMvc: MockMvc
29+
30+
companion object {
31+
private val hmppsAuthMockServer = HmppsAuthMockServer()
32+
33+
private val wireMockServer = WireMockServer(options()
34+
.usingFilesUnderClasspath("simulations")
35+
.port(4002))
36+
37+
@BeforeAll
38+
@JvmStatic
39+
fun startMockServers() {
40+
hmppsAuthMockServer.start()
41+
wireMockServer.start()
42+
43+
hmppsAuthMockServer.stubGetOAuthToken("client", "client-secret")
44+
}
45+
46+
@AfterAll
47+
@JvmStatic
48+
fun stopMockServers() {
49+
hmppsAuthMockServer.stop()
50+
wireMockServer.stop()
51+
}
52+
}
53+
54+
fun getAuthHeader(): HttpHeaders {
55+
val headers = HttpHeaders()
56+
headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client")
57+
return headers
58+
}
59+
}

0 commit comments

Comments
 (0)