diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2023-07-27 10:12:59 +0100 |
---|---|---|
committer | adheli.tavares <adheli.tavares@est.tech> | 2023-09-22 12:58:53 +0100 |
commit | 938005505883cf7a636a8840e20e3dc8a0ad9176 (patch) | |
tree | f2820c1f44c458e95e565943b04b697cb5c88c12 /models-tosca/src/test/java | |
parent | d19537308cbdce440c1faf819eb586983d0a67c9 (diff) |
Java 17 Upgrade
Issue-ID: POLICY-4669
Change-Id: I0157ae0ea7151658308c7e6d429098f16824c190
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'models-tosca/src/test/java')
4 files changed, 65 insertions, 46 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java index 53b42caa7..2fdd29c5a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,6 +21,7 @@ package org.onap.policy.models.tosca.simple.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; @@ -69,7 +70,7 @@ public class JpaToscaConstraintLogicalTest { JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5); assertNull(jc5.toAuthorative()); - assertEquals(-1, jc0.compareTo(null)); + assertThatThrownBy(() -> jc0.compareTo(null)).isInstanceOf(NullPointerException.class); assertEquals(0, jc0.compareTo(jc0)); assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>()))); assertEquals(-2, jc0.compareTo(jc1)); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java index 6c39737f1..02e3fdae3 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -68,7 +68,7 @@ public class JpaToscaConstraintTest { validValues.add("hello"); validValues.add("goodbye"); JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues); - assertEquals(-1, cvv0.compareTo(null)); + assertThatThrownBy(() -> cvv0.compareTo(null)).isInstanceOf(NullPointerException.class); assertEquals(0, cvv0.compareTo(cvv0)); assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT))); JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues); @@ -81,7 +81,7 @@ public class JpaToscaConstraintTest { rangeValues.add("hello"); rangeValues.add("goodbye"); JpaToscaConstraintInRange cir0 = new JpaToscaConstraintInRange(rangeValues); - assertEquals(-1, cir0.compareTo(null)); + assertThatThrownBy(() -> cir0.compareTo(null)).isInstanceOf(NullPointerException.class); assertEquals(0, cir0.compareTo(cir0)); assertNotEquals(0, cir0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT))); JpaToscaConstraintInRange cir1 = new JpaToscaConstraintInRange(rangeValues); 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 685266a9f..ffa21244c 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-2021 Nordix Foundation. + * Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -113,7 +113,7 @@ public class JpaToscaPropertyTest { assertEquals(tp, tdtClone1); assertEquals(0, tp.compareTo(tdtClone1)); - assertEquals(-1, tp.compareTo(null)); + assertThatThrownBy(() -> tp.compareTo(null)).isInstanceOf(NullPointerException.class); assertEquals(0, tp.compareTo(tp)); assertNotEquals(0, tp.compareTo(tp.getKey())); } 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"); - } } |