summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-11 16:18:32 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-12 13:13:50 +0000
commit88bcb550c2efd5e43ad3d256fe075a6bf7e90538 (patch)
treee670f0f0c4cd77e3648aa7387525d6b2bdd94fec /models-tosca/src/test/java
parentfd79f7920d454c35d6a8c02d430d9beba434dcc2 (diff)
Implement validation and hierarchical get
NOTE: This review will require changes to the persistence.xml file in other policy framework components. This change brings in two changes: 1) Validation of the references betwen policies, policy types, and data types This change mans that additions to and changes to policies, policy types, and data types must be structurally correct in the change coming in and with whatever is already in the database 2) Hierarchical return of referenced entitites on policy types, policies and data types. When a policy, policy type, or data type is read from the database, the entities referenced byt the returned policy, policy type, or data type are returned as well. Tests are amended for the stricter validation and structure. Examples are corrected where they are incorrect. Issue-ID: POLICY-1402 Change-Id: Ie6a4cb7ed336562338924079114df405f0ab889f Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test/java')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java12
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java54
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java7
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java54
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java97
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java42
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java38
7 files changed, 225 insertions, 79 deletions
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 36c66546a..8b79374bc 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
@@ -156,8 +156,7 @@ public class AuthorativeToscaProviderPolicyTest {
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
- gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100);
- assertEquals(0, gotPolicyList.size());
+ assertTrue(new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100).isEmpty());
}
@Test
@@ -380,10 +379,11 @@ public class AuthorativeToscaProviderPolicyTest {
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
assertTrue(beforePolicy.getType().equals(deletedPolicy.getType()));
- ToscaServiceTemplate gotServiceTemplate =
- new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
-
- assertTrue(gotServiceTemplate.getToscaTopologyTemplate().getPolicies().isEmpty());
+ // @formatter:off
+ assertThatThrownBy(
+ () -> new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()))
+ .hasMessageMatching("policies for onap.restart.tca:1.0.0 do not exist");
+ // @formatter:on
}
@Test
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 c41f5e1f4..ae350bd90 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
@@ -58,8 +58,8 @@ import org.yaml.snakeyaml.Yaml;
*/
public class AuthorativeToscaProviderPolicyTypeTest {
private static final String VERSION = "version";
- private static final String POLICY_AFFINITY_VERSION0 = "onap.policies.NoVersion:0.0.0";
- private static final String POLICY_AFFINITY = "onap.policies.NoVersion";
+ private static final String POLICY_NO_VERSION_VERSION0 = "onap.policies.NoVersion:0.0.0";
+ private static final String POLICY_NO_VERSION = "onap.policies.NoVersion";
private static final String MISSING_POLICY_TYPES = "no policy types specified on service template";
private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private static final String VERSION_000 = "0.0.0";
@@ -135,7 +135,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
@@ -150,21 +150,26 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
List<ToscaPolicyType> gotPolicyTypeList =
- new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000);
- assertEquals(1, gotPolicyTypeList.size());
+ new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_000);
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, null);
- assertEquals(1, gotPolicyTypeList.size());
+ gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, null);
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, null);
- assertEquals(1, gotPolicyTypeList.size());
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_000);
- assertEquals(1, gotPolicyTypeList.size());
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+
+ assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION,
+ VERSION_000)).hasMessageContaining("Policy Framework DAO has not been initialized");
+
+ assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_000).isEmpty());
}
@Test
@@ -193,13 +198,21 @@ public class AuthorativeToscaProviderPolicyTypeTest {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null);
}).hasMessageMatching("^filter is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> new AuthorativeToscaProvider().getFilteredPolicyTypeList(new DefaultPfDao(),
+ ToscaPolicyTypeFilter.builder().name("i.dont.Exist").build()))
+ .hasMessageContaining("Policy Framework DAO has not been initialized");
+
+ assertTrue(new AuthorativeToscaProvider()
+ .getFilteredPolicyTypeList(pfDao, ToscaPolicyTypeFilter.builder().name("i.dont.Exist").build())
+ .isEmpty());
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
@@ -228,13 +241,13 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
List<ToscaPolicyType> gotPolicyTypeList =
- new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000);
- assertEquals(1, gotPolicyTypeList.size());
+ new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_000);
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
ToscaPolicyTypeFilter.builder().build());
- assertEquals(1, gotPolicyTypeList.size());
+ assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
@@ -249,7 +262,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
ToscaPolicyTypeFilter.builder().version("1.0.0").build());
- assertEquals(0, gotPolicyTypeList.size());
+ assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
}
@@ -283,7 +296,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
@@ -315,7 +328,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
@@ -366,7 +379,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
@@ -380,10 +393,9 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(true, beforePolicyType.getName().equals(deletedPolicy.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), deletedPolicy.getDescription()));
- ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao,
- policyTypeKey.getName(), policyTypeKey.getVersion());
-
- assertTrue(gotServiceTemplate.getPolicyTypes().isEmpty());
+ assertThatThrownBy(() -> {
+ new AuthorativeToscaProvider().getPolicyTypes(pfDao, policyTypeKey.getName(), policyTypeKey.getVersion());
+ }).hasMessage("policy types for onap.policies.NoVersion:0.0.0 do not exist");
}
@Test
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java
index 6d32c6d0b..62c088c83 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.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.
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
import java.util.LinkedHashMap;
import java.util.Map;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -49,10 +50,6 @@ public class LegacyGuardPolicyMapperTest {
JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "2.0.0"));
serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy);
- assertThatThrownBy(() -> {
- new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
- }).hasMessageContaining("no metadata defined on TOSCA policy");
-
policy.setMetadata(new LinkedHashMap<>());
assertThatThrownBy(() -> {
new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
index 499cf72fb..d205794de 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019=-2020 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");
@@ -34,13 +34,14 @@ 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.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
/**
- * DAO test for ToscaDatatype.
+ * DAO test for JpaToscaDatatype.
*
* @author Liam Fallon (liam.fallon@est.tech)
*/
@@ -140,4 +141,53 @@ public class JpaToscaDataTypeTest {
ToscaDataType datOut = tdta.toAuthorative();
assertNotNull(datOut);
}
+
+ @Test
+ public void testGetReferencedDataTypes() {
+ JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0", "0.0.1"));
+
+ assertTrue(dt0.getReferencedDataTypes().isEmpty());
+
+ dt0.setProperties(new LinkedHashMap<>());
+ assertTrue(dt0.getReferencedDataTypes().isEmpty());
+
+ JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop0"));
+ prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION));
+ assertTrue(prop0.validate(new PfValidationResult()).isValid());
+
+ dt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
+ assertTrue(dt0.getReferencedDataTypes().isEmpty());
+
+ JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop1"));
+ prop1.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+ assertTrue(prop1.validate(new PfValidationResult()).isValid());
+
+ dt0.getProperties().put(prop1.getKey().getLocalName(), prop1);
+ assertEquals(1, dt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop2 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop2"));
+ prop2.setType(new PfConceptKey("the.property.Type0", "0.0.1"));
+ assertTrue(prop2.validate(new PfValidationResult()).isValid());
+
+ dt0.getProperties().put(prop2.getKey().getLocalName(), prop2);
+ assertEquals(1, dt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(dt0.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());
+
+ dt0.getProperties().put(prop3.getKey().getLocalName(), prop3);
+ assertEquals(3, dt0.getReferencedDataTypes().size());
+
+ JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(dt0.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());
+
+ dt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
+ assertEquals(3, dt0.getReferencedDataTypes().size());
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
index 95c51e912..5cbec008b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -135,5 +136,101 @@ public class JpaToscaServiceTemplateTest {
assertTrue(tst.validate(new PfValidationResult()).isValid());
assertThatThrownBy(() -> tst.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ tst.setToscaDefinitionsVersion(null);
+ PfValidationResult result = tst.validate(new PfValidationResult());
+ assertThat(result.toString()).contains("service template tosca definitions version may not be null");
+
+ tst.setToscaDefinitionsVersion(JpaToscaServiceTemplate.DEFAULT_TOSCA_DEFINTIONS_VERISON);
+ tst.setDataTypes(null);
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ JpaToscaPolicyType pt0 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.1"));
+ tst.getPolicyTypes().getConceptMap().put(pt0.getKey(), pt0);
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1"));
+ JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
+ prop0.setType(dt0.getKey());
+ pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+
+ tst.setDataTypes(null);
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+
+ tst.setDataTypes(new JpaToscaDataTypes());
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("referenced data type dt0:0.0.1 not found");
+
+ tst.getDataTypes().getConceptMap().put(dt0.getKey(), dt0);
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.setTopologyTemplate(null);
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.setTopologyTemplate(new JpaToscaTopologyTemplate());
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.setPolicyTypes(null);
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ JpaToscaPolicy pol0 = new JpaToscaPolicy(new PfConceptKey("pol0:0.0.1"));
+ tst.getTopologyTemplate().getPolicies().getConceptMap().put(pol0.getKey(), pol0);
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("type is null or a null key");
+
+ pol0.setType(new PfConceptKey("i.dont.Exist:0.0.1"));
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains(
+ "no policy types are defined on the service template for the policies in the topology template");
+
+ tst.setPolicyTypes(policyTypes);
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("policy type i.dont.Exist:0.0.1 referenced in policy not found");
+
+ pol0.setType(dt0.getKey());
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains("policy type dt0:0.0.1 referenced in policy not found");
+
+ pol0.setType(pt0.getKey());
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.setPolicyTypes(null);
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains(
+ "no policy types are defined on the service template for the policies in the topology template");
+
+ tst.setPolicyTypes(policyTypes);
+ pol0.setType(pt0.getKey());
+ result = tst.validate(new PfValidationResult());
+ assertTrue(result.isOk());
+
+ tst.setPolicyTypes(new JpaToscaPolicyTypes());
+ result = tst.validate(new PfValidationResult());
+ assertFalse(result.isOk());
+ assertThat(result.toString()).contains(
+ "no policy types are defined on the service template for the policies in the topology template");
+
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index 03c7f9b1b..f34c0c869 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -24,7 +24,6 @@ package org.onap.policy.models.tosca.simple.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 java.util.Properties;
@@ -59,6 +58,7 @@ import org.yaml.snakeyaml.Yaml;
*/
public class SimpleToscaProviderTest {
private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
+ private static final String INCOMING_TEMPLATE_IS_NULL = "^incomingServiceTemplate is marked .*on.*ull but is null$";
private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
@@ -140,10 +140,8 @@ public class SimpleToscaProviderTest {
assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
- JpaToscaServiceTemplate doesNotExistServiceTemplate =
- new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
-
- assertEquals(null, doesNotExistServiceTemplate.getDataTypes().get(dataType0Key));
+ assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key))
+ .hasMessage("data types for DataType0:0.0.1 do not exist");
}
@Test
@@ -191,10 +189,8 @@ public class SimpleToscaProviderTest {
assertEquals("Updated Description",
deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
- JpaToscaServiceTemplate doesNotExistServiceTemplate =
- new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
-
- assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
+ .hasMessage("policy types for PolicyType0:0.0.1 do not exist");
}
@Test
@@ -235,10 +231,8 @@ public class SimpleToscaProviderTest {
assertEquals("Updated Description",
deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription());
- JpaToscaServiceTemplate doesNotExistServiceTemplate =
- new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key);
-
- assertEquals(null, doesNotExistServiceTemplate.getPolicyTypes().get(policyType0Key));
+ assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key))
+ .hasMessage("policy types for PolicyType0:0.0.1 do not exist");
}
@Test
@@ -255,7 +249,8 @@ public class SimpleToscaProviderTest {
JpaToscaServiceTemplate createdServiceTemplate =
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
- assertEquals(originalServiceTemplate, createdServiceTemplate);
+ assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
+ createdServiceTemplate.getTopologyTemplate().getPolicies());
PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
@@ -264,7 +259,6 @@ public class SimpleToscaProviderTest {
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
-
}
@Test
@@ -281,7 +275,8 @@ public class SimpleToscaProviderTest {
JpaToscaServiceTemplate createdServiceTemplate =
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
- assertEquals(originalServiceTemplate, createdServiceTemplate);
+ assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(),
+ createdServiceTemplate.getTopologyTemplate().getPolicies());
}
@Test
@@ -315,7 +310,7 @@ public class SimpleToscaProviderTest {
JpaToscaServiceTemplate createdServiceTemplate =
new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
- assertEquals(originalServiceTemplate, createdServiceTemplate);
+ assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate());
PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
@@ -325,8 +320,11 @@ public class SimpleToscaProviderTest {
assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
- assertTrue(new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion())
- .getTopologyTemplate().getPolicies().getConceptMap().isEmpty());
+ // @formatter:off
+ assertThatThrownBy(
+ () -> new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()))
+ .hasMessage("policies for onap.restart.tca:1.0.0 do not exist");
+ // @formatter:on
}
@Test
@@ -361,7 +359,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createDataTypes(pfDao, null);
- }).hasMessageMatching(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updateDataTypes(null, null);
@@ -401,7 +399,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(pfDao, null);
- }).hasMessageMatching(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(null, null);
@@ -441,7 +439,7 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, null);
- }).hasMessageMatching(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(INCOMING_TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(null, null);
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 bad89e909..a5d145e39 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
@@ -253,31 +253,23 @@ public class ToscaUtilsTest {
@Test
public void testgetEntityTree() {
assertThatThrownBy(() -> {
- ToscaUtils.getEntityTree(null, null);
+ ToscaUtils.getEntityTree(null, null, null);
}).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
- assertThatThrownBy(() -> {
- ToscaUtils.getEntityTree(null, new PfConceptKey());
- }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
-
- assertThatThrownBy(() -> {
- ToscaUtils.getEntityTree(new JpaToscaDataTypes(), null);
- }).hasMessageMatching("searchKey is marked .*on.*ull but is null");
-
JpaToscaDataTypes dataTypes = new JpaToscaDataTypes(new PfConceptKey("datatypes", "0.0.1"));
JpaToscaDataTypes filteredDataTypes = new JpaToscaDataTypes(new PfConceptKey("datatypes", "0.0.1"));
- ToscaUtils.getEntityTree(filteredDataTypes, new PfConceptKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, "IDontExist", "0.0.0");
assertEquals(dataTypes, filteredDataTypes);
JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0", "0.0.1"));
dataTypes.getConceptMap().put(dt0.getKey(), dt0);
filteredDataTypes.getConceptMap().put(dt0.getKey(), dt0);
- ToscaUtils.getEntityTree(filteredDataTypes, new PfConceptKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, "IDontExist", "0.0.0");
assertNotEquals(dataTypes, filteredDataTypes);
assertTrue(filteredDataTypes.getConceptMap().isEmpty());
filteredDataTypes.getConceptMap().put(dt0.getKey(), dt0);
- ToscaUtils.getEntityTree(filteredDataTypes, dt0.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt0.getKey().getName(), dt0.getKey().getVersion());
assertEquals(dataTypes, filteredDataTypes);
JpaToscaDataType dt1 = new JpaToscaDataType(new PfConceptKey("dt1", "0.0.1"));
@@ -317,31 +309,31 @@ public class ToscaUtilsTest {
dataTypes.getConceptMap().put(dt8.getKey(), dt8);
dataTypes.getConceptMap().put(dt9.getKey(), dt9);
- ToscaUtils.getEntityTree(filteredDataTypes, dt0.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt0.getKey().getName(), dt0.getKey().getVersion());
assertEquals(1, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt1.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt1.getKey().getName(), dt1.getKey().getVersion());
assertEquals(2, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt2.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt2.getKey().getName(), dt2.getKey().getVersion());
assertEquals(2, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt3.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt3.getKey().getName(), dt3.getKey().getVersion());
assertEquals(2, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt4.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt4.getKey().getName(), dt4.getKey().getVersion());
assertEquals(3, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt5.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt5.getKey().getName(), dt5.getKey().getVersion());
assertEquals(4, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt6.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt6.getKey().getName(), dt6.getKey().getVersion());
assertEquals(5, filteredDataTypes.getConceptMap().size());
assertTrue(filteredDataTypes.getConceptMap().containsValue(dt0));
assertFalse(filteredDataTypes.getConceptMap().containsValue(dt1));
@@ -352,15 +344,15 @@ public class ToscaUtilsTest {
assertTrue(filteredDataTypes.getConceptMap().containsValue(dt6));
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt7.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt7.getKey().getName(), dt7.getKey().getVersion());
assertEquals(1, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt8.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt8.getKey().getName(), dt8.getKey().getVersion());
assertEquals(2, filteredDataTypes.getConceptMap().size());
filteredDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(filteredDataTypes, dt9.getKey());
+ ToscaUtils.getEntityTree(filteredDataTypes, dt9.getKey().getName(), dt9.getKey().getVersion());
assertEquals(3, filteredDataTypes.getConceptMap().size());
dt9.setDerivedFrom(new PfConceptKey("i.dont.Exist", "0.0.0"));
@@ -368,7 +360,7 @@ public class ToscaUtilsTest {
assertThatThrownBy(() -> {
final JpaToscaDataTypes badDataTypes = new JpaToscaDataTypes(dataTypes);
- ToscaUtils.getEntityTree(badDataTypes, dt9.getKey());
+ ToscaUtils.getEntityTree(badDataTypes, dt9.getKey().getName(), dt9.getKey().getVersion());
}).hasMessageContaining("parent i.dont.Exist:0.0.0 of entity not found");
}
}