summaryrefslogtreecommitdiffstats
path: root/models-tosca
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java32
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java20
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java64
3 files changed, 73 insertions, 43 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 2c62e7fc0..34feece66 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
@@ -144,26 +144,26 @@ public class ToscaPolicyFilterTest {
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().version(ToscaPolicyFilter.LATEST_VERSION).build();
List<ToscaPolicy> filteredList = filter.filter(policyList);
- assertEquals(15, filteredList.size());
+ assertEquals(22, filteredList.size());
assertEquals(VERSION_100, filteredList.get(7).getVersion());
assertEquals(VERSION_100, filteredList.get(12).getVersion());
- assertEquals(17, policyList.size());
- assertEquals(15, filteredList.size());
+ assertEquals(24, policyList.size());
+ assertEquals(22, filteredList.size());
policyList.get(10).setVersion("2.0.0");
policyList.get(16).setVersion("3.4.5");
filteredList = filter.filter(policyList);
- assertEquals(15, filteredList.size());
- assertEquals("2.0.0", filteredList.get(7).getVersion());
- assertEquals("3.4.5", filteredList.get(12).getVersion());
+ assertEquals(22, filteredList.size());
+ assertEquals("2.0.0", filteredList.get(12).getVersion());
+ assertEquals("3.4.5", filteredList.get(14).getVersion());
policyList.get(10).setVersion(VERSION_100);
policyList.get(16).setVersion(VERSION_100);
filteredList = filter.filter(policyList);
- assertEquals(15, filteredList.size());
- assertEquals(VERSION_100, filteredList.get(7).getVersion());
+ assertEquals(22, filteredList.size());
assertEquals(VERSION_100, filteredList.get(12).getVersion());
+ assertEquals(VERSION_100, filteredList.get(14).getVersion());
}
@Test
@@ -182,7 +182,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().version(VERSION_100).build();
filteredList = filter.filter(policyList);
- assertEquals(15, filteredList.size());
+ assertEquals(21, filteredList.size());
filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build();
filteredList = filter.filter(policyList);
@@ -190,7 +190,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build();
filteredList = filter.filter(policyList);
- assertEquals(2, filteredList.size());
+ assertEquals(1, filteredList.size());
}
@Test
@@ -198,11 +198,11 @@ public class ToscaPolicyFilterTest {
// null pattern
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().versionPrefix(null).build();
List<ToscaPolicy> filteredList = filter.filter(policyList);
- assertEquals(17, filteredList.size());
+ assertEquals(24, filteredList.size());
filter = ToscaPolicyFilter.builder().versionPrefix("1.").build();
filteredList = filter.filter(policyList);
- assertEquals(14, filteredList.size());
+ assertEquals(21, filteredList.size());
filter = ToscaPolicyFilter.builder().versionPrefix("100.").build();
filteredList = filter.filter(policyList);
@@ -229,12 +229,12 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build();
filteredList = filter.filter(policyList);
- assertEquals(14, filteredList.size());
+ assertEquals(7, filteredList.size());
- filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.HpaPolicy").typeVersion(VERSION_000)
- .build();
+ filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.resource.HpaPolicy")
+ .typeVersion(VERSION_100).build();
filteredList = filter.filter(policyList);
- assertEquals(1, filteredList.size());
+ assertEquals(2, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000)
.build();
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
index d9ffec566..f4f822c20 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
@@ -27,12 +27,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
@@ -59,17 +57,17 @@ public class ToscaPolicyTypeFilterTest {
// @formatter:off
private static final String[] policyTypeResourceNames = {
"policytypes/onap.policies.controlloop.Operational.yaml",
- "policytypes/onap.policies.optimization.DistancePolicy.yaml",
- "policytypes/onap.policies.optimization.VnfPolicy.yaml",
- "policytypes/onap.policies.optimization.PciPolicy.yaml",
- "policytypes/onap.policies.optimization.OptimizationPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.PciPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.OptimizationPolicy.yaml",
"policytypes/onap.policies.controlloop.guard.Blacklist.yaml",
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml",
- "policytypes/onap.policies.optimization.HpaPolicy.yaml",
- "policytypes/onap.policies.optimization.Vim_fit.yaml",
- "policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
- "policytypes/onap.policies.optimization.AffinityPolicy.yaml",
- "policytypes/onap.policies.optimization.QueryPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.HpaPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.Vim_fit.yaml",
+ "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml",
+ "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml",
+ "policytypes/onap.policies.optimization.service.QueryPolicy.yaml",
"policytypes/onap.policies.controlloop.guard.MinMax.yaml",
"policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml",
"policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml",
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
index 9f9906930..e710faa31 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/OptimizationPolicyTypeSerializationTest.java
@@ -44,7 +44,10 @@ public class OptimizationPolicyTypeSerializationTest {
private static final String TYPE_ROOT = "tosca.policies.Root";
private static final String VERSION = "1.0.0";
- private static final String INPUT_YAML = "policytypes/onap.policies.Optimization.yaml";
+ private static final String INPUT_OPTIMIZATION_YAML = "policytypes/onap.policies.Optimization.yaml";
+ private static final String INPUT_OPTIMIZATION_RESOURCE_YAML =
+ "policytypes/onap.policies.optimization.Resource.yaml";
+ private static final String INPUT_OPTIMIZATION_SERVICE_YAML = "policytypes/onap.policies.optimization.Service.yaml";
private StandardCoder coder;
@@ -54,13 +57,39 @@ public class OptimizationPolicyTypeSerializationTest {
}
@Test
- public void test() throws CoderException {
- JpaToscaServiceTemplate svctmpl = loadYaml(INPUT_YAML);
- validate("initial object", svctmpl);
+ public void testOptimization() throws CoderException {
+ JpaToscaServiceTemplate svctmpl = loadYaml(INPUT_OPTIMIZATION_YAML);
+ validate("initial object", svctmpl, TYPE_ROOT, "onap.policies.Optimization", false, false);
String ser = serialize(svctmpl);
JpaToscaServiceTemplate svctmpl2 = deserialize(ser);
- validate("copy", svctmpl2);
+ validate("copy", svctmpl2, TYPE_ROOT, "onap.policies.Optimization", false, false);
+
+ assertEquals(svctmpl, svctmpl2);
+ }
+
+ @Test
+ public void testOptimizationResource() throws CoderException {
+ JpaToscaServiceTemplate svctmpl = loadYaml(INPUT_OPTIMIZATION_RESOURCE_YAML);
+ validate("initial object", svctmpl, "onap.policies.Optimization", "onap.policies.optimization.Resource", true,
+ true);
+
+ String ser = serialize(svctmpl);
+ JpaToscaServiceTemplate svctmpl2 = deserialize(ser);
+ validate("copy", svctmpl2, "onap.policies.Optimization", "onap.policies.optimization.Resource", true, true);
+
+ assertEquals(svctmpl, svctmpl2);
+ }
+
+ @Test
+ public void testOptimizationService() throws CoderException {
+ JpaToscaServiceTemplate svctmpl = loadYaml(INPUT_OPTIMIZATION_SERVICE_YAML);
+ validate("initial object", svctmpl, "onap.policies.Optimization", "onap.policies.optimization.Service", false,
+ true);
+
+ String ser = serialize(svctmpl);
+ JpaToscaServiceTemplate svctmpl2 = deserialize(ser);
+ validate("copy", svctmpl2, "onap.policies.Optimization", "onap.policies.optimization.Service", false, true);
assertEquals(svctmpl, svctmpl2);
}
@@ -86,29 +115,32 @@ public class OptimizationPolicyTypeSerializationTest {
return coder.encode(auth);
}
- private void validate(String testnm, JpaToscaServiceTemplate svctmpl) {
+ private void validate(String testnm, JpaToscaServiceTemplate svctmpl, String derivedFrom,
+ String typeName, boolean checkResource, boolean checkService) {
JpaToscaPolicyTypes policyTypes = svctmpl.getPolicyTypes();
assertEquals(testnm + " type count", 1, policyTypes.getConceptMap().size());
JpaToscaPolicyType policyType = policyTypes.getConceptMap().values().iterator().next();
- assertEquals(testnm + " name", "onap.policies.Optimization", policyType.getName());
+ assertEquals(testnm + " name", typeName, policyType.getName());
assertEquals(testnm + " version", VERSION, policyType.getVersion());
assertNotNull(testnm + " derived from", policyType.getDerivedFrom());
- assertEquals(testnm + " derived from name", TYPE_ROOT, policyType.getDerivedFrom().getName());
-
- assertEquals(testnm + " description", "The base policy type for all policies that govern optimization",
- policyType.getDescription());
+ assertEquals(testnm + " derived from name", derivedFrom, policyType.getDerivedFrom().getName());
Map<String, JpaToscaProperty> props = policyType.getProperties();
assertNotNull(testnm + " properties", props);
- validateScope(testnm, props.get("scope"));
- validateServices(testnm, props.get("services"));
- validateResources(testnm, props.get("resources"));
- validateGeography(testnm, props.get("geography"));
- validateIdentity(testnm, props.get("identity"));
+ if (checkResource && checkService) {
+ validateResources(testnm, props.get("resources"));
+ validateServices(testnm, props.get("services"));
+ } else if (checkService && !checkResource) {
+ validateServices(testnm, props.get("services"));
+ } else {
+ validateScope(testnm, props.get("scope"));
+ validateGeography(testnm, props.get("geography"));
+ validateIdentity(testnm, props.get("identity"));
+ }
}
// only need to validate deep match of one of these; geography is the most interesting