From a978716f5f5a494276c88794c3d366a012479f0d Mon Sep 17 00:00:00 2001 From: Ram Krishna Verma Date: Tue, 24 Aug 2021 17:33:07 -0400 Subject: Add dmaap connectivity check in pap Add dmaap connectivity check in pap consolidated health check. Make a rest call to fetch all the topics. Verify POLICY-PDP-PAP topic is present. Issue-ID: POLICY-2896 Change-Id: Ide39c70999eaca61205225c95b904e3009d41408 Signed-off-by: Ram Krishna Verma --- .../TestPolicyComponentsHealthCheckProvider.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'main/src/test/java/org') diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java index 3f4ecd32..f27a8d32 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. * Modifications Copyright (C) 2020-2021 AT&T Corp. - * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020-2021 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. @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import java.io.File; import java.net.HttpURLConnection; +import java.util.Arrays; import java.util.List; import java.util.Map; import javax.ws.rs.core.Response; @@ -88,12 +89,18 @@ public class TestPolicyComponentsHealthCheckProvider { @Mock private HttpClient client2; + @Mock + private HttpClient client3; + @Mock private Response response1; @Mock private Response response2; + @Mock + private Response response3; + private List groups; private PapParameterGroup savedPapParameterGroup; @@ -133,10 +140,17 @@ public class TestPolicyComponentsHealthCheckProvider { when(response2.readEntity(HealthCheckReport.class)).thenReturn(createReport(HttpURLConnection.HTTP_OK, true)); when(client2.get()).thenReturn(response2); + when(client3.getName()).thenReturn("dmaap"); + when(client3.getBaseUrl()).thenReturn("message-router"); + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_OK); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(createDmaapResponse()); + when(client3.get()).thenReturn(response3); + PapParameterGroup papParameterGroup = ParameterService.get(PAP_GROUP_PARAMS_NAME); List params = papParameterGroup.getHealthCheckRestClientParameters(); when(clientFactory.build(params.get(0))).thenReturn(client1); when(clientFactory.build(params.get(1))).thenReturn(client2); + when(clientFactory.build(params.get(2))).thenReturn(client3); PolicyComponentsHealthCheckProvider.initializeClientHealthCheckExecutorService(papParameterGroup, clientFactory); @@ -180,6 +194,20 @@ public class TestPolicyComponentsHealthCheckProvider { assertFalse((Boolean) result2.get(HEALTHY)); HealthCheckReport report2 = (HealthCheckReport) result.get(CLIENT_1); assertFalse(report2.isHealthy()); + + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_INTERNAL_ERROR); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(null); + Map result3 = callFetchPolicyComponentsHealthStatus(); + assertFalse((Boolean) result3.get(HEALTHY)); + HealthCheckReport report3 = (HealthCheckReport) result3.get("dmaap"); + assertFalse(report3.isHealthy()); + + when(response3.getStatus()).thenReturn(HttpURLConnection.HTTP_OK); + when(response3.readEntity(DmaapGetTopicResponse.class)).thenReturn(new DmaapGetTopicResponse()); + Map result4 = callFetchPolicyComponentsHealthStatus(); + assertFalse((Boolean) result4.get(HEALTHY)); + HealthCheckReport report4 = (HealthCheckReport) result4.get("dmaap"); + assertFalse(report4.isHealthy()); } @SuppressWarnings("unchecked") @@ -234,4 +262,10 @@ public class TestPolicyComponentsHealthCheckProvider { throw new RuntimeException(e); } } + + private DmaapGetTopicResponse createDmaapResponse() { + DmaapGetTopicResponse response = new DmaapGetTopicResponse(); + response.setTopics(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP)); + return response; + } } -- cgit 1.2.3-korg