summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorning.xi <ning.xi@est.tech>2019-12-26 21:28:20 +0800
committerRam Krishna Verma <ram.krishna.verma@est.tech>2020-01-09 14:44:39 +0000
commitf3d671360961af57fa8921ecfebcdf6f1fa17243 (patch)
tree6de5da070fa38a59a5f0a8dee5be2a64111284f4 /main/src/test
parent46c781f75fd1f29fd15bb81d9b4d640aa315cab8 (diff)
statistics rest api update
Issue-ID: POLICY-1629 Signed-off-by: ning.xi <ning.xi@est.tech> Change-Id: I104fc448d27a282c01e7f54db300f918374b8d07
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java7
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java88
-rw-r--r--main/src/test/resources/META-INF/persistence.xml1
3 files changed, 95 insertions, 1 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
index 1894fd7b..70deedc1 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,10 +36,15 @@ import org.onap.policy.pap.main.PapConstants;
public class TestStatisticsRestControllerV1 extends CommonPapRestServer {
private static final String STATISTICS_ENDPOINT = "statistics";
+ private static final String STATISTICS_DB_ENDPOINT = "pdps/statistics";
@Test
public void testSwagger() throws Exception {
super.testSwagger(STATISTICS_ENDPOINT);
+ super.testSwagger(STATISTICS_DB_ENDPOINT);
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}");
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}" + "/{type}");
+ super.testSwagger(STATISTICS_DB_ENDPOINT + "/{group}" + "/{type}" + "/{pdp}");
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
index 13492cf9..aa2c59ea 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/StatisticsTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +24,27 @@ package org.onap.policy.pap.main.rest.e2e;
import static org.junit.Assert.assertEquals;
import java.net.HttpURLConnection;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
import org.junit.Test;
import org.onap.policy.common.utils.services.Registry;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.rest.PapStatisticsManager;
import org.onap.policy.pap.main.rest.StatisticsReport;
public class StatisticsTest extends End2EndBase {
private static final String STATISTICS_ENDPOINT = "statistics";
+ private List<PdpStatistics> recordList = new ArrayList<>();
@Test
@@ -56,6 +69,47 @@ public class StatisticsTest extends End2EndBase {
assertEquals(report.getPolicyDeployFailureCount() + 1, report2.getPolicyDeployFailureCount());
}
+ @Test
+ public void testDb() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithGroup() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+
+ }
+
+ @Test
+ public void testDbWithSubGroup() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithPdp() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex/pdp1");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
+ @Test
+ public void testDbWithPdpLatest() throws Exception {
+ setupEnv();
+ Invocation.Builder invocationBuilder = sendRequest("pdps/statistics/defaultGroup/apex/pdp1?recordCount=5");
+ Response testResponse = invocationBuilder.get();
+ verifyResponse(testResponse);
+ }
+
private void updateDistributionStatistics() {
PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class);
@@ -68,4 +122,38 @@ public class StatisticsTest extends End2EndBase {
mgr.updatePolicyDownloadSuccessCount();
mgr.updatePolicyDownloadFailureCount();
}
+
+ private void setupEnv() {
+ PolicyModelsProviderFactoryWrapper modelProviderWrapper =
+ Registry.get(PapConstants.REG_PAP_DAO_FACTORY, PolicyModelsProviderFactoryWrapper.class);
+
+ try (PolicyModelsProvider databaseProvider = modelProviderWrapper.create()) {
+ PdpStatistics pdpStatisticsRecord = new PdpStatistics();
+ pdpStatisticsRecord.setPdpGroupName("defaultGroup");
+ pdpStatisticsRecord.setPdpSubGroupName("apex");
+ pdpStatisticsRecord.setPdpInstanceId("pdp1");
+ pdpStatisticsRecord.setTimeStamp(new Date());
+ pdpStatisticsRecord.setPolicyDeployCount(1);
+ pdpStatisticsRecord.setPolicyDeployFailCount(0);
+ pdpStatisticsRecord.setPolicyDeploySuccessCount(1);
+ pdpStatisticsRecord.setPolicyExecutedCount(1);
+ pdpStatisticsRecord.setPolicyExecutedFailCount(0);
+ pdpStatisticsRecord.setPolicyExecutedSuccessCount(1);
+ recordList.add(pdpStatisticsRecord);
+ databaseProvider.createPdpStatistics(recordList);
+ } catch (final PfModelException exp) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, exp.getMessage());
+ }
+ }
+
+ private void verifyResponse(Response testResponse) {
+ assertEquals(Response.Status.OK.getStatusCode(), testResponse.getStatus());
+ Map<String, Map<String, List<PdpStatistics>>> map =
+ testResponse.readEntity(new GenericType<Map<String, Map<String, List<PdpStatistics>>>>() {});
+ Map<String, List<PdpStatistics>> subMap = map.get("defaultGroup");
+ List<PdpStatistics> resRecord = subMap.get("apex");
+ assertEquals("pdp1", resRecord.get(0).getPdpInstanceId());
+ assertEquals("apex", resRecord.get(0).getPdpSubGroupName());
+ assertEquals("defaultGroup", resRecord.get(0).getPdpGroupName());
+ }
}
diff --git a/main/src/test/resources/META-INF/persistence.xml b/main/src/test/resources/META-INF/persistence.xml
index 40b62197..ed09e78a 100644
--- a/main/src/test/resources/META-INF/persistence.xml
+++ b/main/src/test/resources/META-INF/persistence.xml
@@ -32,6 +32,7 @@
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
+ <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create" />