Skip to content

Commit afe700b

Browse files
[HIA-257]
Adding new service down test to LicenceConditionControllerTests
1 parent 74438b5 commit afe700b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test/kotlin/uk/gov/justice/digital/hmpps/hmppsintegrationapi/controllers/v1/person/LicenceConditionControllerTests.kt

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.kotest.matchers.shouldBe
55
import io.kotest.matchers.string.shouldContain
66
import org.mockito.Mockito
77
import org.mockito.internal.verification.VerificationModeFactory
8+
import org.mockito.kotlin.doThrow
89
import org.mockito.kotlin.verify
910
import org.mockito.kotlin.whenever
1011
import org.springframework.beans.factory.annotation.Autowired
@@ -13,6 +14,7 @@ import org.springframework.boot.test.mock.mockito.MockBean
1314
import org.springframework.http.HttpStatus
1415
import org.springframework.test.context.ActiveProfiles
1516
import org.springframework.test.web.servlet.MockMvc
17+
import org.springframework.web.reactive.function.client.WebClientResponseException
1618
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.extensions.removeWhitespaceAndNewlines
1719
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.helpers.IntegrationAPIMockMvc
1820
import uk.gov.justice.digital.hmpps.hmppsintegrationapi.models.hmpps.Licence
@@ -109,6 +111,17 @@ class LicenceConditionControllerTests(
109111
""".removeWhitespaceAndNewlines(),
110112
)
111113
}
114+
115+
it("fails with the appropriate error when an upstream service is down") {
116+
whenever(getLicenceConditionService.execute(hmppsId)).doThrow(
117+
WebClientResponseException(500, "MockError", null, null, null, null),
118+
)
119+
120+
val response = mockMvc.performAuthorised(path)
121+
122+
assert(response.response.status == 500)
123+
assert(response.response.contentAsString.equals("{\"status\":500,\"errorCode\":null,\"userMessage\":\"500 MockError\",\"developerMessage\":\"Unable to complete request as an upstream service is not responding\",\"moreInfo\":null}"))
124+
}
112125
}
113126
},
114127
)

0 commit comments

Comments
 (0)