From 71ee61264d77d1e4cd2f7aa9d33ec7e3ae4e1ce0 Mon Sep 17 00:00:00 2001 From: Mingyang Zhu <mzhu9@slb.com> Date: Wed, 12 May 2021 16:22:06 -0500 Subject: [PATCH] add negative test cases for the health check apis --- .../osdu/partition/api/HealthCheckTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/partition-core/src/test/java/org/opengroup/osdu/partition/api/HealthCheckTest.java b/partition-core/src/test/java/org/opengroup/osdu/partition/api/HealthCheckTest.java index 91f3bd0c2..d66879dce 100644 --- a/partition-core/src/test/java/org/opengroup/osdu/partition/api/HealthCheckTest.java +++ b/partition-core/src/test/java/org/opengroup/osdu/partition/api/HealthCheckTest.java @@ -24,6 +24,7 @@ import org.opengroup.osdu.partition.provider.interfaces.IHealthCheckService; import org.springframework.http.HttpStatus; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) @@ -42,9 +43,21 @@ public class HealthCheckTest { assertEquals(HttpStatus.OK, this.sut.livenessCheck().getStatusCode()); } + @Test(expected = Exception.class) + public void should_throwException_when_customizedLivenessCheckFail() { + doThrow(new Exception()).when(healthCheckService).performLivenessCheck(); + this.sut.livenessCheck(); + } + @Test public void should_returnHttp200_when_checkReadiness() { assertEquals(HttpStatus.OK, this.sut.readinessCheck().getStatusCode()); verify(healthCheckService).performReadinessCheck(); } + + @Test(expected = Exception.class) + public void should_throwException_when_customizedReadinessCheckFail() { + doThrow(new Exception()).when(healthCheckService).performReadinessCheck(); + this.sut.readinessCheck(); + } } \ No newline at end of file -- GitLab