aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorPrakhar Pandey <prakhar.pandey@bell.ca>2022-02-10 14:14:13 -0500
committerPrakhar Pandey <prakhar.pandey@bell.ca>2022-02-11 11:36:06 -0500
commit0fdbdd8200b8a16243ce96a2a039dbc3922d3171 (patch)
treead512602d2c74be6ba04bed74655ca29b6e8dacb /main/src/test/java/org
parent873803eca00830dc3ecb61e610d90710f64a8242 (diff)
Improve PAP healthcheck api to verify DB connectivity
This commit improves PAP healthcheck API to enable verification of PAP to DB connectivity. Issue-ID: POLICY-3763 Signed-off-by: Prakhar Pandey <prakhar.pandey@bell.ca> Change-Id: I14353572a00e68a89161bcffd2ec3476b4a4c303
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java
index 6dd7103b..bc97c634 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +23,13 @@
package org.onap.policy.pap.main.rest;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
import javax.ws.rs.client.Invocation;
import org.junit.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.springframework.boot.test.mock.mockito.MockBean;
/**
* Class to perform unit test of {@link PapRestServer}.
@@ -36,6 +40,9 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
+ @MockBean
+ private PolicyStatusProvider policyStatusProvider;
+
@Test
public void testSwagger() throws Exception {
super.testSwagger(HEALTHCHECK_ENDPOINT);
@@ -52,13 +59,21 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
}
@Test
- public void testHealthCheck_500() throws Exception {
+ public void testHealthCheckActivatorFailure() throws Exception {
markActivatorDead();
final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
+ validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report);
+ }
+
+ @Test
+ public void testHealthCheckDbConnectionFailure() throws Exception {
+ when(policyStatusProvider.getPolicyStatus()).thenThrow(PfModelRuntimeException.class);
+ final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
+ final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
+ validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report);
}
private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,