aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorisaac <isaac.adorno@att.com>2022-05-19 15:12:05 -0500
committerisaac <isaac.adorno@att.com>2022-06-21 18:22:34 -0500
commitfd5ed6f15c9f2b78417dad0d7f168982dfeeae56 (patch)
tree615bd5eb4b76f07cc73a3a2dc35e01f19f41a43b /main/src/test
parent86c91fd09daeb36367bf4c99eda9a52b4523521b (diff)
Adding support for custom application metrics in Xacml-PDP.
Issue-ID: POLICY-3762 Signed-off-by: isaac <isaac.adorno@att.com> Change-Id: I84b43ae3a61702ceaf9f526a1c537caa77802af6
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java37
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java37
2 files changed, 53 insertions, 21 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
index a8a7b84d..b626142a 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. 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,6 +22,8 @@ package org.onap.policy.pdpx.main.rest;
import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.Map;
import javax.ws.rs.client.Invocation;
import org.junit.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
@@ -83,12 +85,12 @@ public class TestXacmlPdpRestServer extends CommonRest {
Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
LOGGER.info("testStatistics_200 health report {}", report);
- validateStatisticsReport(report, 0, 200);
+ validateStatisticsReport(report, 0, 200, new HashMap<>());
updateXacmlPdpStatistics();
invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
report = invocationBuilder.get(StatisticsReport.class);
LOGGER.info("testStatistics_200 health report {}", report);
- validateStatisticsReport(report, 1, 200);
+ validateStatisticsReport(report, 1, 200, returnStatisticsMap());
}
@Test
@@ -100,7 +102,7 @@ public class TestXacmlPdpRestServer extends CommonRest {
final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
LOGGER.info("testStatistics_500 health report {}", report);
- validateStatisticsReport(report, 0, 500);
+ validateStatisticsReport(report, 0, 500, new HashMap<>());
}
@Test
@@ -109,7 +111,20 @@ public class TestXacmlPdpRestServer extends CommonRest {
final Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT);
final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
LOGGER.info("testHttpsStatistic health report {}", report);
- validateStatisticsReport(report, 0, 200);
+ validateStatisticsReport(report, 0, 200, new HashMap<>());
+ }
+
+ private Map<String, Map<String, Integer>> returnStatisticsMap() {
+ Map<String, Integer> testAppMetrics1 = new HashMap<>();
+ Map<String, Integer> testAppMetrics2 = new HashMap<>();
+ testAppMetrics1.put("permit_decisions_count", 1);
+ testAppMetrics1.put("deny_decisions_count", 1);
+ testAppMetrics2.put("indeterminant_decisions_count", 1);
+ testAppMetrics2.put("not_applicable_decisions_count", 1);
+ Map<String, Map<String, Integer>> statisticsMap = new HashMap<>();
+ statisticsMap.put("testApp1", testAppMetrics1);
+ statisticsMap.put("testApp2", testAppMetrics2);
+ return statisticsMap;
}
private void updateXacmlPdpStatistics() {
@@ -117,13 +132,14 @@ public class TestXacmlPdpRestServer extends CommonRest {
++nupdates;
stats.setTotalPolicyCount(nupdates);
stats.setTotalPolicyTypesCount(nupdates);
- stats.updatePermitDecisionsCount();
- stats.updateDenyDecisionsCount();
- stats.updateIndeterminantDecisionsCount();
- stats.updateNotApplicableDecisionsCount();
+ stats.updatePermitDecisionsCount("testApp1");
+ stats.updateDenyDecisionsCount("testApp1");
+ stats.updateIndeterminantDecisionsCount("testApp2");
+ stats.updateNotApplicableDecisionsCount("testApp2");
}
- private void validateStatisticsReport(final StatisticsReport report, final int count, final int code) {
+ private void validateStatisticsReport(final StatisticsReport report, final int count,
+ final int code, final Map<String, Map<String, Integer>> decisionsMap) {
assertEquals(code, report.getCode());
assertEquals(count, report.getTotalPoliciesCount());
assertEquals(count, report.getTotalPolicyTypesCount());
@@ -131,6 +147,7 @@ public class TestXacmlPdpRestServer extends CommonRest {
assertEquals(count, report.getDenyDecisionsCount());
assertEquals(count, report.getIndeterminantDecisionsCount());
assertEquals(count, report.getNotApplicableDecisionsCount());
+ assertEquals(decisionsMap, report.getApplicationMetrics());
}
private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
index 030b9075..856a29a3 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2022 AT&T Intellectual Property. 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.
@@ -23,6 +23,8 @@ package org.onap.policy.pdpx.main.rest;
import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Test;
import org.onap.policy.pdpx.main.CommonRest;
import org.onap.policy.pdpx.main.rest.model.StatisticsReport;
@@ -43,20 +45,31 @@ public class TestXacmlPdpStatistics extends CommonRest {
public void testXacmlPdpStatistics_200() throws Exception {
LOGGER.info("*************************** Running testXacmlPdpStatistics_200 ***************************");
StatisticsReport report = getXacmlPdpStatistics();
- validateReport(report, 0, 200);
+ validateReport(report, 0, 200, new HashMap<>());
updateXacmlPdpStatistics();
report = getXacmlPdpStatistics();
- validateReport(report, 1, 200);
+ validateReport(report, 1, 200, returnStatisticsMap());
}
@Test
public void testXacmlPdpStatistics_500() throws Exception {
LOGGER.info("***************************** Running testXacmlPdpStatistics_500 *****************************");
-
markActivatorDead();
-
final StatisticsReport report = getXacmlPdpStatistics();
- validateReport(report, 0, 500);
+ validateReport(report, 0, 500, new HashMap<>());
+ }
+
+ private Map<String, Map<String, Integer>> returnStatisticsMap() {
+ Map<String, Integer> testAppMetrics1 = new HashMap<>();
+ Map<String, Integer> testAppMetrics2 = new HashMap<>();
+ testAppMetrics1.put("permit_decisions_count", 1);
+ testAppMetrics1.put("deny_decisions_count", 1);
+ testAppMetrics2.put("indeterminant_decisions_count", 1);
+ testAppMetrics2.put("not_applicable_decisions_count", 1);
+ Map<String, Map<String, Integer>> statisticsMap = new HashMap<>();
+ statisticsMap.put("testApp1", testAppMetrics1);
+ statisticsMap.put("testApp2", testAppMetrics2);
+ return statisticsMap;
}
private StatisticsReport getXacmlPdpStatistics() throws Exception {
@@ -69,13 +82,14 @@ public class TestXacmlPdpStatistics extends CommonRest {
++nupdates;
stats.setTotalPolicyCount(nupdates);
stats.setTotalPolicyTypesCount(nupdates);
- stats.updatePermitDecisionsCount();
- stats.updateDenyDecisionsCount();
- stats.updateIndeterminantDecisionsCount();
- stats.updateNotApplicableDecisionsCount();
+ stats.updatePermitDecisionsCount("testApp1");
+ stats.updateDenyDecisionsCount("testApp1");
+ stats.updateIndeterminantDecisionsCount("testApp2");
+ stats.updateNotApplicableDecisionsCount("testApp2");
}
- private void validateReport(final StatisticsReport report, final int count, final int code) {
+ private void validateReport(final StatisticsReport report, final int count,
+ final int code, final Map<String, Map<String, Integer>> decisionsMap) {
assertEquals(code, report.getCode());
assertEquals(count, report.getTotalPoliciesCount());
assertEquals(count, report.getTotalPolicyTypesCount());
@@ -83,5 +97,6 @@ public class TestXacmlPdpStatistics extends CommonRest {
assertEquals(count, report.getDenyDecisionsCount());
assertEquals(count, report.getIndeterminantDecisionsCount());
assertEquals(count, report.getNotApplicableDecisionsCount());
+ assertEquals(decisionsMap, report.getApplicationMetrics());
}
}