aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorHenry.Sun <henry.a.sun@est.tech>2019-12-13 13:46:35 +0800
committerHenry.Sun <henry.a.sun@est.tech>2020-01-10 00:39:59 +0800
commit8ed8fd648b4bd58aa7e23a9c3a326d2871717233 (patch)
tree730c82f0a3f6c0b3c299ae87786c85aade930da1 /main/src/test
parentd97629ff8ec522d30d1f552201496182c72559ab (diff)
validate and save PdpStatistisc
Issue-ID: POLICY-2303 Change-Id: Ide10256556a20e2ab3977ab2cfd876dd82e44390 Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java129
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java16
-rw-r--r--main/src/test/resources/META-INF/persistence.xml6
3 files changed, 148 insertions, 3 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
index 93d65a09..7dd7eefa 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-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.
@@ -22,7 +22,10 @@ package org.onap.policy.pap.main.comm;
import static org.junit.Assert.assertEquals;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
+import java.util.Date;
import java.util.List;
import org.junit.Test;
@@ -30,6 +33,7 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
@@ -52,6 +56,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
+ private Date timeStamp;
private PdpHeartbeatListener pdpHeartbeatListener;
@Test
@@ -180,7 +185,122 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
status9.setPolicies(idents9);
pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status9);
verifyPdpGroup(DEFAULT_GROUP, 0);
+ }
+
+ @Test
+ public void testPdpStatistics() throws CoderException, PfModelException, ParseException {
+ addGroups("PdpGroups.json");
+ pdpHeartbeatListener = new PdpHeartbeatListener();
+ timeStamp = new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01");
+
+ // init default pdp group
+ final PdpStatus status1 = new PdpStatus();
+ status1.setName(PDP_NAME);
+ status1.setState(PdpState.ACTIVE);
+ status1.setPdpGroup(DEFAULT_GROUP);
+ status1.setPdpType(APEX_TYPE);
+ status1.setHealthy(PdpHealthStatus.HEALTHY);
+ final List<ToscaPolicyIdentifier> idents1 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status1.setPolicies(idents1);
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status1);
+ verifyPdpGroup(DEFAULT_GROUP, 1);
+
+ // init pdp instance
+ final PdpStatus status2 = new PdpStatus();
+ status2.setName(PDP_NAME);
+ status2.setState(PdpState.ACTIVE);
+ status2.setPdpGroup(DEFAULT_GROUP);
+ status2.setPdpType(APEX_TYPE);
+ status2.setHealthy(PdpHealthStatus.HEALTHY);
+ status2.setPdpSubgroup(APEX_TYPE);
+ final List<ToscaPolicyIdentifier> idents2 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status2.setPolicies(idents2);
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status2);
+
+ // Testing passing pdp statistics success case
+ final PdpStatus status3 = new PdpStatus();
+ status3.setName(PDP_NAME);
+ status3.setState(PdpState.ACTIVE);
+ status3.setPdpGroup(DEFAULT_GROUP);
+ status3.setPdpType(APEX_TYPE);
+ status3.setHealthy(PdpHealthStatus.HEALTHY);
+ status3.setPdpSubgroup(APEX_TYPE);
+ final List<ToscaPolicyIdentifier> idents3 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status3.setPolicies(idents3);
+ PdpStatistics pdpStatistics03 = new PdpStatistics();
+ pdpStatistics03.setPdpInstanceId(PDP_NAME);
+ pdpStatistics03.setPdpGroupName(DEFAULT_GROUP);
+ pdpStatistics03.setPdpSubGroupName(APEX_TYPE);
+ pdpStatistics03.setTimeStamp(timeStamp);
+ status3.setStatistics(pdpStatistics03);
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status3);
+ verifyPdpStatistics(PDP_NAME, DEFAULT_GROUP, null, 1);
+
+ // Testing pdp statistics failure having the pdpStatistics null in the heartbeat for already registered pdp
+ final PdpStatus status4 = new PdpStatus();
+ status4.setName(PDP_NAME);
+ status4.setState(PdpState.ACTIVE);
+ status4.setPdpGroup(DEFAULT_GROUP);
+ status4.setPdpType(APEX_TYPE);
+ status4.setHealthy(PdpHealthStatus.HEALTHY);
+ status4.setPdpSubgroup(APEX_TYPE);
+ final List<ToscaPolicyIdentifier> idents4 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status4.setPolicies(idents4);
+ status4.setStatistics(null);
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status4);
+ verifyPdpStatistics(PDP_NAME, DEFAULT_GROUP, null, 1);
+
+ // Testing pdp statistics failure passing different pdpGroup, PdpSubGroup & pdpInstanceId
+ final PdpStatus status5 = new PdpStatus();
+ status5.setName(PDP_NAME);
+ status5.setState(PdpState.ACTIVE);
+ status5.setPdpGroup(DEFAULT_GROUP);
+ status5.setPdpType(APEX_TYPE);
+ status5.setHealthy(PdpHealthStatus.HEALTHY);
+ status5.setPdpSubgroup(APEX_TYPE);
+ final List<ToscaPolicyIdentifier> idents5 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status5.setPolicies(idents5);
+
+ PdpStatistics pdpStatistics05 = new PdpStatistics();
+ pdpStatistics05.setPdpInstanceId("pdp_2");
+ pdpStatistics05.setPdpGroupName("defaultGroup_1");
+ pdpStatistics05.setPdpSubGroupName("apex_1");
+ pdpStatistics03.setTimeStamp(timeStamp);
+ status5.setStatistics(pdpStatistics05);
+
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status5);
+ verifyPdpStatistics(null, DEFAULT_GROUP, null, 1);
+
+ // Test pdp statistics failure passing negative values
+ final PdpStatus status6 = new PdpStatus();
+ status6.setName(PDP_NAME);
+ status6.setState(PdpState.ACTIVE);
+ status6.setPdpGroup(DEFAULT_GROUP);
+ status6.setPdpType(APEX_TYPE);
+ status6.setHealthy(PdpHealthStatus.HEALTHY);
+ status6.setPdpSubgroup(APEX_TYPE);
+ final List<ToscaPolicyIdentifier> idents6 =
+ Arrays.asList(new ToscaPolicyIdentifier(POLICY_NAME, POLICY_VERSION));
+ status5.setPolicies(idents6);
+
+ PdpStatistics pdpStatistics06 = new PdpStatistics();
+ pdpStatistics06.setPdpInstanceId(PDP_NAME);
+ pdpStatistics06.setPdpGroupName(DEFAULT_GROUP);
+ pdpStatistics06.setPdpSubGroupName(APEX_TYPE);
+ pdpStatistics03.setTimeStamp(timeStamp);
+
+ pdpStatistics06.setPolicyDeployCount(-1);
+ pdpStatistics06.setPolicyDeployFailCount(-1);
+ status5.setStatistics(pdpStatistics06);
+
+ pdpHeartbeatListener.onTopicEvent(INFRA, TOPIC, status5);
+ verifyPdpStatistics(null, DEFAULT_GROUP, null, 1);
}
private void verifyPdpGroup(final String name, final int count) throws PfModelException {
@@ -195,4 +315,11 @@ public class PdpHeartbeatListenerTest extends End2EndBase {
}
}
}
+
+ private void verifyPdpStatistics(final String pdpInstanceId, final String pdpGroupName,
+ final String pdpSubGroupName, final int count) throws PfModelException {
+ final List<PdpStatistics> fetchedPdpStatistics =
+ fetchPdpStatistics(pdpInstanceId, pdpGroupName, pdpSubGroupName);
+ assertEquals(count, fetchedPdpStatistics.size());
+ }
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
index e6dd2005..abec6d72 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
@@ -3,7 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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.
@@ -38,6 +38,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
@@ -182,6 +183,19 @@ public class End2EndBase extends CommonPapRestServer {
}
/**
+ * Fetch PDP statistics from the DB.
+ *
+ * @param instanceId name of the pdpStatistics
+ * @param groupName name of the pdpGroup
+ * @param subGroupName name of the pdpSubGroup
+ * @throws PfModelException if a DAO error occurs
+ */
+ public static List<PdpStatistics> fetchPdpStatistics(final String instanceId, final String groupName,
+ final String subGroupName) throws PfModelException {
+ return dbConn.getFilteredPdpStatistics(instanceId, groupName, subGroupName, null, null, null, 0);
+ }
+
+ /**
* Loads an object from a YAML file.
*
* @param fileName name of the file from which to load
diff --git a/main/src/test/resources/META-INF/persistence.xml b/main/src/test/resources/META-INF/persistence.xml
index f2078164..423bd75f 100644
--- a/main/src/test/resources/META-INF/persistence.xml
+++ b/main/src/test/resources/META-INF/persistence.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
- Copyright (C) 2019 Nordix Foundation.
+ Copyright (C) 2019-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.
@@ -26,11 +26,13 @@
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
<class>org.onap.policy.models.base.PfConceptKey</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
<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" />
@@ -46,11 +48,13 @@
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
<class>org.onap.policy.models.base.PfConceptKey</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
<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" />