diff options
author | liamfallon <liam.fallon@est.tech> | 2020-11-20 10:24:44 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-12-01 12:27:54 +0000 |
commit | 950cbb8872fb2227f4a0382a756a7e1dff53b09c (patch) | |
tree | ce493c7161872360f4d88c5065c0730d53987c82 /models-base/src/test/java | |
parent | 1dd41890f83702d47c5a957493046433989ef36c (diff) |
Add extra authorative TOSCA concepts
This review brings in extra TOSCA concepts for Node types, nodes, and
capabilities.
The TOSCA handling is also amended to make the handling of equality
consistent. Now, if filtering or ordering is required using an order
rather than natural ordering, a comparator must be supplied by the user.
Issue-ID: POLICY-2900
Change-Id: Ie40e86870b97eb993b1338bdc0666ac116f72f67
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/test/java')
8 files changed, 101 insertions, 19 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java new file mode 100644 index 000000000..ea0762711 --- /dev/null +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java @@ -0,0 +1,35 @@ +/*- + * ============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.base; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.policy.models.base.testconcepts.DummyBadPfConcept; +import org.onap.policy.models.base.testconcepts.DummyPfConcept; + +public class PfConceptComparatorTest { + + @Test + public void testPfConceptComparator() { + assertEquals(0, new PfConceptComparator().compare(new DummyPfConcept(), new DummyPfConcept())); + } +} diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java index 424293f78..6d02b2fdd 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java @@ -21,6 +21,7 @@ package org.onap.policy.models.base; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -50,5 +51,14 @@ public class PfConceptFilterTest { final PfConceptFilter conceptFilterNull = new PfConceptFilter(null, null, null); conceptFilterNull.filter(null); }).hasMessageMatching("^originalList is marked .*on.*ull but is null$"); + + conceptFilter.setName("hello"); + assertEquals("hello", conceptFilter.getName()); + + conceptFilter.setVersion("1.2.3"); + assertEquals("1.2.3", conceptFilter.getVersion()); + + conceptFilter.setVersionPrefix("AAA"); + assertEquals("AAA", conceptFilter.getVersionPrefix()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java index 7bf270b5f..8b94a48c3 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java @@ -145,6 +145,12 @@ public class PfKeyImplTest { MyKey someKey8 = new MyKey(); someKey8.setVersion(VERSION001); assertFalse(someKey8.isNullKey()); + + someKey8.setVersion("10"); + assertEquals(0, someKey8.getMinorVersion()); + + someKey8.setVersion("10.11"); + assertEquals(0, someKey8.getPatchVersion()); } @Test diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java index 2e742c336..5cebf1e91 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java @@ -22,6 +22,7 @@ package org.onap.policy.models.base; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import javax.ws.rs.core.Response; import org.junit.Test; @@ -39,10 +40,12 @@ public class PfModelExceptionInfoTest { final PfModelException pfme = new PfModelException(Response.Status.ACCEPTED, "HELLO"); assertThat(pfme).hasMessage("HELLO"); assertEquals("Server returned: Accepted", getErrorMessage(pfme).substring(0, 25)); + assertNotNull(pfme.toString()); final PfModelRuntimeException pfmr = new PfModelRuntimeException(Response.Status.ACCEPTED, "HELLO"); assertThat(pfmr).hasMessage("HELLO"); assertEquals("Server returned: Accepted", getErrorMessage(pfmr).substring(0, 25)); + assertNotNull(pfmr.toString()); } private String getErrorMessage(final ErrorResponseInfo eri) { diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java index 7152b12f1..2937b60ab 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-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. @@ -57,6 +57,9 @@ public class PfNameVersionTest { dnv0.setVersion("1.2.3"); assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1)); + dnv1.setVersion(null); + assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1)); + dnv1.setVersion("1.2.3"); assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java index d6985e949..59d7ad70e 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -26,12 +26,14 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; import org.junit.Test; import org.onap.policy.models.base.testconcepts.DummyPfObject; +import org.onap.policy.models.base.testconcepts.DummyPfObjectComparator; import org.onap.policy.models.base.testconcepts.DummyPfObjectFilter; /** @@ -96,7 +98,7 @@ public class PfObjectFilterTest { assertEquals(true, dof.filterString(HELLO, HELLO)); assertEquals(true, dof.filterString(HELLO, null)); - List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList); + List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList, new DummyPfObjectComparator()); assertEquals(3, latestVersionList.size()); assertEquals("aaaaa", latestVersionList.get(0).getName()); assertEquals(VERSION002, latestVersionList.get(0).getVersion()); @@ -107,7 +109,8 @@ public class PfObjectFilterTest { latestVersionList.remove(2); latestVersionList.remove(1); - List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList); + List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList, + new DummyPfObjectComparator()); assertEquals(latestVersionList, newestVersionList); MyFilter filter = new MyFilter(); diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java index 53009ddc8..9759f4aef 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-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. @@ -33,21 +33,8 @@ import org.onap.policy.models.base.PfNameVersion; */ @Data @RequiredArgsConstructor -public class DummyPfObject implements PfNameVersion, Comparable<DummyPfObject> { +public class DummyPfObject implements PfNameVersion { private String name; private String version; private String description; - - @Override - public int compareTo(@NonNull final DummyPfObject otherObject) { - int result = ObjectUtils.compare(this.name, otherObject.name); - if (result != 0) { - return result; - } - result = ObjectUtils.compare(this.version, otherObject.version); - if (result != 0) { - return result; - } - return ObjectUtils.compare(this.description, otherObject.description); - } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java new file mode 100644 index 000000000..f83bce6a6 --- /dev/null +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java @@ -0,0 +1,35 @@ +/*- + * ============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.base.testconcepts; + +import java.util.Comparator; +import org.onap.policy.models.base.PfNameVersion; + +/** + * Compare two PfNameVersion objects. + */ +public class DummyPfObjectComparator implements Comparator<DummyPfObject> { + + @Override + public int compare(final DummyPfObject left, final DummyPfObject right) { + return left.compareNameVersion(left, right); + } +} |