aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-01-10 14:29:30 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-10 14:29:30 +0000
commitf9abcdb123fd3a7489cf2dfa50f6f47c5e436355 (patch)
treed10f3d46537d833fd886e0eef0b00f1330b2a765 /main/src/test/java/org
parentf3d671360961af57fa8921ecfebcdf6f1fa17243 (diff)
parent8ed8fd648b4bd58aa7e23a9c3a326d2871717233 (diff)
Merge "validate and save PdpStatistisc"
Diffstat (limited to 'main/src/test/java/org')
-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
2 files changed, 143 insertions, 2 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