aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java96
1 files changed, 57 insertions, 39 deletions
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 9a91a9558..6296788ee 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2023 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -96,39 +96,7 @@ public class JpaToscaServiceTemplateTest {
tst.setTopologyTemplate(ttt);
assertEquals(ttt, tst.getTopologyTemplate());
- JpaToscaServiceTemplate tttClone0 = new JpaToscaServiceTemplate(tst);
- assertEquals(tst, tttClone0);
- assertEquals(0, tst.compareTo(tttClone0));
-
- JpaToscaServiceTemplate tttClone1 = new JpaToscaServiceTemplate(tst);
- assertEquals(tst, tttClone1);
- assertEquals(0, tst.compareTo(tttClone1));
-
- assertEquals(-1, tst.compareTo(null));
- assertEquals(0, tst.compareTo(tst));
- assertNotEquals(0, tst.compareTo(tst.getKey()));
-
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
- JpaToscaServiceTemplate otherDt = new JpaToscaServiceTemplate(otherDtKey);
-
- assertNotEquals(0, tst.compareTo(otherDt));
- otherDt.setKey(tstKey);
- assertNotEquals(0, tst.compareTo(otherDt));
- otherDt.setToscaDefinitionsVersion("Tosca Version");
- assertNotEquals(0, tst.compareTo(otherDt));
- otherDt.setDataTypes(dataTypes);
- assertNotEquals(0, tst.compareTo(otherDt));
- otherDt.setPolicyTypes(policyTypes);
- assertNotEquals(0, tst.compareTo(otherDt));
- otherDt.setTopologyTemplate(ttt);
- assertEquals(0, tst.compareTo(otherDt));
-
- assertEquals(6, tst.getKeys().size());
- assertEquals(1, new JpaToscaServiceTemplate().getKeys().size());
-
- new JpaToscaServiceTemplate().clean();
- tst.clean();
- assertEquals(tttClone0, tst);
+ assertCloneAndCopies(tstKey, tst, dataTypes, policyTypes, ttt);
assertTrue(new JpaToscaServiceTemplate().validate("").isValid());
assertTrue(tst.validate("").isValid());
@@ -146,7 +114,7 @@ public class JpaToscaServiceTemplateTest {
BeanValidationResult result = tst.validate("");
assertThat(result.getResult()).contains("tosca_definitions_version").contains(Validated.IS_NULL);
- tst.setToscaDefinitionsVersion(JpaToscaServiceTemplate.DEFAULT_TOSCA_DEFINTIONS_VERISON);
+ tst.setToscaDefinitionsVersion(JpaToscaServiceTemplate.DEFAULT_TOSCA_DEFINITIONS_VERSION);
tst.setDataTypes(null);
result = tst.validate("");
assertTrue(result.isValid());
@@ -160,6 +128,19 @@ public class JpaToscaServiceTemplateTest {
JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0"));
prop0.setType(dt0.getKey());
+ assertDataTypesAndToscaTopology(tst, pt0, dt0, prop0);
+
+ tst.setPolicyTypes(null);
+ result = tst.validate("");
+ assertTrue(result.isValid());
+
+ assertNoPolicyType(tst, policyTypes, pt0, dt0);
+
+ }
+
+ private static void assertDataTypesAndToscaTopology(JpaToscaServiceTemplate tst, JpaToscaPolicyType pt0,
+ JpaToscaDataType dt0, JpaToscaProperty prop0) {
+ BeanValidationResult result;
pt0.setProperties(new LinkedHashMap<>());
pt0.getProperties().put(prop0.getKey().getLocalName(), prop0);
result = tst.validate("");
@@ -191,11 +172,49 @@ public class JpaToscaServiceTemplateTest {
tst.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
result = tst.validate("");
assertTrue(result.isValid());
+ }
- tst.setPolicyTypes(null);
- result = tst.validate("");
- assertTrue(result.isValid());
+ private static void assertCloneAndCopies(PfConceptKey tstKey, JpaToscaServiceTemplate tst,
+ JpaToscaDataTypes dataTypes, JpaToscaPolicyTypes policyTypes,
+ JpaToscaTopologyTemplate ttt) {
+ JpaToscaServiceTemplate tttClone0 = new JpaToscaServiceTemplate(tst);
+ assertEquals(tst, tttClone0);
+ assertEquals(0, tst.compareTo(tttClone0));
+
+ JpaToscaServiceTemplate tttClone1 = new JpaToscaServiceTemplate(tst);
+ assertEquals(tst, tttClone1);
+ assertEquals(0, tst.compareTo(tttClone1));
+
+ assertEquals(-1, tst.compareTo(null));
+ assertEquals(0, tst.compareTo(tst));
+ assertNotEquals(0, tst.compareTo(tst.getKey()));
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
+ JpaToscaServiceTemplate otherDt = new JpaToscaServiceTemplate(otherDtKey);
+
+ assertNotEquals(0, tst.compareTo(otherDt));
+ otherDt.setKey(tstKey);
+ assertNotEquals(0, tst.compareTo(otherDt));
+ otherDt.setToscaDefinitionsVersion("Tosca Version");
+ assertNotEquals(0, tst.compareTo(otherDt));
+ otherDt.setDataTypes(dataTypes);
+ assertNotEquals(0, tst.compareTo(otherDt));
+ otherDt.setPolicyTypes(policyTypes);
+ assertNotEquals(0, tst.compareTo(otherDt));
+ otherDt.setTopologyTemplate(ttt);
+ assertEquals(0, tst.compareTo(otherDt));
+
+ assertEquals(6, tst.getKeys().size());
+ assertEquals(1, new JpaToscaServiceTemplate().getKeys().size());
+
+ new JpaToscaServiceTemplate().clean();
+ tst.clean();
+ assertEquals(tttClone0, tst);
+ }
+ private static void assertNoPolicyType(JpaToscaServiceTemplate tst, JpaToscaPolicyTypes policyTypes,
+ JpaToscaPolicyType pt0, JpaToscaDataType dt0) {
+ BeanValidationResult result;
JpaToscaPolicy pol0 = new JpaToscaPolicy(new PfConceptKey("pol0:0.0.1"));
tst.getTopologyTemplate().getPolicies().getConceptMap().put(pol0.getKey(), pol0);
result = tst.validate("");
@@ -239,6 +258,5 @@ public class JpaToscaServiceTemplateTest {
assertFalse(result.isValid());
assertThat(result.getResult()).contains(
"no policy types are defined on the service template for the policies in the topology template");
-
}
}