summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java2
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java38
-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/e2e/PapConfigParameters.json20
-rw-r--r--main/src/test/resources/parameters/MinimumParameters.json20
-rw-r--r--main/src/test/resources/parameters/PapConfigParameters.json20
-rw-r--r--main/src/test/resources/parameters/PapConfigParametersStd.json20
8 files changed, 209 insertions, 6 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
index 8660d005..3823365b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
@@ -72,7 +72,7 @@ public class CommonPapRestServer {
public static final String NOT_ALIVE = "not alive";
public static final String ALIVE = "alive";
- public static final String SELF = "self";
+ public static final String SELF = NetworkUtil.getHostname();
public static final String NAME = "Policy PAP";
public static final String ENDPOINT_PREFIX = "policy/pap/v1/";
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java
new file mode 100644
index 00000000..f73178b7
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest;
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
+ *
+ * @author Yehui Wang (yehui.wang@est.tech)
+ */
+public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
+
+ private static final String ENDPOINT = "components/healthcheck";
+
+ @Test
+ public void testSwagger() throws Exception {
+ super.testSwagger(ENDPOINT);
+ }
+}
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/e2e/PapConfigParameters.json b/main/src/test/resources/e2e/PapConfigParameters.json
index 17507bdb..610ded8c 100644
--- a/main/src/test/resources/e2e/PapConfigParameters.json
+++ b/main/src/test/resources/e2e/PapConfigParameters.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/MinimumParameters.json b/main/src/test/resources/parameters/MinimumParameters.json
index 6b21b4dc..69492e9b 100644
--- a/main/src/test/resources/parameters/MinimumParameters.json
+++ b/main/src/test/resources/parameters/MinimumParameters.json
@@ -37,5 +37,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "dmaap"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/PapConfigParameters.json b/main/src/test/resources/parameters/PapConfigParameters.json
index 11315029..111a6352 100644
--- a/main/src/test/resources/parameters/PapConfigParameters.json
+++ b/main/src/test/resources/parameters/PapConfigParameters.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}
diff --git a/main/src/test/resources/parameters/PapConfigParametersStd.json b/main/src/test/resources/parameters/PapConfigParametersStd.json
index 828c1a44..47925dff 100644
--- a/main/src/test/resources/parameters/PapConfigParametersStd.json
+++ b/main/src/test/resources/parameters/PapConfigParametersStd.json
@@ -42,5 +42,23 @@
"servers" : [ "message-router" ],
"topicCommInfrastructure" : "noop"
}]
- }
+ },
+ "healthCheckRestClientParameters":[{
+ "clientName": "api",
+ "hostname": "policy-api",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "policy/api/v1/healthcheck"
+ },
+ {
+ "clientName": "distribution",
+ "hostname": "policy-distribution",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34",
+ "useHttps": true,
+ "basePath": "healthcheck"
+ }]
}