summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.input.json (renamed from models-examples/src/main/resources/policies/vCPE.policy.operational.input.json)0
-rw-r--r--models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.output.json (renamed from models-examples/src/main/resources/policies/vCPE.policy.operational.output.json)0
-rw-r--r--models-examples/src/main/resources/policies/vCPE.policy.operational.output.tosca.yaml2
-rw-r--r--models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.input.json (renamed from models-examples/src/main/resources/policies/vDNS.policy.operational.input.json)0
-rw-r--r--models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.output.json (renamed from models-examples/src/main/resources/policies/vDNS.policy.operational.output.json)0
-rw-r--r--models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json39
-rw-r--r--models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.input.json (renamed from models-examples/src/main/resources/policies/vFirewall.policy.operational.input.json)0
-rw-r--r--models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.output.json (renamed from models-examples/src/main/resources/policies/vFirewall.policy.operational.output.json)0
-rw-r--r--models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml2
-rw-r--r--models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml37
-rw-r--r--models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml1
-rw-r--r--models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml13
-rw-r--r--models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml2
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatistics.java13
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java12
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java62
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java40
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java119
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java23
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java6
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java4
23 files changed, 275 insertions, 117 deletions
diff --git a/models-examples/src/main/resources/policies/vCPE.policy.operational.input.json b/models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.input.json
index 7d26e8e67..7d26e8e67 100644
--- a/models-examples/src/main/resources/policies/vCPE.policy.operational.input.json
+++ b/models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.input.json
diff --git a/models-examples/src/main/resources/policies/vCPE.policy.operational.output.json b/models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.output.json
index 7d26e8e67..7d26e8e67 100644
--- a/models-examples/src/main/resources/policies/vCPE.policy.operational.output.json
+++ b/models-examples/src/main/resources/policies/vCPE.policy.operational.legacy.output.json
diff --git a/models-examples/src/main/resources/policies/vCPE.policy.operational.output.tosca.yaml b/models-examples/src/main/resources/policies/vCPE.policy.operational.output.tosca.yaml
index e4a06947f..2c7981a29 100644
--- a/models-examples/src/main/resources/policies/vCPE.policy.operational.output.tosca.yaml
+++ b/models-examples/src/main/resources/policies/vCPE.policy.operational.output.tosca.yaml
@@ -23,7 +23,7 @@ topology_template:
actor: APPC
recipe: Restart
target:
- type: VM
+ targetType: VM
retry: 3
timeout: 1200
success: final_success
diff --git a/models-examples/src/main/resources/policies/vDNS.policy.operational.input.json b/models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.input.json
index 5ce44e0ba..5ce44e0ba 100644
--- a/models-examples/src/main/resources/policies/vDNS.policy.operational.input.json
+++ b/models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.input.json
diff --git a/models-examples/src/main/resources/policies/vDNS.policy.operational.output.json b/models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.output.json
index 5ce44e0ba..5ce44e0ba 100644
--- a/models-examples/src/main/resources/policies/vDNS.policy.operational.output.json
+++ b/models-examples/src/main/resources/policies/vDNS.policy.operational.legacy.output.json
diff --git a/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json b/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json
index 63c0d8b85..f6f15fe50 100644
--- a/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json
+++ b/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json
@@ -4,32 +4,32 @@
"policies": [
{
"operational.modifyconfig": {
- "type": "onap.policies.controlloop.Operational",
- "version": "1.0.0",
+ "type": "onap.policies.controlloop.operational.common.Drools",
+ "type_version": "1.0.0",
"metadata": {
"policy-id": "operational.modifyconfig"
},
"properties": {
- "controlLoop": {
- "version": "2.0.0",
- "controlLoopName": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
- "trigger_policy": "unique-policy-id-1-modifyConfig",
- "timeout": 1200,
- "abatement": false
- },
- "policies": [
+ "id": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
+ "timeout": 1200,
+ "abatement": false,
+ "trigger": "unique-policy-id-1-modifyConfig",
+ "operations": [
{
"id": "unique-policy-id-1-modifyConfig",
- "name": "modify packet gen config",
- "description": null,
- "actor": "APPC",
- "recipe": "ModifyConfig",
- "target": {
- "resourceID": "Eace933104d443b496b8.nodes.heat.vpg",
- "type": "VNF"
+ "description": "Modify the packet generator",
+ "operation": {
+ "actor": "APPC",
+ "operation": "ModifyConfig",
+ "target": {
+ "targetType": "VNF",
+ "entityId": {
+ "resourceID": "bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"
+ }
+ }
},
- "retry": 0,
"timeout": 300,
+ "retries": 0,
"success": "final_success",
"failure": "final_failure",
"failure_timeout": "final_failure_timeout",
@@ -37,7 +37,8 @@
"failure_exception": "final_failure_exception",
"failure_guard": "final_failure_guard"
}
- ]
+ ],
+ "controllerName": "usecases"
}
}
}
diff --git a/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.json b/models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.input.json
index bb8b907f8..bb8b907f8 100644
--- a/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.json
+++ b/models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.input.json
diff --git a/models-examples/src/main/resources/policies/vFirewall.policy.operational.output.json b/models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.output.json
index bb8b907f8..bb8b907f8 100644
--- a/models-examples/src/main/resources/policies/vFirewall.policy.operational.output.json
+++ b/models-examples/src/main/resources/policies/vFirewall.policy.operational.legacy.output.json
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml
index f21fd5afb..773e0c90b 100644
--- a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml
+++ b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml
@@ -3,4 +3,4 @@ policy_types:
onap.policies.controlloop.Operational:
derived_from: tosca.policies.Root
version: 1.0.0
- description: Operational Policy for Control Loops \ No newline at end of file
+ description: Operational Policy for Control Loops Supporting Legacy YAML Policy Definition. \ No newline at end of file
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml
index 0dbe7e41a..4a918bef1 100644
--- a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml
+++ b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml
@@ -3,7 +3,9 @@ policy_types:
onap.policies.controlloop.operational.Common:
derived_from: tosca.policies.Root
version: 1.0.0
- description: Operational Policy for Control Loop execution
+ description: |
+ Operational Policy for Control Loop execution. Originated in Frankfurt to support TOSCA Compliant
+ Policy Types. This does NOT support the legacy Policy YAML policy type.
properties:
id:
type: string
@@ -31,36 +33,7 @@ policy_types:
entry_schema:
type: onap.datatype.controlloop.Operation
- onap.policies.controlloop.operational.common.Drools:
- derived_from: onap.policies.controlloop.operational.Common
- type_version: 1.0.0
- version: 1.0.0
- description: Operational policies for Drools PDP
- properties:
- controllerName:
- type: string
- description: Drools controller properties
- required: false
-
data_types:
- # TBD if this is needed
- onap.datatype.controlloop.operation.Failure:
- derived_from: tosca.datatypes.Root
- description: Captures information of an operational failure performed for control loop
- properties:
- messages:
- type: string
- description: error message
- required: true
- category:
- type: string
- description: |
- The category the error occurred in. Whether this is a general error from the actor, or the operation
- timed out, retries were exhausted in trying to execute the operation, a guard policy prevented the
- operation from occuring, or an exception in the system caused the failure.
- constraints:
- - valid_values: [error, timeout, retries, guard, exception]
-
onap.datatype.controlloop.Target:
derived_from: tosca.datatypes.Root
description: Definition for a entity in A&AI to perform a control loop operation on
@@ -77,6 +50,8 @@ data_types:
Map of values that identify the resource. If none are provided, it is assumed that the
entity that generated the ONSET event will be the target.
required: false
+ entry_schema:
+ type: string
onap.datatype.controlloop.Actor:
derived_from: tosca.datatypes.Root
@@ -91,7 +66,7 @@ data_types:
description: The operation the actor is performing.
required: true
target:
- type: string
+ type: onap.datatype.controlloop.Target
description: The resource the operation should be performed on.
required: true
metadata:
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml
index e1555e8ed..9c6c6120d 100644
--- a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml
+++ b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml
@@ -2,6 +2,7 @@ tosca_definitions_version: tosca_simple_yaml_1_0_0
policy_types:
onap.policies.controlloop.operational.common.Apex:
derived_from: onap.policies.controlloop.operational.Common
+ type_version: 1.0.0
version: 1.0.0
description: Operational policies for Apex PDP
properties:
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml
new file mode 100644
index 000000000..2d793cc4b
--- /dev/null
+++ b/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml
@@ -0,0 +1,13 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ onap.policies.controlloop.operational.common.Drools:
+ derived_from: onap.policies.controlloop.operational.Common
+ type_version: 1.0.0
+ version: 1.0.0
+ description: Operational policies for Drools PDP
+ properties:
+ controllerName:
+ type: string
+ description: Drools controller properties
+ required: false
+
diff --git a/models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml b/models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml
index 4f124a2f1..8419b096f 100644
--- a/models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml
+++ b/models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml
@@ -5,7 +5,7 @@ policy_types:
description: a base policy type for all policies that govern monitoring provisioning
version: 1.0.0
onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:
- derived_from: policy.nodes.Root
+ derived_from: onap.policies.Monitoring
version: 1.0.0
properties:
buscontroller_feed_publishing_endpoint:
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatistics.java
index 43fa6c072..06f603069 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatistics.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,16 +22,13 @@ package org.onap.policy.models.pdp.concepts;
import java.io.Serializable;
import javax.persistence.Embeddable;
-import lombok.Getter;
+import lombok.Data;
import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.ToString;
+import lombok.NonNull;
import org.onap.policy.models.pdp.enums.PdpEngineWorkerState;
@Embeddable
-@Getter
-@Setter
-@ToString
+@Data
@NoArgsConstructor
public class PdpEngineWorkerStatistics implements Serializable {
private static final long serialVersionUID = 8262176849743624013L;
@@ -51,7 +48,7 @@ public class PdpEngineWorkerStatistics implements Serializable {
*
* @param source source from which to copy
*/
- public PdpEngineWorkerStatistics(PdpEngineWorkerStatistics source) {
+ public PdpEngineWorkerStatistics(@NonNull PdpEngineWorkerStatistics source) {
this.engineId = source.engineId;
this.engineWorkerState = source.engineWorkerState;
this.engineTimeStamp = source.engineTimeStamp;
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
index ad5547ecf..1ba983be2 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpStatistics.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * 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,10 +24,9 @@ package org.onap.policy.models.pdp.concepts;
import java.util.Date;
import java.util.List;
-import lombok.Getter;
+import lombok.Data;
import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.ToString;
+import lombok.NonNull;
import org.onap.policy.models.base.PfUtils;
/**
@@ -34,9 +34,7 @@ import org.onap.policy.models.base.PfUtils;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-@Getter
-@Setter
-@ToString
+@Data
@NoArgsConstructor
public class PdpStatistics {
@@ -57,7 +55,7 @@ public class PdpStatistics {
*
* @param source source from which to copy
*/
- public PdpStatistics(PdpStatistics source) {
+ public PdpStatistics(@NonNull PdpStatistics source) {
this.pdpInstanceId = source.pdpInstanceId;
this.timeStamp = source.timeStamp == null ? null : new Date(source.timeStamp.getTime());
this.pdpGroupName = source.pdpGroupName;
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
new file mode 100644
index 000000000..c0d2ba6bf
--- /dev/null
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpEngineWorkerStatisticsTest.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpEngineWorkerState;
+
+public class PdpEngineWorkerStatisticsTest {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new PdpEngineWorkerStatistics(null)).hasMessageContaining("source");
+
+ PdpEngineWorkerStatistics stat = createPdpEngineWorkerStatistics();
+ PdpEngineWorkerStatistics stat2 = new PdpEngineWorkerStatistics(stat);
+ assertEquals(stat, stat2);
+ }
+
+ @Test
+ public void testClean() {
+ PdpEngineWorkerStatistics stat = createPdpEngineWorkerStatistics();
+ stat.setEngineId(" Engine0 ");
+ stat.clean();
+ assertEquals("Engine0", stat.getEngineId());
+ }
+
+ private PdpEngineWorkerStatistics createPdpEngineWorkerStatistics() {
+ PdpEngineWorkerStatistics stat = new PdpEngineWorkerStatistics();
+ stat.setEngineId("Engine0");
+ stat.setEngineWorkerState(PdpEngineWorkerState.READY);
+ stat.setEngineTimeStamp(new Date().getTime());
+ stat.setEventCount(1);
+ stat.setLastExecutionTime(100);
+ stat.setAverageExecutionTime(99);
+ stat.setUpTime(1000);
+ stat.setLastEnterTime(2000);
+ stat.setLastStart(3000);
+ return stat;
+ }
+} \ No newline at end of file
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
index 08098cc28..adf9b9f7c 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStatisticsTest.java
@@ -3,6 +3,7 @@
* ONAP Policy Models
* ================================================================================
* 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.
@@ -22,32 +23,35 @@ package org.onap.policy.models.pdp.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
-import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
+import java.util.ArrayList;
+import java.util.Date;
import org.junit.Test;
public class PdpStatisticsTest {
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new PdpStatistics(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new PdpStatistics(null)).hasMessageContaining("source");
- PdpStatistics orig = new PdpStatistics();
-
- // verify with null values
- assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStatistics(orig).toString()));
-
- // verify with all values
- orig.setPdpInstanceId("my-instance");
-
- int count = 1;
- orig.setPolicyDeployCount(count++);
- orig.setPolicyDeployFailCount(count++);
- orig.setPolicyDeploySuccessCount(count++);
- orig.setPolicyExecutedCount(count++);
- orig.setPolicyExecutedFailCount(count++);
- orig.setPolicyExecutedSuccessCount(count++);
+ PdpStatistics orig = createPdpStatistics();
+ PdpStatistics copied = new PdpStatistics(orig);
+ assertEquals(orig, copied);
+ }
- assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpStatistics(orig).toString()));
+ private PdpStatistics createPdpStatistics() {
+ PdpStatistics pdpStat = new PdpStatistics();
+ pdpStat.setPdpInstanceId("PDP0");
+ pdpStat.setPdpGroupName("PDPGroup0");
+ pdpStat.setPdpSubGroupName("PDPSubGroup0");
+ pdpStat.setTimeStamp(new Date());
+ pdpStat.setPolicyDeployCount(3);
+ pdpStat.setPolicyDeploySuccessCount(1);
+ pdpStat.setPolicyDeployFailCount(2);
+ pdpStat.setPolicyExecutedCount(9);
+ pdpStat.setPolicyExecutedSuccessCount(4);
+ pdpStat.setPolicyExecutedFailCount(5);
+ pdpStat.setEngineStats(new ArrayList<>());
+ return pdpStat;
}
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
index 62f0c5be0..0b22e1b3e 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpStatisticsTest.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.
@@ -21,22 +21,123 @@
package org.onap.policy.models.pdp.persistence.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.Date;
import org.junit.Test;
+import org.onap.policy.models.base.PfTimestampKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
/**
* Test the {@link JpaPdpStatistics} class.
- *
*/
public class JpaPdpStatisticsTest {
- private static final String NULL_KEY_ERROR = "key is marked @NonNull but is null";
- private static final String PDP1 = "ThePDP";
- // TODO More unit test cases will be added later.
@Test
- public void testJpaPdpStatistics() {
- assertThatThrownBy(() -> {
- new JpaPdpStatistics((JpaPdpStatistics) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ public void testConstructor() {
+ assertThatThrownBy(() -> new JpaPdpStatistics((PfTimestampKey) null)).hasMessageContaining("key");
+
+ assertThatThrownBy(() -> new JpaPdpStatistics((JpaPdpStatistics) null))
+ .hasMessageContaining("copyConcept");
+
+ assertThatThrownBy(() -> new JpaPdpStatistics((PdpStatistics) null))
+ .hasMessageContaining("authorativeConcept");
+
+ assertNotNull(new JpaPdpStatistics());
+ assertNotNull(new JpaPdpStatistics(new PfTimestampKey()));
+
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat = new JpaPdpStatistics(createPdpStatistics());
+ checkEquals(pdpStat, jpaPdpStat);
+
+ JpaPdpStatistics jpaPdpStat2 = new JpaPdpStatistics(jpaPdpStat);
+ assertEquals(0, jpaPdpStat2.compareTo(jpaPdpStat));
+ }
+
+ @Test
+ public void testFromAuthorative() {
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat = new JpaPdpStatistics();
+ jpaPdpStat.fromAuthorative(pdpStat);
+ checkEquals(pdpStat, jpaPdpStat);
+ }
+
+ @Test
+ public void testToAuthorative() {
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat = new JpaPdpStatistics(pdpStat);
+ PdpStatistics toPdpStat = jpaPdpStat.toAuthorative();
+ assertEquals(pdpStat, toPdpStat);
+ }
+
+ @Test
+ public void testCompareTo() {
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat1 = new JpaPdpStatistics(pdpStat);
+ assertEquals(-1, jpaPdpStat1.compareTo(null));
+
+ JpaPdpStatistics jpaPdpStat2 = new JpaPdpStatistics(pdpStat);
+ assertEquals(0, jpaPdpStat1.compareTo(jpaPdpStat2));
+
+ PdpStatistics pdpStat3 = createPdpStatistics();
+ pdpStat3.setPdpInstanceId("PDP3");
+ JpaPdpStatistics jpaPdpStat3 = new JpaPdpStatistics(pdpStat3);
+ assertNotEquals(0, jpaPdpStat1.compareTo(jpaPdpStat3));
+ }
+
+ @Test
+ public void testValidate() {
+ JpaPdpStatistics nullKeyJpaPdpStat = new JpaPdpStatistics();
+ assertFalse(nullKeyJpaPdpStat.validate(new PfValidationResult()).isOk());
+
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat2 = new JpaPdpStatistics(pdpStat);
+ assertTrue(jpaPdpStat2.validate(new PfValidationResult()).isOk());
+ }
+
+ @Test
+ public void testClean() {
+ PdpStatistics pdpStat = createPdpStatistics();
+ JpaPdpStatistics jpaPdpStat = new JpaPdpStatistics(pdpStat);
+ jpaPdpStat.setPdpGroupName(" PDPGroup0 ");
+ jpaPdpStat.setPdpSubGroupName(" PDPSubGroup0 ");
+ jpaPdpStat.clean();
+ assertEquals("PDPGroup0", jpaPdpStat.getPdpGroupName());
+ assertEquals("PDPSubGroup0", jpaPdpStat.getPdpSubGroupName());
+ }
+
+ private void checkEquals(PdpStatistics pdpStat, JpaPdpStatistics jpaPdpStat) {
+ assertEquals(pdpStat.getPdpInstanceId(), jpaPdpStat.getKey().getName());
+ assertEquals(pdpStat.getPdpGroupName(), jpaPdpStat.getPdpGroupName());
+ assertEquals(pdpStat.getPdpSubGroupName(), jpaPdpStat.getPdpSubGroupName());
+ assertEquals(pdpStat.getTimeStamp(), jpaPdpStat.getKey().getTimeStamp());
+ assertEquals(pdpStat.getPolicyDeployCount(), jpaPdpStat.getPolicyDeployCount());
+ assertEquals(pdpStat.getPolicyDeploySuccessCount(), jpaPdpStat.getPolicyDeploySuccessCount());
+ assertEquals(pdpStat.getPolicyDeployFailCount(), jpaPdpStat.getPolicyDeployFailCount());
+ assertEquals(pdpStat.getPolicyExecutedCount(), jpaPdpStat.getPolicyExecutedCount());
+ assertEquals(pdpStat.getPolicyExecutedSuccessCount(), jpaPdpStat.getPolicyExecutedSuccessCount());
+ assertEquals(pdpStat.getPolicyExecutedFailCount(), jpaPdpStat.getPolicyExecutedFailCount());
+ }
+
+ private PdpStatistics createPdpStatistics() {
+ PdpStatistics pdpStat = new PdpStatistics();
+ pdpStat.setPdpInstanceId("PDP0");
+ pdpStat.setPdpGroupName("PDPGroup0");
+ pdpStat.setPdpSubGroupName("PDPSubGroup0");
+ pdpStat.setTimeStamp(new Date());
+ pdpStat.setPolicyDeployCount(3);
+ pdpStat.setPolicyDeploySuccessCount(1);
+ pdpStat.setPolicyDeployFailCount(2);
+ pdpStat.setPolicyExecutedCount(9);
+ pdpStat.setPolicyExecutedSuccessCount(4);
+ pdpStat.setPolicyExecutedFailCount(5);
+ pdpStat.setEngineStats(new ArrayList<>());
+ return pdpStat;
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
index 47855c4cd..30428b099 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,15 +56,15 @@ public class PolicyLegacyOperationalPersistenceTest {
// @formatter:off
private String[] policyInputResourceNames = {
- "policies/vCPE.policy.operational.input.json",
- "policies/vDNS.policy.operational.input.json",
- "policies/vFirewall.policy.operational.input.json"
+ "policies/vCPE.policy.operational.legacy.input.json",
+ "policies/vDNS.policy.operational.legacy.input.json",
+ "policies/vFirewall.policy.operational.legacy.input.json"
};
private String[] policyOutputResourceNames = {
- "policies/vCPE.policy.operational.output.json",
- "policies/vDNS.policy.operational.output.json",
- "policies/vFirewall.policy.operational.output.json"
+ "policies/vCPE.policy.operational.legacy.output.json",
+ "policies/vDNS.policy.operational.legacy.output.json",
+ "policies/vFirewall.policy.operational.legacy.output.json"
};
// @formatter:on
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
index 0bf371022..858ac09fe 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
@@ -87,6 +87,7 @@ public class ToscaPolicyFilterTest {
for (String policyResourceName : policyResourceNames) {
String policyString = ResourceUtils.getResourceAsString(policyResourceName);
if (policyResourceName.endsWith("yaml")) {
+ LOGGER.info("loading {}", policyResourceName);
Object yamlObject = new Yaml().load(policyString);
policyString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
}
@@ -150,7 +151,7 @@ public class ToscaPolicyFilterTest {
assertEquals(VERSION_100, filteredList.get(7).getVersion());
assertEquals(VERSION_100, filteredList.get(12).getVersion());
- assertEquals(24, policyList.size());
+ assertEquals(23, policyList.size());
assertEquals(22, filteredList.size());
policyList.get(10).setVersion("2.0.0");
@@ -172,7 +173,7 @@ public class ToscaPolicyFilterTest {
public void testFilterNameVersion() {
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").build();
List<ToscaPolicy> filteredList = filter.filter(policyList);
- assertEquals(2, filteredList.size());
+ assertEquals(1, filteredList.size());
filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build();
filteredList = filter.filter(policyList);
@@ -184,7 +185,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().version(VERSION_100).build();
filteredList = filter.filter(policyList);
- assertEquals(22, filteredList.size());
+ assertEquals(21, filteredList.size());
filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build();
filteredList = filter.filter(policyList);
@@ -192,7 +193,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build();
filteredList = filter.filter(policyList);
- assertEquals(1, filteredList.size());
+ assertEquals(0, filteredList.size());
}
@Test
@@ -200,11 +201,11 @@ public class ToscaPolicyFilterTest {
// null pattern
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().versionPrefix(null).build();
List<ToscaPolicy> filteredList = filter.filter(policyList);
- assertEquals(24, filteredList.size());
+ assertEquals(23, filteredList.size());
filter = ToscaPolicyFilter.builder().versionPrefix("1.").build();
filteredList = filter.filter(policyList);
- assertEquals(22, filteredList.size());
+ assertEquals(21, filteredList.size());
filter = ToscaPolicyFilter.builder().versionPrefix("100.").build();
filteredList = filter.filter(policyList);
@@ -215,7 +216,11 @@ public class ToscaPolicyFilterTest {
public void testFilterTypeVersion() {
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").build();
List<ToscaPolicy> filteredList = filter.filter(policyList);
- assertEquals(1, filteredList.size());
+ assertEquals(0, filteredList.size());
+
+ filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Apex").build();
+ filteredList = filter.filter(policyList);
+ assertEquals(0, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.operational.common.Drools").build();
filteredList = filter.filter(policyList);
@@ -231,7 +236,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build();
filteredList = filter.filter(policyList);
- assertEquals(4, filteredList.size());
+ assertEquals(3, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy")
.typeVersion(VERSION_100).build();
@@ -241,6 +246,6 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000)
.build();
filteredList = filter.filter(policyList);
- assertEquals(1, filteredList.size());
+ assertEquals(0, filteredList.size());
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
index 0aa1da0d7..4dcfeafc9 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
@@ -71,7 +71,7 @@ public class LegacyOperationalPolicyMapperTest {
JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate();
policyTypeServiceTemplate.fromAuthorative(policyTypes);
- String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json");
+ String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.legacy.input.json");
LegacyOperationalPolicy legacyOperationalPolicy =
standardCoder.decode(vcpePolicyJson, LegacyOperationalPolicy.class);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
index ec03122a6..4d0fd6fd6 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 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.
@@ -51,8 +51,8 @@ import org.yaml.snakeyaml.Yaml;
*/
public class LegacyProvider4LegacyOperationalTest {
private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
- private static final String VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.output.json";
- private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.input.json";
+ private static final String VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.legacy.output.json";
+ private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.legacy.input.json";
private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private PfDao pfDao;
private StandardCoder standardCoder;
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
index 3c62a7424..0a8283e98 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -382,7 +382,7 @@ public class MonitoringPolicyTypeSerializationTest {
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
assertEquals(DCAE, secondPolicyType.getKey().getName());
assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
- assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
+ assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();