X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaDataTypeTest.java;h=d205794de131498287eef52c06faecb10fbfc4a8;hb=88bcb550c2efd5e43ad3d256fe075a6bf7e90538;hp=66cde51fcc4ceb51e69af9eb7594a75982b93ea7;hpb=e936413c9082afed0fef4646b8f12d351c87800c;p=policy%2Fmodels.git 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 66cde51fc..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,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 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"); * you may not use this file except in compliance with the License. @@ -33,21 +34,21 @@ 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; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; /** - * DAO test for ToscaDatatype. + * DAO test for JpaToscaDatatype. * * @author Liam Fallon (liam.fallon@est.tech) */ public class JpaToscaDataTypeTest { + private static final String VERSION_001 = "0.0.1"; + @Test public void testDataTypePojo() { assertNotNull(new JpaToscaDataType()); @@ -57,13 +58,12 @@ public class JpaToscaDataTypeTest { assertThatThrownBy(() -> { new JpaToscaDataType((PfConceptKey) null); - }).hasMessage("key is marked @NonNull but is null"); + }).hasMessageMatching("key is marked .*on.*ull but is null"); - assertThatThrownBy(() -> { - new JpaToscaDataType((JpaToscaDataType) null); - }).hasMessage("copyConcept is marked @NonNull but is null"); + assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null)) + .isInstanceOf(NullPointerException.class); - PfConceptKey dtKey = new PfConceptKey("tdt", "0.0.1"); + PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001); JpaToscaDataType tdt = new JpaToscaDataType(dtKey); List constraints = new ArrayList<>(); @@ -73,7 +73,8 @@ public class JpaToscaDataTypeTest { assertEquals(constraints, tdt.getConstraints()); Map properties = new LinkedHashMap<>(); - JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1")); + JpaToscaProperty tp = + new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001)); properties.put(tp.getKey().getLocalName(), tp); tdt.setProperties(properties); assertEquals(properties, tdt.getProperties()); @@ -82,8 +83,7 @@ public class JpaToscaDataTypeTest { assertEquals(tdt, tdtClone0); assertEquals(0, tdt.compareTo(tdtClone0)); - JpaToscaDataType tdtClone1 = new JpaToscaDataType(); - tdt.copyTo(tdtClone1); + JpaToscaDataType tdtClone1 = new JpaToscaDataType(tdt); assertEquals(tdt, tdtClone1); assertEquals(0, tdt.compareTo(tdtClone1)); @@ -91,7 +91,7 @@ public class JpaToscaDataTypeTest { assertEquals(0, tdt.compareTo(tdt)); assertFalse(tdt.compareTo(tdt.getKey()) == 0); - PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1"); + PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001); JpaToscaDataType otherDt = new JpaToscaDataType(otherDtKey); assertFalse(tdt.compareTo(otherDt) == 0); @@ -102,10 +102,6 @@ public class JpaToscaDataTypeTest { otherDt.setProperties(properties); assertEquals(0, tdt.compareTo(otherDt)); - assertThatThrownBy(() -> { - tdt.copyTo(null); - }).hasMessage("target is marked @NonNull but is null"); - assertEquals(3, tdt.getKeys().size()); assertEquals(1, new JpaToscaDataType().getKeys().size()); @@ -128,7 +124,7 @@ public class JpaToscaDataTypeTest { assertThatThrownBy(() -> { tdt.validate(null); - }).hasMessage("resultIn is marked @NonNull but is null"); + }).hasMessageMatching("resultIn is marked .*on.*ull but is null"); ToscaDataType dat = new ToscaDataType(); dat.setName("name"); @@ -145,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()); + } }