summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src/test/java/org/onap')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java35
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java20
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java50
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java82
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java96
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java5
7 files changed, 177 insertions, 113 deletions
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 64c3b1365..0bf371022 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
@@ -231,7 +231,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build();
filteredList = filter.filter(policyList);
- assertEquals(7, filteredList.size());
+ assertEquals(4, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy")
.typeVersion(VERSION_100).build();
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
index 82f75a721..a1a080df0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
@@ -3,7 +3,7 @@
* ONAP Policy Model
* ================================================================================
* 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.
@@ -29,11 +29,13 @@ import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils;
import org.yaml.snakeyaml.Yaml;
/**
@@ -44,6 +46,7 @@ import org.yaml.snakeyaml.Yaml;
public class ToscaServiceTemplateMappingTest {
private StandardCoder standardCoder;
+ private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
@Before
public void setUp() {
@@ -52,14 +55,25 @@ public class ToscaServiceTemplateMappingTest {
@Test
public void testPlainToscaPolicies() throws Exception {
- String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
+ String policyTypeInputJson =
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
+ ToscaServiceTemplate plainPolicyTypes =
+ yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class);
- ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class);
- JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate();
- internalPolicies.fromAuthorative(plainPolicies);
+ String policyInputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
+ ToscaServiceTemplate plainPolicies = standardCoder.decode(policyInputJson, ToscaServiceTemplate.class);
- assertTrue(internalPolicies.validate(new PfValidationResult()).isValid());
- ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative();
+ JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate();
+ policyTypeServiceTemplate.fromAuthorative(plainPolicyTypes);
+
+ JpaToscaServiceTemplate policyFragmentServiceTemplate = new JpaToscaServiceTemplate();
+ policyFragmentServiceTemplate.fromAuthorative(plainPolicies);
+
+ JpaToscaServiceTemplate internalServiceTemplate =
+ ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, policyFragmentServiceTemplate);
+
+ assertTrue(internalServiceTemplate.validate(new PfValidationResult()).isValid());
+ ToscaServiceTemplate plainPolicies2 = internalServiceTemplate.toAuthorative();
ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
@@ -70,13 +84,12 @@ public class ToscaServiceTemplateMappingTest {
@Test
public void testPlainToscaPolicyTypes() throws Exception {
Yaml yaml = new Yaml();
- String inputYaml = ResourceUtils.getResourceAsString(
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
+ String inputYaml =
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
Object yamlObject = yaml.load(inputYaml);
String yamlAsJsonString = standardCoder.encode(yamlObject);
- ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString,
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
internalPolicyTypes.fromAuthorative(plainPolicyTypes);
assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
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 e9761c669..0aa1da0d7 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,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,15 +31,17 @@ import java.util.LinkedHashMap;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
+import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,6 +55,7 @@ public class LegacyOperationalPolicyMapperTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapperTest.class);
private StandardCoder standardCoder;
+ private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
@Before
public void setUp() {
@@ -61,14 +64,23 @@ public class LegacyOperationalPolicyMapperTest {
@Test
public void testJsonDeserialization() throws Exception {
- String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json");
+ String policyTypeInputJson =
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml");
+ ToscaServiceTemplate policyTypes = yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate();
+ policyTypeServiceTemplate.fromAuthorative(policyTypes);
+ String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json");
LegacyOperationalPolicy legacyOperationalPolicy =
standardCoder.decode(vcpePolicyJson, LegacyOperationalPolicy.class);
- JpaToscaServiceTemplate serviceTemplate =
+ JpaToscaServiceTemplate legacyPolicyFragmentServiceTemplate =
new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
+ JpaToscaServiceTemplate serviceTemplate =
+ ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, legacyPolicyFragmentServiceTemplate);
+
assertNotNull(serviceTemplate);
LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
index 2ed03fa8d..a7ca3cc8b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
@@ -35,6 +35,7 @@ import java.util.Map;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -187,4 +188,53 @@ public class JpaToscaPolicyTypeTest {
assertNotNull(new JpaToscaEntityType<ToscaPolicyType>(new ToscaPolicyType()));
}
+
+ @Test
+ public void testGetReferencedDataTypes() {
+ JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0", "0.0.1"));
+
+ assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+ pt0.setProperties(new LinkedHashMap<>());
+ assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+ JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
+ prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION));
+ assertTrue(prop0.validate(new PfValidationResult()).isValid());
+
+ pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
+ assertTrue(pt0.getReferencedDataTypes().isEmpty());
+
+ JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop1"));
+ prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+ assertTrue(prop1.validate(new PfValidationResult()).isValid());
+
+ pt0.getProperties().put(prop1.getKey().getLocalName(), prop1);
+ assertEquals(1, pt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop2"));
+ prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+ assertTrue(prop2.validate(new PfValidationResult()).isValid());
+
+ pt0.getProperties().put(prop2.getKey().getLocalName(), prop2);
+ assertEquals(1, pt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4"));
+ prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
+ prop3.setEntrySchema(new JpaToscaEntrySchema());
+ prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1"));
+ assertTrue(prop3.validate(new PfValidationResult()).isValid());
+
+ pt0.getProperties().put(prop3.getKey().getLocalName(), prop3);
+ assertEquals(3, pt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4"));
+ prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1"));
+ prop4.setEntrySchema(new JpaToscaEntrySchema());
+ prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1"));
+ assertTrue(prop4.validate(new PfValidationResult()).isValid());
+
+ pt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
+ assertEquals(3, pt0.getReferencedDataTypes().size());
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
index f5722dded..f6f1b2c42 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,16 +31,18 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.Map;
-import org.junit.Before;
+
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.YamlJsonTranslator;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
@@ -90,30 +92,40 @@ public class MonitoringPolicySerializationTest {
private static final String VFW_MON_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json";
private static final String VFW_MON_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml";
- private StandardCoder standardCoder;
-
- @Before
- public void setUp() {
- standardCoder = new StandardCoder();
- }
+ private StandardCoder standardCoder = new StandardCoder();
+ private YamlJsonTranslator yamlJsonTranslator = new YamlJsonTranslator();
@Test
public void testDeserialization() throws Exception {
+ String policyTypeInputJson =
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
+ ToscaServiceTemplate plainPolicyTypes =
+ yamlJsonTranslator.fromYaml(policyTypeInputJson, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate policyTypeServiceTemplate = new JpaToscaServiceTemplate();
+ policyTypeServiceTemplate.fromAuthorative(plainPolicyTypes);
+
// vCPE
JpaToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON);
- verifyVcpeMonitoringInputDeserialization(serviceTemplateFromJson);
+ JpaToscaServiceTemplate mergedServiceTemplate =
+ ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson);
+ verifyVcpeMonitoringInputDeserialization(mergedServiceTemplate);
JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MON_INPUT_YAML);
assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
// vDNS
serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON);
- verifyVdnsMonitoringInputDeserialization(serviceTemplateFromJson);
+ mergedServiceTemplate =
+ ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson);
+ verifyVdnsMonitoringInputDeserialization(mergedServiceTemplate);
serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MON_INPUT_YAML);
assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
// vFirewall
serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON);
- verifyVfwMonitoringInputDeserialization(serviceTemplateFromJson);
+ mergedServiceTemplate =
+ ToscaServiceTemplateUtils.addFragment(policyTypeServiceTemplate, serviceTemplateFromJson);
+ verifyVfwMonitoringInputDeserialization(mergedServiceTemplate);
serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MON_INPUT_YAML);
assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
}
@@ -142,8 +154,7 @@ public class MonitoringPolicySerializationTest {
}
}
- private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath)
- throws Exception {
+ private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) throws Exception {
String policyJson = ResourceUtils.getResourceAsString(resourcePath);
ToscaServiceTemplate serviceTemplate = standardCoder.decode(policyJson, ToscaServiceTemplate.class);
@@ -152,8 +163,7 @@ public class MonitoringPolicySerializationTest {
return jpaToscaServiceTemplate;
}
- private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath)
- throws Exception {
+ private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
Yaml yaml = new Yaml();
String policyYaml = ResourceUtils.getResourceAsString(resourcePath);
@@ -178,11 +188,10 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals(YAML_VERSION,
- serviceTemplate.getToscaDefinitionsVersion());
+ assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
- Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
- .getPolicies().getConceptMap();
+ Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap =
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap();
// Check policies
assertTrue(policiesConceptMap.size() == 1);
@@ -211,11 +220,10 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals(YAML_VERSION,
- serviceTemplate.getToscaDefinitionsVersion());
+ assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
- Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
- .getPolicies().getConceptMap();
+ Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap =
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap();
// Check policies
assertTrue(policiesConceptMap.size() == 1);
@@ -244,11 +252,10 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals(YAML_VERSION,
- serviceTemplate.getToscaDefinitionsVersion());
+ assertEquals(YAML_VERSION, serviceTemplate.getToscaDefinitionsVersion());
- Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
- .getPolicies().getConceptMap();
+ Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap =
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap();
// Check policies
assertTrue(policiesConceptMap.size() == 1);
@@ -272,10 +279,8 @@ public class MonitoringPolicySerializationTest {
private void verifyVcpeMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
- .getAsString());
- JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE)
- .getAsJsonObject();
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString());
+ JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject();
JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
@@ -283,8 +288,7 @@ public class MonitoringPolicySerializationTest {
JsonObject policyVal = policy.get(POLICY1).getAsJsonObject();
assertEquals(TYPE1, policyVal.get("type").getAsString());
assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
- assertEquals(POLICY1, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
- .getAsString());
+ assertEquals(POLICY1, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString());
JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
assertNotNull(properties.get(TCA_POLICY));
}
@@ -292,8 +296,7 @@ public class MonitoringPolicySerializationTest {
private void verifyVdnsMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
- .getAsString());
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString());
JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject();
JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
@@ -302,8 +305,7 @@ public class MonitoringPolicySerializationTest {
JsonObject policyVal = policy.get(POLICY2).getAsJsonObject();
assertEquals(TYPE1, policyVal.get("type").getAsString());
assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
- assertEquals(POLICY2, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
- .getAsString());
+ assertEquals(POLICY2, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString());
JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
assertNotNull(properties.get(TCA_POLICY));
}
@@ -311,8 +313,7 @@ public class MonitoringPolicySerializationTest {
private void verifyVfwMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
- .getAsString());
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION).getAsString());
JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject();
JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
@@ -321,8 +322,7 @@ public class MonitoringPolicySerializationTest {
JsonObject policyVal = policy.get(POLICY3).getAsJsonObject();
assertEquals(TYPE1, policyVal.get("type").getAsString());
assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
- assertEquals(POLICY3, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
- .getAsString());
+ assertEquals(POLICY3, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID).getAsString());
JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
assertNotNull(properties.get(TCA_POLICY));
}
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 20ba756e9..01a52f7bd 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,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,11 +24,11 @@ package org.onap.policy.models.tosca.simple.serialization;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
@@ -98,37 +98,31 @@ public class MonitoringPolicyTypeSerializationTest {
}
@Test
- public void testSerialization() {
- try {
- // TCA
- JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
- String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
-
- ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
- coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
-
- JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
- serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
- String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
- assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
-
- // Collector
- JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
- deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
- String serializedServiceTemplateCollector =
- serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
- ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
- coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
- JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
- serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
- String serializedServiceTemplateCollectorsOut =
- serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
- assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
-
- } catch (Exception e) {
- LOGGER.warn("No exception should be thrown", e);
- fail("No exception should be thrown");
- }
+ public void testSerialization() throws Exception {
+ // TCA
+ JpaToscaServiceTemplate tcaServiceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
+ String serializedServiceTemplateTca = serializeMonitoringServiceTemplate(tcaServiceTemplateFromYaml);
+
+ ToscaServiceTemplate toscaServiceTemplateFromJsonTca =
+ coder.decode(serializedServiceTemplateTca, ToscaServiceTemplate.class);
+
+ JpaToscaServiceTemplate serviceTemplateFromJsonTca = new JpaToscaServiceTemplate();
+ serviceTemplateFromJsonTca.fromAuthorative(toscaServiceTemplateFromJsonTca);
+ String serializedServiceTemplateTcaOut = serializeMonitoringServiceTemplate(serviceTemplateFromJsonTca);
+ assertEquals(serializedServiceTemplateTca, serializedServiceTemplateTcaOut);
+
+ // Collector
+ JpaToscaServiceTemplate collectorServiceTemplateFromYaml =
+ deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
+ String serializedServiceTemplateCollector =
+ serializeMonitoringServiceTemplate(collectorServiceTemplateFromYaml);
+ ToscaServiceTemplate toscaServiceTemplateFromJsonCollector =
+ coder.decode(serializedServiceTemplateCollector, ToscaServiceTemplate.class);
+ JpaToscaServiceTemplate serviceTemplateFromJsonCollector = new JpaToscaServiceTemplate();
+ serviceTemplateFromJsonCollector.fromAuthorative(toscaServiceTemplateFromJsonCollector);
+ String serializedServiceTemplateCollectorsOut =
+ serializeMonitoringServiceTemplate(serviceTemplateFromJsonCollector);
+ assertEquals(serializedServiceTemplateCollector, serializedServiceTemplateCollectorsOut);
}
private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception {
@@ -196,8 +190,7 @@ public class MonitoringPolicyTypeSerializationTest {
Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeFirstProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName());
assertTrue(firstDataTypeFirstProperty.isRequired());
@@ -210,47 +203,41 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 2);
JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeSecondProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeSecondProperty.getKey().getParentKeyName());
assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
assertTrue(firstDataTypeSecondProperty.isRequired());
assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeThirdProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeThirdProperty.getKey().getParentKeyName());
assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
assertTrue(firstDataTypeThirdProperty.isRequired());
assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeFourthProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeFourthProperty.getKey().getParentKeyName());
assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
assertTrue(firstDataTypeFourthProperty.isRequired());
assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeFifthProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeFifthProperty.getKey().getParentKeyName());
assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
assertTrue(firstDataTypeFifthProperty.isRequired());
assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
- assertEquals(METRICS,
- firstDataTypeSixthProperty.getKey().getParentKeyName());
+ assertEquals(METRICS, firstDataTypeSixthProperty.getKey().getParentKeyName());
assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
assertEquals("list", firstDataTypeSixthProperty.getType().getName());
assertTrue(firstDataTypeSixthProperty.isRequired());
assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
- assertEquals(THRESHOLDS,
- firstDataTypeSixthProperty.getEntrySchema().getType().getName());
+ assertEquals(THRESHOLDS, firstDataTypeSixthProperty.getEntrySchema().getType().getName());
Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
assertEquals(TCA, secondDataType.getKey().getName());
@@ -281,8 +268,7 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
secondDataTypeSecondProperty.getDescription());
assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
- assertEquals(METRICS,
- secondDataTypeSecondProperty.getEntrySchema().getType().getName());
+ assertEquals(METRICS, secondDataTypeSecondProperty.getEntrySchema().getType().getName());
Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
@@ -352,7 +338,8 @@ public class MonitoringPolicyTypeSerializationTest {
assertEquals("JpaToscaConstraintValidValues(validValues=[CRITICAL, MAJOR, MINOR, WARNING, NORMAL])",
thirdDataTypeFifthProperty.getConstraints().iterator().next().toString());
assertTrue(((JpaToscaConstraintValidValues) (thirdDataTypeFifthProperty.getConstraints().iterator().next()))
- .getValidValues().size() == 5);;
+ .getValidValues().size() == 5);
+ ;
JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
@@ -393,8 +380,7 @@ public class MonitoringPolicyTypeSerializationTest {
firstPolicyType.getValue().getDescription());
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
- assertEquals(DCAE,
- secondPolicyType.getKey().getName());
+ assertEquals(DCAE, secondPolicyType.getKey().getName());
assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
@@ -402,16 +388,14 @@ public class MonitoringPolicyTypeSerializationTest {
Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
JpaToscaProperty firstProperty = propertiesIter.next();
- assertEquals(DCAE,
- firstProperty.getKey().getParentKeyName());
+ assertEquals(DCAE, firstProperty.getKey().getParentKeyName());
assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, firstProperty.getType().getName());
assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
JpaToscaProperty secondProperty = propertiesIter.next();
- assertEquals(DCAE,
- secondProperty.getKey().getParentKeyName());
+ assertEquals(DCAE, secondProperty.getKey().getParentKeyName());
assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
assertEquals(STRING_TEXT, secondProperty.getType().getName());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
index ecd066a14..a5568bab8 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
@@ -243,4 +243,9 @@ public class ToscaUtilsTest {
assertFalse(result.isValid());
assertTrue(result.toString().contains("parent dt1:0.0.1 of entity not found"));
}
+
+ @Test
+ public void testGetPredefinedDataTypes() {
+ assertTrue(ToscaUtils.getPredefinedDataTypes().contains(new PfConceptKey("string", PfKey.NULL_KEY_VERSION)));
+ }
}