Skip to content

Commit 2e7d1c4

Browse files
[HIA-257]
Adding new service down test to NeedsControllerTest
1 parent afe700b commit 2e7d1c4

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/NeedsControllerTest.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.Need
@@ -173,6 +175,17 @@ internal class NeedsControllerTest(
173175

174176
result.response.status.shouldBe(HttpStatus.NOT_FOUND.value())
175177
}
178+
179+
it("fails with the appropriate error when an upstream service is down") {
180+
whenever(getNeedsForPersonService.execute(hmppsId)).doThrow(
181+
WebClientResponseException(500, "MockError", null, null, null, null),
182+
)
183+
184+
val response = mockMvc.performAuthorised(path)
185+
186+
assert(response.response.status == 500)
187+
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}"))
188+
}
176189
}
177190
},
178191
)

0 commit comments

Comments
 (0)