diff options
Diffstat (limited to 'models-tosca/src/test/java')
9 files changed, 295 insertions, 86 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java new file mode 100644 index 000000000..ee2fee86b --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaCapabilityAssignmentTest.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +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.assertNotNull; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment; + +/** + * DAO test for JpaToscaCapabilityAssignment. + */ +public class JpaToscaCapabilityAssignmentTest { + + private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null"; + + @Test + public void testPropertyPojo() { + assertNotNull(new JpaToscaCapabilityAssignment()); + assertNotNull(new JpaToscaCapabilityAssignment(new PfConceptKey())); + assertNotNull(new JpaToscaCapabilityAssignment(new JpaToscaCapabilityAssignment())); + assertNotNull(new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment())); + + assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL); + assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((JpaToscaCapabilityAssignment) null)) + .hasMessageMatching("copyConcept is marked .*on.*ull but is null"); + assertThatThrownBy(() -> new JpaToscaCapabilityAssignment((ToscaCapabilityAssignment) null)) + .hasMessageMatching("authorativeConcept is marked .*on.*ull but is null"); + + PfConceptKey caKey = new PfConceptKey("tParentKey", "0.0.1"); + + JpaToscaCapabilityAssignment caNull = new JpaToscaCapabilityAssignment(caKey); + caNull.setProperties(null); + caNull.setAttributes(null); + caNull.setOccurrences(null); + + assertEquals(caNull, new JpaToscaCapabilityAssignment(caNull)); + + JpaToscaCapabilityAssignment ca = new JpaToscaCapabilityAssignment(caKey); + + assertEquals(ca, new JpaToscaCapabilityAssignment(ca)); + assertEquals(caKey, ca.getKeys().get(0)); + + ca.clean(); + ca.validate(new PfValidationResult()); + assertThat(ca.getProperties()).isNullOrEmpty(); + assertThat(ca.getAttributes()).isNullOrEmpty(); + + ca.setProperties(null); + ca.setAttributes(null); + ca.setOccurrences(null); + ca.clean(); + ca.validate(new PfValidationResult()); + assertEquals(null, ca.getProperties()); + assertEquals(null, ca.getAttributes()); + + Map<String, String> properties = new LinkedHashMap<>(); + properties.put("Key0", " Untrimmed Value "); + ca.setProperties(properties); + + Map<String, String> attributes = new LinkedHashMap<>(); + attributes.put("Key0", " Untrimmed Value "); + ca.setAttributes(attributes); + + List<Integer> occurrences = new ArrayList<>(); + occurrences.add(12345); + ca.setOccurrences(occurrences); + + ca.clean(); + ca.validate(new PfValidationResult()); + assertEquals("Untrimmed Value", ca.getProperties().get("Key0")); + assertEquals("Untrimmed Value", ca.getAttributes().get("Key0")); + + ca.getProperties().put("Key1", null); + ca.getAttributes().put("Key1", null); + ca.getOccurrences().add(null); + ca.getOccurrences().add(-12345); + PfValidationResult result = ca.validate(new PfValidationResult()); + assertThat(result.toString()).contains("capability assignment property Key1 value may not be null"); + assertThat(result.toString()).contains("capability assignment attribute Key1 value may not be null"); + assertThat(result.toString()).contains("capability assignment occurrence value may not be negative"); + } + + @Test + public void testCompareTo() { + assertEquals(-1, new JpaToscaCapabilityAssignment().compareTo(null)); + assertEquals(0, new JpaToscaCapabilityAssignment().compareTo(new JpaToscaCapabilityAssignment())); + + JpaToscaCapabilityAssignment ca = new JpaToscaCapabilityAssignment(); + assertEquals(0, ca.compareTo(ca)); + assertEquals(18, ca.compareTo(new PfConceptKey())); + + JpaToscaCapabilityAssignment ca2 = new JpaToscaCapabilityAssignment(); + ca2.getKey().setName("ca2"); + assertEquals(-21, ca.compareTo(ca2)); + + ca.getKey().setName("ca"); + ca2.getKey().setName("ca"); + + ca.setProperties(new LinkedHashMap<>()); + ca2.setProperties(new LinkedHashMap<>()); + ca.getProperties().put("Key0", "Value0"); + assertEquals(-1737938642, ca.compareTo(ca2)); + ca2.getProperties().put("Key0", "Value0"); + assertEquals(0, ca.compareTo(ca2)); + + ca.setAttributes(new LinkedHashMap<>()); + ca2.setAttributes(new LinkedHashMap<>()); + ca.getAttributes().put("Key0", "Value0"); + assertEquals(-1737938642, ca.compareTo(ca2)); + ca2.getAttributes().put("Key0", "Value0"); + assertEquals(0, ca.compareTo(ca2)); + + ca.setOccurrences(new ArrayList<>()); + ca2.setOccurrences(new ArrayList<>()); + ca.getOccurrences().add(12345); + assertEquals(12375, ca.compareTo(ca2)); + ca2.getOccurrences().add(12345); + assertEquals(0, ca.compareTo(ca2)); + } + + @Test + public void testAuthorative() { + ToscaCapabilityAssignment tca = + new JpaToscaCapabilityAssignment(new ToscaCapabilityAssignment()).toAuthorative(); + + JpaToscaCapabilityAssignment jtca = new JpaToscaCapabilityAssignment(tca); + ToscaCapabilityAssignment tca2 = jtca.toAuthorative(); + assertEquals(tca, tca2); + } +} 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 e00e48f21..7168f488c 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 @@ -174,7 +174,7 @@ public class JpaToscaDataTypeTest { JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop4")); prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1")); - prop3.setEntrySchema(new JpaToscaEntrySchema()); + prop3.setEntrySchema(new JpaToscaSchemaDefinition()); prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1")); assertTrue(prop3.validate(new PfValidationResult()).isValid()); @@ -183,7 +183,7 @@ public class JpaToscaDataTypeTest { JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop4")); prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1")); - prop4.setEntrySchema(new JpaToscaEntrySchema()); + prop4.setEntrySchema(new JpaToscaSchemaDefinition()); prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1")); assertTrue(prop4.validate(new PfValidationResult()).isValid()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java index 14a0b6a96..7f356224f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java @@ -30,11 +30,13 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; 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.PfUtils; import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -60,8 +62,8 @@ public class JpaToscaPolicyTest { assertThatThrownBy(() -> { new JpaToscaPolicy(pol); }).hasMessage( - "PolicyType version not specified, the version of the PolicyType for this policy must be specified in the " - + "type_version field"); + "PolicyType version not specified, the version of the PolicyType for this policy must be specified in" + + " the type_version field"); assertThatThrownBy(() -> { new JpaToscaPolicy((PfConceptKey) null); @@ -182,4 +184,44 @@ public class JpaToscaPolicyTest { tp.fromAuthorative(pol1); assertEquals("2.2.3", tp.getType().getVersion()); } + + @Test + public void testPolicyProperties() { + + Map<String, Object> properties = new LinkedHashMap<>(); + + // @formatter:off + properties.put("byte", Byte.valueOf("2")); + properties.put("short", Short.valueOf("1234")); + properties.put("int", Integer.valueOf("12345678")); + properties.put("long", Long.valueOf("1234567890")); + properties.put("float", Float.valueOf("12345.678")); + properties.put("double", Double.valueOf("-12345.6789")); + properties.put("char", '%'); + properties.put("string", "hello"); + properties.put("boolean", false); + // @formatter:on + + ToscaPolicy tp = new ToscaPolicy(); + tp.setType("org.onap.Policy"); + tp.setTypeVersion("1.2.3"); + tp.setProperties(properties); + + JpaToscaPolicy jtp = new JpaToscaPolicy(tp); + assertEquals(0, PfUtils.compareCollections(tp.getProperties().keySet(), jtp.getProperties().keySet())); + + ToscaPolicy tpFromTo = jtp.toAuthorative(); + + // @formatter:off + assertEquals(2, tpFromTo.getProperties().get("byte")); + assertEquals(1234, tpFromTo.getProperties().get("short")); + assertEquals(12345678, tpFromTo.getProperties().get("int")); + assertEquals(1234567890, tpFromTo.getProperties().get("long")); + assertEquals(12345.678, tpFromTo.getProperties().get("float")); + assertEquals(-12345.6789, tpFromTo.getProperties().get("double")); + assertEquals("%", tpFromTo.getProperties().get("char")); + assertEquals("hello", tpFromTo.getProperties().get("string")); + assertEquals(false, tpFromTo.getProperties().get("boolean")); + // @formatter:on + } } 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 5a18902d0..43cacda19 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 @@ -221,7 +221,7 @@ public class JpaToscaPolicyTypeTest { JpaToscaProperty prop3 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4")); prop3.setType(new PfConceptKey("the.property.Type1", "0.0.1")); - prop3.setEntrySchema(new JpaToscaEntrySchema()); + prop3.setEntrySchema(new JpaToscaSchemaDefinition()); prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1")); assertTrue(prop3.validate(new PfValidationResult()).isValid()); @@ -230,7 +230,7 @@ public class JpaToscaPolicyTypeTest { JpaToscaProperty prop4 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop4")); prop4.setType(new PfConceptKey("the.property.Type1", "0.0.1")); - prop4.setEntrySchema(new JpaToscaEntrySchema()); + prop4.setEntrySchema(new JpaToscaSchemaDefinition()); prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1")); assertTrue(prop4.validate(new PfValidationResult()).isValid()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java index ac2f6030f..0fa0d3f14 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java @@ -91,7 +91,7 @@ public class JpaToscaPropertyTest { assertEquals(constraints, tp.getConstraints()); PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); - JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); tp.setEntrySchema(tes); TreeMap<String, String> metadata = new TreeMap<>(); @@ -134,6 +134,8 @@ public class JpaToscaPropertyTest { otherDt.setConstraints(constraints); assertNotEquals(0, tp.compareTo(otherDt)); otherDt.setEntrySchema(tes); + assertNotEquals(0, tp.compareTo(otherDt)); + otherDt.setMetadata(metadata); assertEquals(0, tp.compareTo(otherDt)); otherDt.setRequired(true); @@ -220,7 +222,7 @@ public class JpaToscaPropertyTest { tp.setConstraints(constraints); PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); - JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); tp.setEntrySchema(tes); TreeMap<String, String> metadata = new TreeMap<>(); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java index 83d6aad97..e7163f756 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java @@ -39,23 +39,23 @@ import org.onap.policy.models.base.PfValidationResult; * * @author Liam Fallon (liam.fallon@est.tech) */ -public class JpaToscaEntrySchemaTest { +public class JpaToscaSchemaDefinitionTest { private static final String A_DESCRIPTION = "A Description"; @Test public void testEntrySchemaPojo() { - assertNotNull(new JpaToscaEntrySchema(new PfConceptKey())); - assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey()))); + assertNotNull(new JpaToscaSchemaDefinition(new PfConceptKey())); + assertNotNull(new JpaToscaSchemaDefinition(new JpaToscaSchemaDefinition(new PfConceptKey()))); - assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null)) + assertThatThrownBy(() -> new JpaToscaSchemaDefinition((PfConceptKey) null)) .hasMessageMatching("type is marked .*on.*ull but is null"); - assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null)) + assertThatThrownBy(() -> new JpaToscaSchemaDefinition((JpaToscaSchemaDefinition) null)) .hasMessageMatching("copyConcept is marked .*on.*ull but is null"); PfConceptKey typeKey = new PfConceptKey("type", "0.0.1"); - JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); tes.setDescription(A_DESCRIPTION); assertEquals(A_DESCRIPTION, tes.getDescription()); @@ -66,18 +66,18 @@ public class JpaToscaEntrySchemaTest { tes.setConstraints(constraints); assertEquals(constraints, tes.getConstraints()); - JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes); + JpaToscaSchemaDefinition tdtClone0 = new JpaToscaSchemaDefinition(tes); assertEquals(tes, tdtClone0); assertEquals(0, tes.compareTo(tdtClone0)); - JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(tes); + JpaToscaSchemaDefinition tdtClone1 = new JpaToscaSchemaDefinition(tes); assertEquals(tes, tdtClone1); assertEquals(0, tes.compareTo(tdtClone1)); assertEquals(-1, tes.compareTo(null)); assertEquals(0, tes.compareTo(tes)); - JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(typeKey); + JpaToscaSchemaDefinition otherEs = new JpaToscaSchemaDefinition(typeKey); assertNotEquals(0, tes.compareTo(otherEs)); otherEs.setType(typeKey); @@ -90,13 +90,13 @@ public class JpaToscaEntrySchemaTest { assertThatThrownBy(() -> tes.copyTo(null)).hasMessageMatching("target is marked .*on.*ull but is null"); assertEquals(1, tes.getKeys().size()); - assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size()); + assertEquals(1, new JpaToscaSchemaDefinition(typeKey).getKeys().size()); - new JpaToscaEntrySchema(typeKey).clean(); + new JpaToscaSchemaDefinition(typeKey).clean(); tes.clean(); assertEquals(tdtClone0, tes); - assertTrue(new JpaToscaEntrySchema(typeKey).validate(new PfValidationResult()).isValid()); + assertTrue(new JpaToscaSchemaDefinition(typeKey).validate(new PfValidationResult()).isValid()); assertTrue(tes.validate(new PfValidationResult()).isValid()); tes.setType(PfConceptKey.getNullKey()); 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 65d832b98..bb0d2dcb5 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 @@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import org.junit.Test; @@ -154,6 +155,8 @@ public class JpaToscaServiceTemplateTest { JpaToscaDataType dt0 = new JpaToscaDataType(new PfConceptKey("dt0:0.0.1")); JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0.getKey(), "prop0")); prop0.setType(dt0.getKey()); + + pt0.setProperties(new LinkedHashMap<>()); pt0.getProperties().put(prop0.getKey().getLocalName(), prop0); result = tst.validate(new PfValidationResult()); assertFalse(result.isOk()); 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 1e18f12d4..3c363b364 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 @@ -26,6 +26,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import java.util.LinkedHashMap; import java.util.Properties; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.junit.After; @@ -119,7 +120,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); @@ -128,19 +129,19 @@ public class SimpleToscaProviderTest { dataType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate); assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); + new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion()); assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key)); assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("data type IDontExist:0.0.1 not found"); + .hasMessage("data type IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key); @@ -161,7 +162,7 @@ public class SimpleToscaProviderTest { assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("no data types found"); + .hasMessage("no data types found"); // Create the data type again new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); @@ -169,12 +170,13 @@ public class SimpleToscaProviderTest { JpaToscaPolicyType pt0v2 = new JpaToscaPolicyType(new PfConceptKey("pt0:0.0.2")); JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(pt0v2.getKey(), "prop0")); prop0.setType(dataType0Key); + pt0v2.setProperties(new LinkedHashMap<>()); pt0v2.getProperties().put(prop0.getKey().getLocalName(), prop0); updatedServiceTemplate.getPolicyTypes().getConceptMap().put(pt0v2.getKey(), pt0v2); new SimpleToscaProvider().createPolicyTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType0v2 = new JpaToscaDataType(new PfConceptKey("DataType0:0.0.2")); updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType0v2.getKey(), dataType0v2); @@ -186,17 +188,18 @@ public class SimpleToscaProviderTest { assertNull(deletedServiceTemplate.getDataTypes().get(dataType0v2.getKey()).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key)) - .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); + .hasMessage("data type DataType0:0.0.1 is in use, it is referenced in policy type pt0:0.0.2"); JpaToscaDataType dataType1 = new JpaToscaDataType(new PfConceptKey("DataType1:0.0.3")); JpaToscaProperty prop1 = new JpaToscaProperty(new PfReferenceKey(dataType1.getKey(), "prop1")); prop1.setType(dataType0v2.getKey()); + dataType1.setProperties(new LinkedHashMap<>()); dataType1.getProperties().put(prop1.getKey().getLocalName(), prop1); updatedServiceTemplate.getDataTypes().getConceptMap().put(dataType1.getKey(), dataType1); new SimpleToscaProvider().createDataTypes(pfDao, updatedServiceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deleteDataType(pfDao, dataType0v2.getKey())) - .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); + .hasMessage("data type DataType0:0.0.2 is in use, it is referenced in data type DataType1:0.0.3"); } @Test @@ -216,7 +219,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getPolicyTypes().getConceptMap().size()); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); @@ -225,14 +228,14 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -247,7 +250,7 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); @@ -262,10 +265,10 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().createPolicies(pfDao, serviceTemplate); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); + .hasMessage("policy type PolicyType0:0.0.1 is in use, it is referenced in policy type pt1:0.0.2"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, pt1.getKey())) - .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); + .hasMessage("policy type pt1:0.0.2 is in use, it is referenced in policy p1:0.0.1"); new SimpleToscaProvider().deletePolicy(pfDao, p1.getKey()); @@ -274,17 +277,17 @@ public class SimpleToscaProviderTest { new SimpleToscaProvider().deletePolicy(pfDao, p0.getKey()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); JpaToscaServiceTemplate newServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(serviceTemplate, newServiceTemplate); } @@ -299,7 +302,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getPolicyTypes().getConceptMap().put(policyType0Key, policyType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createPolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, createdServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals(null, createdServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); @@ -307,33 +310,33 @@ public class SimpleToscaProviderTest { policyType0.setDescription("Updated Description"); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().updatePolicyTypes(pfDao, serviceTemplate); assertEquals(policyType0, updatedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + updatedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, policyType0Key.getName(), policyType0Key.getVersion()); assertEquals(policyType0, gotServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", gotServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); JpaToscaServiceTemplate deletedServiceTemplate = - new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); + new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key); assertEquals(policyType0, deletedServiceTemplate.getPolicyTypes().get(policyType0Key)); assertEquals("Updated Description", - deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); + deletedServiceTemplate.getPolicyTypes().get(policyType0Key).getDescription()); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicyType(pfDao, policyType0Key)) - .hasMessage("no policy types found"); + .hasMessage("no policy types found"); } @Test public void testPoliciesGet() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -342,18 +345,18 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); JpaToscaServiceTemplate gotServiceTemplate = - new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); + new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); - assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), - gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); + assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey) + .compareTo(gotServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); assertEquals(1, deletedServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size()); @@ -362,7 +365,7 @@ public class SimpleToscaProviderTest { @Test public void testPolicyCreate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -371,21 +374,21 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); } @Test public void testPolicyCreateTypeAndVersion() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); ToscaPolicy toscaPolicy = - toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next(); + toscaServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().values().iterator().next(); JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate(); @@ -397,13 +400,13 @@ public class SimpleToscaProviderTest { assertThatThrownBy(() -> { originalServiceTemplate.fromAuthorative(toscaServiceTemplate); }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be " - + "specified in the type field"); + + "specified in the type field"); toscaPolicy.setType("IDontExist"); assertThatThrownBy(() -> { originalServiceTemplate.fromAuthorative(toscaServiceTemplate); }).hasMessage("PolicyType version not specified, the version of the PolicyType for this policy must be " - + "specified in the type_version field"); + + "specified in the type_version field"); toscaPolicy.setTypeVersion("hello"); assertThatThrownBy(() -> { @@ -425,22 +428,22 @@ public class SimpleToscaProviderTest { assertThatThrownBy(() -> { originalServiceTemplate.fromAuthorative(toscaServiceTemplate); }).hasMessage("PolicyType type not specified, the type of the PolicyType for this policy must be " - + "specified in the type field"); + + "specified in the type field"); toscaPolicy.setType(originalPolicyType); toscaPolicy.setTypeVersion(originalPolicyTypeVersion); originalServiceTemplate.fromAuthorative(toscaServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies(), - createdServiceTemplate.getTopologyTemplate().getPolicies()); + createdServiceTemplate.getTopologyTemplate().getPolicies()); } @Test public void testPolicyUpdate() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -449,7 +452,7 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate updatedServiceTemplate = - new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, updatedServiceTemplate); } @@ -457,7 +460,7 @@ public class SimpleToscaProviderTest { @Test public void testPoliciesDelete() throws Exception { ToscaServiceTemplate toscaServiceTemplate = - standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); + standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class); createPolicyTypes(); @@ -466,26 +469,26 @@ public class SimpleToscaProviderTest { assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); + new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate.getTopologyTemplate(), createdServiceTemplate.getTopologyTemplate()); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, new PfConceptKey("IDontExist:0.0.1"))) - .hasMessage("policy IDontExist:0.0.1 not found"); + .hasMessage("policy IDontExist:0.0.1 not found"); JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, policyKey); - assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), - deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey)); + assertEquals(0, originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey) + .compareTo(deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey))); assertThatThrownBy(() -> { new SimpleToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion()); }).hasMessage("policies for onap.restart.tca:1.0.0 do not exist"); assertThatThrownBy(() -> new SimpleToscaProvider().deletePolicy(pfDao, policyKey)) - .hasMessage("no policies found"); + .hasMessage("no policies found"); new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); } @@ -495,21 +498,21 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate(); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("topology template not specified on service template"); + .hasMessage("topology template not specified on service template"); testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("no policies specified on topology template of service template"); + .hasMessage("no policies specified on topology template of service template"); testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate)) - .hasMessage("list of policies specified on topology template of service template is empty"); + .hasMessage("list of policies specified on topology template of service template is empty"); } @Test public void testGetServiceTemplate() throws PfModelException { assertThatThrownBy(() -> new SimpleToscaProvider().getServiceTemplate(pfDao)) - .hasMessage("service template not found in database"); + .hasMessage("service template not found in database"); } @Test @@ -520,8 +523,8 @@ public class SimpleToscaProviderTest { serviceTemplateFragment.getPolicyTypes().getConceptMap().put(badPt.getKey(), badPt); assertThatThrownBy(() -> new SimpleToscaProvider().appendToServiceTemplate(pfDao, serviceTemplateFragment)) - .hasMessageContaining( - "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key"); + .hasMessageContaining( + "key on concept entry PfConceptKey(name=NULL, version=0.0.0) may not be the null key"); } @Test @@ -609,7 +612,7 @@ public class SimpleToscaProviderTest { }).hasMessageMatching("policy types for hello:0.0.1 do not exist"); JpaToscaServiceTemplate gotSt = - new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); + new SimpleToscaProvider().getPolicyTypes(pfDao, pt01.getName(), pt01.getVersion()); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getKey())); assertEquals(pt01, gotSt.getPolicyTypes().get(pt01.getName())); @@ -674,10 +677,10 @@ public class SimpleToscaProviderTest { JpaToscaServiceTemplate gotSt = new SimpleToscaProvider().getPolicies(pfDao, p01.getName(), p01.getVersion()); - assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getKey())); - assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName())); - assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null)); - assertEquals(p01, gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion())); + assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getKey()))); + assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName()))); + assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), null))); + assertEquals(0, p01.compareTo(gotSt.getTopologyTemplate().getPolicies().get(p01.getName(), p01.getVersion()))); assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null).size()); assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(null, null).size()); assertEquals(1, gotSt.getTopologyTemplate().getPolicies().getAll(p01.getName(), null).size()); @@ -859,7 +862,7 @@ public class SimpleToscaProviderTest { serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0); JpaToscaServiceTemplate createdServiceTemplate = - new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); + new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate); assertEquals(1, createdServiceTemplate.getDataTypes().getConceptMap().size()); assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key)); @@ -878,12 +881,12 @@ public class SimpleToscaProviderTest { } private void createPolicyTypes() throws CoderException, PfModelException { - Object yamlObject = new Yaml() - .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml")); + Object yamlObject = + new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml")); String yamlAsJsonString = new StandardCoder().encode(yamlObject); ToscaServiceTemplate toscaServiceTemplatePolicyType = - standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); + standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class); assertNotNull(toscaServiceTemplatePolicyType); new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType); 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 f74fad4b4..ba486035c 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 @@ -25,6 +25,7 @@ import static org.junit.Assert.assertTrue; import java.util.List; import java.util.Map; +import org.apache.commons.collections4.MapUtils; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.utils.coder.CoderException; @@ -194,7 +195,7 @@ public class OptimizationPolicyTypeSerializationTest { String testnm = testName + " identity"; assertNotNull(testnm, prop); - assertEquals(testnm + " metadata", 0, prop.getMetadata().size()); + assertEquals(testnm + " metadata", true, MapUtils.isEmpty(prop.getMetadata())); } private void validateMatchable(String testName, Map<String, String> metadata) { |