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%2FJpaToscaPropertyTest.java;h=685266a9fc76d9daa220e469f7dc413e7bc52f64;hb=3c629ea3357cbe212db9acfcde002dac8b821ac2;hp=b8288810864d9e1cea17366f7a0b0793f9f1ffe9;hpb=b0fc73fd9ff6d9727c0f93a7ad0a742b704b4c9d;p=policy%2Fmodels.git 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 b82888108..685266a9f 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 @@ -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"); @@ -32,6 +32,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; @@ -51,7 +52,7 @@ public class JpaToscaPropertyTest { private static final String VERSION_001 = "0.0.1"; @Test - public void testPropertyPojo() { + public void testPropertyNull() { assertNotNull(new JpaToscaProperty()); assertNotNull(new JpaToscaProperty(new PfReferenceKey())); assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey())); @@ -65,7 +66,10 @@ public class JpaToscaPropertyTest { assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null)) .hasMessageMatching("type is marked .*on.*ull but is null"); + } + @Test + public void testProperty() { PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); @@ -112,13 +116,23 @@ public class JpaToscaPropertyTest { assertEquals(-1, tp.compareTo(null)); assertEquals(0, tp.compareTo(tp)); assertNotEquals(0, tp.compareTo(tp.getKey())); + } + + @Test + public void testPropertyCompareData() { + JpaToscaProperty tp = setUpJpaToscaProperty(); PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherProperty"); JpaToscaProperty otherDt = new JpaToscaProperty(otherDtKey); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); + PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); otherDt.setKey(pkey); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); otherDt.setType(ptypeKey); assertNotEquals(0, tp.compareTo(otherDt)); otherDt.setDescription(A_DESCRIPTION); @@ -130,10 +144,21 @@ public class JpaToscaPropertyTest { otherDt.setStatus(ToscaProperty.Status.SUPPORTED); assertNotEquals(0, tp.compareTo(otherDt)); assertNotEquals(0, tp.compareTo(otherDt)); + + List constraints = new ArrayList<>(); + JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello"); + constraints.add(lsc); otherDt.setConstraints(constraints); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); otherDt.setEntrySchema(tes); assertNotEquals(0, tp.compareTo(otherDt)); + + TreeMap metadata = new TreeMap<>(); + metadata.put("metaA", "dataA"); + metadata.put("metaB", "dataB"); otherDt.setMetadata(metadata); assertEquals(0, tp.compareTo(otherDt)); @@ -152,6 +177,12 @@ public class JpaToscaPropertyTest { assertEquals(3, tp.getKeys().size()); assertEquals(2, new JpaToscaProperty().getKeys().size()); + } + + @Test + public void testPropertyCompareDescription() { + JpaToscaProperty tp = setUpJpaToscaProperty(); + JpaToscaProperty tdtClone0 = new JpaToscaProperty(tp); new JpaToscaProperty().clean(); tp.clean(); @@ -169,6 +200,12 @@ public class JpaToscaPropertyTest { tp.setType(null); assertFalse(tp.validate("").isValid()); + } + + @Test + public void testPropertyCompareMetadata() { + JpaToscaProperty tp = setUpJpaToscaProperty(); + PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); tp.setType(typeKey); assertTrue(tp.validate("").isValid()); @@ -239,4 +276,29 @@ public class JpaToscaPropertyTest { assertEquals(tp.toString(), tp2.toString()); assertEquals(tp, tp2); } + + private JpaToscaProperty setUpJpaToscaProperty() { + PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); + PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); + PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); + + JpaToscaProperty tp = new JpaToscaProperty(pkey, ptypeKey); + tp.setDescription(A_DESCRIPTION); + tp.setRequired(false); + tp.setDefaultValue(DEFAULT_KEY); + tp.setStatus(ToscaProperty.Status.SUPPORTED); + + JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello"); + // Maps and Lists need to be modifiable + List constraints = new ArrayList<>(List.of(lsc)); + tp.setConstraints(constraints); + + PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); + tp.setEntrySchema(tes); + TreeMap metadata = new TreeMap<>(Map.of("metaA", "dataA", "metaB", "dataB")); + tp.setMetadata(metadata); + + return tp; + } }