diff options
Diffstat (limited to 'models-base/src/test/java/org')
5 files changed, 194 insertions, 98 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java index 8c74850d2..f5c6e3a9b 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.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"); @@ -42,11 +42,6 @@ import org.onap.policy.models.base.testconcepts.DummyPfConcept; import org.onap.policy.models.base.testconcepts.DummyPfConceptContainer; import org.onap.policy.models.base.testconcepts.DummyPfConceptSub; -/** - * Test the PfCOnceptCOntainer class. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ public class PfConceptContainerTest { private static final String NAME0 = "name0"; @@ -83,7 +78,11 @@ public class PfConceptContainerTest { assertThatThrownBy(() -> new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>())) .hasMessageMatching(KEY_IS_NULL); + } + @Test + public void testNamedConceptContainer() { + DummyPfConceptContainer container = new DummyPfConceptContainer(); container.getKey().setName(DUMMY_VALUE); DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container); assertNotNull(clonedContainer); @@ -132,6 +131,15 @@ public class PfConceptContainerTest { PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0_0_1); testContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertNotEquals(0, container.compareTo(testContainer)); + } + + @Test + public void testValidationContainer() { + DummyPfConceptContainer container = new DummyPfConceptContainer(); + PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0_0_1); + Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>(); + conceptMap.put(conceptKey, new DummyPfConcept(conceptKey)); + container.setConceptMap(conceptMap); final DummyPfConceptContainer container3 = container; assertThatThrownBy(() -> container3.validate(null)) @@ -142,6 +150,7 @@ public class PfConceptContainerTest { validateContainer.setKey(new PfConceptKey("VCKey", VERSION0_0_1)); assertTrue(validateContainer.validate("").isValid()); + PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0_0_1); validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertTrue(validateContainer.validate("").isValid()); @@ -159,6 +168,15 @@ public class PfConceptContainerTest { assertFalse(validateContainer.validate("").isValid()); validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertTrue(validateContainer.validate("").isValid()); + } + + @Test + public void testSetContainer() { + DummyPfConceptContainer container = new DummyPfConceptContainer(); + PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0_0_1); + Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>(); + conceptMap.put(conceptKey, new DummyPfConcept(conceptKey)); + container.setConceptMap(conceptMap); assertEquals(conceptKey, container.get(conceptKey).getKey()); assertEquals(conceptKey, container.get(conceptKey.getName()).getKey()); @@ -191,6 +209,7 @@ public class PfConceptContainerTest { assertEquals(conceptKey, container.get(anotherKey).getKey()); } + @Test public void testAuthorative() { Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>(); 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 dc69e2e67..171077e35 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 @@ -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"); @@ -35,6 +35,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.annotations.Pattern; @@ -48,48 +49,71 @@ public class PfKeyImplTest { private static final String VERSION123 = "1.2.3"; private static final String VERSION100 = "1.0.0"; private static final String VERSION001 = "0.0.1"; - - @Test - public void testConceptKey() { - assertThatIllegalArgumentException().isThrownBy(() -> new MyKey("some bad key id")) - .withMessage("parameter \"id\": value \"some bad key id\", " + "does not match regular expression \"" - + PfKey.KEY_ID_REGEXP + "\""); - - assertThatThrownBy(() -> new MyKey((MyKey) null)) - .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); - - MyKey someKey0 = new MyKey(); - assertTrue(someKey0.isNullKey()); - assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey0); - - MyKey someKey1 = new MyKey("name", VERSION001); - MyKey someKey2 = new MyKey(someKey1); - MyKey someKey3 = new MyKey(someKey1.getId()); - assertEquals(someKey1, someKey2); - assertEquals(someKey1, someKey3); - assertFalse(someKey1.isNullKey()); - assertFalse(someKey1.isNullVersion()); - - assertEquals(someKey2, someKey1.getKey()); - assertEquals(1, someKey1.getKeys().size()); + private static MyKey someKey; + private static MyKey someKey0; + private static MyKey someKey1; + private static MyKey someKey2; + private static MyKey someKey3; + private static MyKey someKey4; + private static MyKey someKey4a; + private static MyKey someKey5; + private static MyKey someKey6; + + /** + * Sets data in Keys for the tests. + */ + @BeforeClass + public static void setUp() { + someKey = new MyKey(); + + someKey0 = new MyKey(); + someKey1 = new MyKey("name", VERSION001); + someKey2 = new MyKey(someKey1); + someKey3 = new MyKey(someKey1.getId()); someKey0.setName("zero"); someKey0.setVersion("0.0.2"); - someKey3.setVersion("0.0.2"); - MyKey someKey4 = new MyKey(someKey1); + someKey4 = new MyKey(someKey1); someKey4.setVersion("0.1.2"); - MyKey someKey4a = new MyKey(someKey1); + someKey4a = new MyKey(someKey1); someKey4a.setVersion("0.0.0"); - MyKey someKey5 = new MyKey(someKey1); + someKey5 = new MyKey(someKey1); someKey5.setVersion("1.2.2"); - MyKey someKey6 = new MyKey(someKey1); + someKey6 = new MyKey(someKey1); someKey6.setVersion("3.0.0"); + } + + @Test + public void testConceptKey() { + assertThatIllegalArgumentException().isThrownBy(() -> new MyKey("some bad key id")) + .withMessage("parameter \"id\": value \"some bad key id\", " + "does not match regular expression \"" + + PfKey.KEY_ID_REGEXP + "\""); + + assertThatThrownBy(() -> new MyKey((MyKey) null)) + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); + + assertTrue(someKey.isNullKey()); + assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey); + MyKey someKey11 = new MyKey("name", VERSION001); + MyKey someKey22 = new MyKey(someKey11); + MyKey someKey33 = new MyKey(someKey11.getId()); + assertEquals(someKey11, someKey22); + assertEquals(someKey11, someKey33); + assertFalse(someKey11.isNullKey()); + assertFalse(someKey11.isNullVersion()); + + assertEquals(someKey22, someKey11.getKey()); + assertEquals(1, someKey11.getKeys().size()); + } + + @Test + public void testCompatibilityConceptKey() { assertEquals("name:0.1.2", someKey4.getId()); assertThatThrownBy(() -> someKey0.getCompatibility(null)).isInstanceOf(NullPointerException.class) @@ -111,7 +135,10 @@ public class PfKeyImplTest { assertFalse(someKey1.isCompatible(someKey0)); assertFalse(someKey1.isCompatible(someKey5)); assertFalse(someKey1.isCompatible(new DummyPfKey())); + } + @Test + public void testValidityConceptKey() { assertTrue(someKey0.validate("").isValid()); assertTrue(someKey1.validate("").isValid()); assertTrue(someKey2.validate("").isValid()); @@ -119,7 +146,10 @@ public class PfKeyImplTest { assertTrue(someKey4.validate("").isValid()); assertTrue(someKey5.validate("").isValid()); assertTrue(someKey6.validate("").isValid()); + } + @Test + public void testCleanConceptKey() { someKey0.clean(); assertNotNull(someKey0.toString()); @@ -135,8 +165,8 @@ public class PfKeyImplTest { assertEquals(-36, someKey0.compareTo(new DummyPfKey())); assertNotEquals(someKey0, null); - assertEquals(someKey0, (Object) someKey0); - assertNotEquals(someKey0, (Object) new DummyPfKey()); + assertEquals(someKey0, someKey0); + assertNotEquals(someKey0, new DummyPfKey()); MyKey someKey8 = new MyKey(); someKey8.setVersion(VERSION001); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java index d2aebdc43..1b8534433 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.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"); @@ -71,17 +71,21 @@ public class PfKeyUseTest { assertNotEquals(0, keyUse.hashCode()); - assertEquals(keyUse, (Object) keyUse); + assertEquals(keyUse, keyUse); assertEquals(keyUse, clonedKeyUse); - assertNotEquals(keyUse, (Object) "Hello"); + assertNotEquals(keyUse, "Hello"); assertEquals(keyUse, new PfKeyUse(key)); assertEquals(0, keyUse.compareTo(keyUse)); assertEquals(0, keyUse.compareTo(clonedKeyUse)); assertNotEquals(0, keyUse.compareTo(new PfConceptKey())); assertEquals(0, keyUse.compareTo(new PfKeyUse(key))); + } + @Test + public void testNullKey() { PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey()); + PfKeyUse keyUse = new PfKeyUse(); assertEquals(false, keyUseNull.validate("").isValid()); assertThatThrownBy(() -> keyUse.setKey(null)).hasMessageMatching("^key is marked .*on.*ull but is null$"); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java index 760231a7c..8f0ca35ad 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.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"); @@ -94,6 +94,19 @@ public class PfModelTest { dpm.getKeyList().add(goodCKey); dpm.getKeyList().add(goodRKey); assertTrue(dpm.validate("").isValid()); + } + + @Test + public void testPfReferenceValidation() { + PfConceptKey dpmKey = new PfConceptKey("modelKey", VERSION001); + DummyPfModel dpm = new DummyPfModel(dpmKey); + + PfConceptKey goodCKey = new PfConceptKey("goodCKey", VERSION001); + PfReferenceKey goodRKey = new PfReferenceKey(goodCKey, "goodLocalName"); + + dpm.getKeyList().add(goodCKey); + dpm.getKeyList().add(goodRKey); + assertTrue(dpm.validate("").isValid()); PfConceptKey goodCKeyDup = new PfConceptKey(goodCKey); dpm.getKeyList().add(goodCKeyDup); 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 68cae439d..169d97f84 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-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,6 +51,90 @@ public class PfObjectFilterTest { @Test public void testPfObjectInterface() { + DummyPfObjectFilter dof = new DummyPfObjectFilter(); + assertFalse(dof.filterString(HELLO, "Goodbye")); + assertTrue(dof.filterString(HELLO, HELLO)); + + assertFalse(dof.filterString(HELLO, "Goodbye")); + assertTrue(dof.filterString(HELLO, HELLO)); + assertTrue(dof.filterString(HELLO, null)); + + List<DummyPfObject> doList = getListPfObject(); + List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList, new DummyPfObjectComparator()); + assertEquals(3, latestVersionList.size()); + assertEquals("aaaaa", latestVersionList.get(0).getName()); + assertEquals(VERSION002, latestVersionList.get(0).getVersion()); + assertEquals(NAME0, latestVersionList.get(1).getName()); + assertEquals(VERSION100, latestVersionList.get(1).getVersion()); + assertEquals(NAME1, latestVersionList.get(2).getName()); + assertEquals("0.1.2", latestVersionList.get(2).getVersion()); + + latestVersionList.remove(2); + latestVersionList.remove(1); + List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList, + new DummyPfObjectComparator()); + assertEquals(latestVersionList, newestVersionList); + } + + @Test + public void testStringFilteredPfObjectInterface() { + List<DummyPfObject> doList = getListPfObject(); + MyFilter filter = new MyFilter(); + + assertTrue(filter.filterString(null, HELLO)); + + DummyPfObject do0 = doList.get(0); + DummyPfObject do5 = doList.get(5); + DummyPfObject doNullVersion = new DummyPfObject(); + do5.setName("bbbbb"); + + assertFalse(filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, VERSION100)); + assertFalse(filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1")); + assertFalse(filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "2.0.0")); + assertTrue(filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, null)); + assertTrue(filter(filter::filterStringPred, DummyPfObject::getVersion, do0, null)); + assertTrue(filter(filter::filterStringPred, DummyPfObject::getVersion, do0, VERSION100)); + } + + @Test + public void testPrefixFilteredPfObjectInterface() { + + DummyPfObject doNullVersion = new DummyPfObject(); + MyFilter filter = new MyFilter(); + + List<DummyPfObject> doList = getListPfObject(); + DummyPfObject do0 = doList.get(0); + + assertFalse(filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, "1.")); + assertFalse(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); + assertFalse(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); + assertFalse(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "2")); + assertTrue(filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, null)); + assertTrue(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, null)); + assertTrue(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.")); + assertTrue(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.")); + assertTrue(filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, VERSION100)); + } + + @Test + public void testRegexFilteredPfObjectInterface() { + List<DummyPfObject> doList = getListPfObject(); + DummyPfObject do0 = doList.get(0); + + MyFilter filter = new MyFilter(); + DummyPfObject doNullVersion = new DummyPfObject(); + + assertFalse(filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, "1[.].*")); + assertFalse(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "2[.].*")); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, null)); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, null)); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.].*")); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.].*")); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.]0")); + assertTrue(filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1....")); + } + + private List<DummyPfObject> getListPfObject() { DummyPfObject do0 = new DummyPfObject(); do0.setName(NAME0); do0.setVersion(VERSION100); @@ -89,61 +173,7 @@ public class PfObjectFilterTest { doList.add(do4); doList.add(do5); - DummyPfObjectFilter dof = new DummyPfObjectFilter(); - assertFalse(dof.filterString(HELLO, "Goodbye")); - assertTrue(dof.filterString(HELLO, HELLO)); - - assertEquals(false, dof.filterString(HELLO, "Goodbye")); - assertEquals(true, dof.filterString(HELLO, HELLO)); - assertEquals(true, dof.filterString(HELLO, null)); - - List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList, new DummyPfObjectComparator()); - assertEquals(3, latestVersionList.size()); - assertEquals("aaaaa", latestVersionList.get(0).getName()); - assertEquals(VERSION002, latestVersionList.get(0).getVersion()); - assertEquals(NAME0, latestVersionList.get(1).getName()); - assertEquals(VERSION100, latestVersionList.get(1).getVersion()); - assertEquals(NAME1, latestVersionList.get(2).getName()); - assertEquals("0.1.2", latestVersionList.get(2).getVersion()); - - latestVersionList.remove(2); - latestVersionList.remove(1); - List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList, - new DummyPfObjectComparator()); - assertEquals(latestVersionList, newestVersionList); - - MyFilter filter = new MyFilter(); - - assertEquals(true, filter.filterString(null, HELLO)); - - DummyPfObject doNullVersion = new DummyPfObject(); - do5.setName("bbbbb"); - - assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, VERSION100)); - assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1")); - assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "2.0.0")); - assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, null)); - assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, null)); - assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, VERSION100)); - - assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, "1.")); - assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); - assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); - assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "2")); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, null)); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, null)); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.")); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.")); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, VERSION100)); - - assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, "1[.].*")); - assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "2[.].*")); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, null)); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, null)); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.].*")); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.].*")); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1[.]0[.]0")); - assertEquals(true, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "1....")); + return doList; } private boolean filter(BiFunction<String, Function<DummyPfObject, String>, Predicate<DummyPfObject>> predMaker, |