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=7399fdc33e1cfd47cd6abe26fd32e6d82e352d9f;hb=0f18850ed482e71db9d61fa2656e5e84c2f61f74;hp=e00e48f2118f3dffb5f4607bbc4e32260bb7fbfe;hpb=43aaa62cdf9a7dadfb6d688f1fe83c5bd355a86d;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 e00e48f21..7399fdc33 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-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,7 +36,6 @@ 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; @@ -62,7 +61,10 @@ public class JpaToscaDataTypeTest { assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null)) .isInstanceOf(NullPointerException.class); + } + @Test + public void testDataTypeProperties() { PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001); JpaToscaDataType tdt = new JpaToscaDataType(dtKey); @@ -109,23 +111,30 @@ public class JpaToscaDataTypeTest { tdt.clean(); assertEquals(tdtClone0, tdt); - assertFalse(new JpaToscaDataType().validate(new PfValidationResult()).isValid()); - assertTrue(tdt.validate(new PfValidationResult()).isValid()); + assertFalse(new JpaToscaDataType().validate("").isValid()); + validateJpaToscaDataTypeOperations(tdt); + + assertThatThrownBy(() -> { + tdt.validate(null); + }).hasMessageMatching("fieldName is marked .*on.*ull but is null"); + } + + private void validateJpaToscaDataTypeOperations(JpaToscaDataType tdt) { + assertTrue(tdt.validate("").isValid()); tdt.getConstraints().add(null); - assertFalse(tdt.validate(new PfValidationResult()).isValid()); + assertFalse(tdt.validate("").isValid()); tdt.getConstraints().remove(null); - assertTrue(tdt.validate(new PfValidationResult()).isValid()); + assertTrue(tdt.validate("").isValid()); tdt.getProperties().put(null, null); - assertFalse(tdt.validate(new PfValidationResult()).isValid()); + assertFalse(tdt.validate("").isValid()); tdt.getProperties().remove(null); - assertTrue(tdt.validate(new PfValidationResult()).isValid()); - - assertThatThrownBy(() -> { - tdt.validate(null); - }).hasMessageMatching("result is marked .*on.*ull but is null"); + assertTrue(tdt.validate("").isValid()); + } + @Test + public void testDataTypeConstraints() { ToscaDataType dat = new ToscaDataType(); dat.setName("name"); dat.setVersion("1.2.3"); @@ -153,39 +162,39 @@ public class JpaToscaDataTypeTest { JpaToscaProperty prop0 = new JpaToscaProperty(new PfReferenceKey(dt0.getKey(), "prop0")); prop0.setType(new PfConceptKey("string", PfKey.NULL_KEY_VERSION)); - assertTrue(prop0.validate(new PfValidationResult()).isValid()); + assertTrue(prop0.validate("").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()); + assertTrue(prop1.validate("").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()); + assertTrue(prop2.validate("").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.setEntrySchema(new JpaToscaSchemaDefinition()); prop3.getEntrySchema().setType(new PfConceptKey("the.property.Type3", "0.0.1")); - assertTrue(prop3.validate(new PfValidationResult()).isValid()); + assertTrue(prop3.validate("").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.setEntrySchema(new JpaToscaSchemaDefinition()); prop4.getEntrySchema().setType(new PfConceptKey("the.property.Type2", "0.0.1")); - assertTrue(prop4.validate(new PfValidationResult()).isValid()); + assertTrue(prop4.validate("").isValid()); dt0.getProperties().put(prop4.getKey().getLocalName(), prop4); assertEquals(3, dt0.getReferencedDataTypes().size());