summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-06-14 07:38:26 +0000
committerliamfallon <liam.fallon@est.tech>2019-06-14 07:38:26 +0000
commit10c11e142feb1d040612fed695aaf76d007294da (patch)
tree58d4b61c8ceed0ee660b65b9331bbb3c4b67cbc2 /models-tosca/src/test
parent2d69f0ed6b0a59bacd4e7986c23281e4a9006c93 (diff)
Allow multiple versions of entities to be returned
Fix .gitreviw file to point at "master" rather than "dublin" Allow return of multiple versions of policy types and data types in TOSCA service templates and multiple policies in TOSCA topology templates. Because the return type is a list of singleton maps, utility methods were added to return flat maps of poliicy types, data types, and policies keyed by a compound ToscaEntityKey name/version key. Issue-ID: POLICY-1807 Change-Id: I355038aaca26f41064d0e3cb3b45b1de2294cf5f Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java46
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java15
-rw-r--r--models-tosca/src/test/resources/logback-test.xml2
4 files changed, 56 insertions, 9 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
index f5be66c4a..8ee74233b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
@@ -46,6 +46,8 @@ public class ToscaPolicyTest {
policy.setType("my_type");
policy.setTypeVersion("3.2.1");
+ assertEquals("ToscaEntityKey(name=my_name, version=1.2.3)", policy.getKey().toString());
+
ToscaPolicyIdentifier ident = policy.getIdentifier();
assertEquals("my_name", ident.getName());
assertEquals("1.2.3", ident.getVersion());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
index a7f3761a5..10f3b0db2 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import org.eclipse.persistence.config.PersistenceUnitProperties;
@@ -382,7 +383,7 @@ public class AuthorativeToscaProviderPolicyTest {
ToscaServiceTemplate gotServiceTemplate =
new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
- assertEquals(0, gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).size());
+ assertTrue(gotServiceTemplate.getToscaTopologyTemplate().getPolicies().isEmpty());
}
@Test
@@ -408,6 +409,49 @@ public class AuthorativeToscaProviderPolicyTest {
}).hasMessage("An incoming list of concepts must have at least one entry");
}
+ @Test
+ public void testEntityMaps() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+
+ assertEquals(3, toscaServiceTemplatePolicyType.getDataTypesAsMap().size());
+ assertEquals(2, toscaServiceTemplatePolicyType.getPolicyTypesAsMap().size());
+
+ ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
+ ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplate);
+ ToscaServiceTemplate createdServiceTemplate =
+ new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+
+ PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+
+ ToscaPolicy beforePolicy =
+ toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
+ ToscaPolicy createdPolicy =
+ createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
+ assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
+ assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+
+ assertEquals(1, toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+ assertEquals(1, createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
+
+ Map<String, ToscaPolicy> policyMapItem = createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0);
+ createdServiceTemplate.getToscaTopologyTemplate().getPolicies().add(policyMapItem);
+
+ assertThatThrownBy(() -> {
+ createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap();
+ }).hasMessageContaining("list of map of entities contains more than one entity with key");
+ }
+
private void createPolicyTypes() throws CoderException, PfModelException {
Object yamlObject = new Yaml().load(
ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
index 6a925bcf3..ded2cdee2 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.models.tosca.authorative.provider;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
@@ -133,7 +134,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
- ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
@@ -199,7 +200,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
- ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
@@ -283,7 +284,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
- ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
}
@@ -315,14 +316,14 @@ public class AuthorativeToscaProviderPolicyTypeTest {
PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
- ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
ToscaServiceTemplate updatedServiceTemplate =
new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate);
- ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(updatedPolicy.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), updatedPolicy.getDescription()));
}
@@ -366,7 +367,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
- ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+ ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
@@ -380,7 +381,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao,
policyTypeKey.getName(), policyTypeKey.getVersion());
- assertEquals(0, gotServiceTemplate.getPolicyTypes().get(0).size());
+ assertTrue(gotServiceTemplate.getPolicyTypes().isEmpty());
}
@Test
diff --git a/models-tosca/src/test/resources/logback-test.xml b/models-tosca/src/test/resources/logback-test.xml
index 6e2737da6..a7a583827 100644
--- a/models-tosca/src/test/resources/logback-test.xml
+++ b/models-tosca/src/test/resources/logback-test.xml
@@ -25,7 +25,7 @@
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<property name="LOG_DIR" value="${java.io.tmpdir}/pf_logging/" />
- <!-- USE FOR STD OUT ONLY -->
+ <!-- USE FOR STD OUTPUT ONLY -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>