Skip to content

Commit 4cd02f7

Browse files
committed
PI-2517 - add new integration test
1 parent 478fe04 commit 4cd02f7

File tree

7 files changed

+106
-41
lines changed

7 files changed

+106
-41
lines changed

Dockerfile.prism

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ADD https://probation-offender-search-dev.hmpps.service.justice.gov.uk/v3/api-do
1313
ADD https://prisoner-search-dev.prison.service.justice.gov.uk/v3/api-docs /tmp/prisoner-offender-search-tmp.json
1414
RUN jq 'del(.components.schemas.Query.properties.subQueries)' /tmp/prisoner-offender-search-tmp.json > prisoner-offender-search-tmp1.json
1515
RUN swagger-cli bundle -r -o /prismMocks/prisoner-offender-search.json prisoner-offender-search-tmp1.json
16-
1716
RUN sed -i 's/\*\/\*/application\/json/g' /prismMocks/prisoner-offender-search.json
1817

1918
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'

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ authenticate-docker:
22
./scripts/authenticate_docker.sh
33

44
build-dev:
5-
docker compose pull hmpps-auth
5+
#docker compose pull hmpps-auth
66
docker compose build
77

88
build:
@@ -26,16 +26,16 @@ unit-test:
2626
smoke-test: serve
2727
./gradlew smokeTest --warning-mode all
2828

29-
integration-test:
30-
./gradlew integrationTest
29+
integration-test: serve
30+
./gradlew integrationTest --warning-mode all
3131

3232
heartbeat:
3333
./scripts/heartbeat.sh
3434

3535
test: unit-test smoke-test
3636

3737
e2e:
38-
./gradlew smokeTest --warning-mode all
38+
./gradlew integrationTest --warning-mode all
3939

4040
lint:
4141
./gradlew ktlintCheck

docker-compose.yml

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
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

18-
hmpps-auth:
19-
image: quay.io/hmpps/hmpps-auth:latest
20-
container_name: hmpps-auth
21-
ports:
22-
- "9090:8080"
23-
healthcheck:
24-
test: [ "CMD", "curl", "-f", "http://localhost:8080/auth/health" ]
25-
environment:
26-
- SERVER_PORT=8080
27-
- SPRING_PROFILES_ACTIVE=dev
28-
- LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=TRACE
18+
# hmpps-auth:
19+
# image: quay.io/hmpps/hmpps-auth:latest
20+
# container_name: hmpps-auth
21+
# ports:
22+
# - "9090:8080"
23+
# healthcheck:
24+
# test: [ "CMD", "curl", "-f", "http://localhost:8080/auth/health" ]
25+
# environment:
26+
# - SERVER_PORT=8080
27+
# - SPRING_PROFILES_ACTIVE=dev
28+
# - LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=TRACE
2929

3030
prism:
3131
build:

src/main/resources/application-integration-test.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ management.endpoint:
77

88
services:
99
prison-api:
10-
base-url: http://localhost:4000
10+
base-url: http://localhost:4016
1111
hmpps-auth:
12-
base-url: http://localhost:9090
12+
base-url: http://localhost:3000
13+
username: client
14+
password: client-secret
1315
prisoner-offender-search:
1416
base-url: http://localhost:4017
1517
probation-offender-search:

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

+24
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package uk.gov.justice.digital.hmpps.hmppsintegrationapi.integration
22

3+
import org.junit.jupiter.api.AfterAll
4+
import org.junit.jupiter.api.BeforeAll
35
import org.springframework.beans.factory.annotation.Autowired
46
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
57
import org.springframework.boot.test.context.SpringBootTest
68
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
79
import org.springframework.http.HttpHeaders
810
import org.springframework.test.context.ActiveProfiles
911
import org.springframework.test.web.servlet.MockMvc
12+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
13+
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.mockservers.HmppsAuthMockServer
14+
import java.io.File
1015

1116
@ActiveProfiles("integration-test")
1217
@AutoConfigureMockMvc
@@ -15,9 +20,28 @@ abstract class IntegrationTestBase {
1520
@Autowired
1621
lateinit var mockMvc: MockMvc
1722

23+
companion object {
24+
private val hmppsAuthMockServer = HmppsAuthMockServer()
25+
26+
@BeforeAll
27+
@JvmStatic
28+
fun startMockServers() {
29+
hmppsAuthMockServer.start()
30+
hmppsAuthMockServer.stubGetOAuthToken("client", "client-secret")
31+
}
32+
33+
@AfterAll
34+
@JvmStatic
35+
fun stopMockServers() {
36+
hmppsAuthMockServer.stop()
37+
}
38+
}
39+
1840
fun getAuthHeader(): HttpHeaders {
1941
val headers = HttpHeaders()
2042
headers.set("subject-distinguished-name", "C=GB,ST=London,L=London,O=Home Office,CN=automated-test-client")
2143
return headers
2244
}
45+
46+
fun getExpectedResponse(filename: String): String = File("./src/test/resources/expected-responses/$filename").readText(Charsets.UTF_8).removeWhitespaceAndNewlines()
2347
}

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

+28-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
55
import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print
66
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
77
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
8-
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
9-
import java.io.File
108
import java.net.URLEncoder
119
import java.nio.charset.StandardCharsets
1210

@@ -21,25 +19,47 @@ internal class PersonIntegrationTest : IntegrationTestBase() {
2119
val lastName = "Example_Last_Name"
2220
val queryParams = "first_name=$firstName&last_name=$lastName"
2321

24-
val expectedResponse = File("./src/test/resources/expected-responses/person-name-search-response").readText(Charsets.UTF_8).removeWhitespaceAndNewlines()
25-
2622
mockMvc.perform(
2723
get("$basePath?$queryParams").headers(getAuthHeader()),
2824
)
2925
.andExpect(status().isOk)
3026
.andDo(print())
31-
.andExpect(content().json(expectedResponse))
27+
.andExpect(content().json(getExpectedResponse("person-name-search-response")))
3228
}
3329

3430
@Test
3531
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-
3832
mockMvc.perform(
3933
get("$basePath/$encodedHmppsId").headers(getAuthHeader()),
4034
)
4135
.andExpect(status().isOk)
4236
.andDo(print())
43-
.andExpect(content().json(expectedResponse))
37+
.andExpect(content().json(getExpectedResponse("person-offender-and-probation-search-response")))
38+
}
39+
40+
@Test
41+
fun `returns image metadata for a person`() {
42+
mockMvc.perform(
43+
get("$basePath/$encodedHmppsId/images").headers(getAuthHeader()),
44+
)
45+
.andExpect(status().isOk)
46+
.andDo(print())
47+
.andExpect(content().json(getExpectedResponse("person-image-meta-data")))
48+
}
49+
50+
@Test
51+
fun `returns person name details for a person`() {
52+
mockMvc.perform(
53+
get("$basePath/$encodedHmppsId/name").headers(getAuthHeader()),
54+
)
55+
.andExpect(status().isOk)
56+
.andDo(print())
57+
.andExpect(
58+
content().json(
59+
"""
60+
{"data":{"firstName":"string","lastName":"string"}}
61+
""",
62+
),
63+
)
4464
}
4565
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"data": [
3+
{
4+
"id": 2461788,
5+
"active": false,
6+
"captureDateTime": "2021-07-05T10:35:17",
7+
"view": "OIC",
8+
"orientation": "NECK",
9+
"type": "OFF_IDM"
10+
}
11+
],
12+
"pagination": {
13+
"isLastPage": true,
14+
"count": 1,
15+
"page": 1,
16+
"perPage": 10,
17+
"totalCount": 1,
18+
"totalPages": 1
19+
}
20+
}

0 commit comments

Comments
 (0)