summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-03-04 14:13:06 +0000
committerGerrit Code Review <gerrit@onap.org>2021-03-04 14:13:06 +0000
commit8d77651dfb0ade7d5b9059260788ec583340c590 (patch)
treefa8af25556eb0cb8b1c9aef6f73ea2bf9223ec36
parentfcbf3698fa3e3fbc6ea3364d80d4a3f3a8d37650 (diff)
parent24e47e99077ab0b7608fca68bd30a7bc70e766c2 (diff)
Merge "Fix sonar issues on policy-models"
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java2
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java31
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java94
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java10
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java15
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java142
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java32
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java77
8 files changed, 251 insertions, 152 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
index a99651999..22d29f745 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfTimestampKey.java
@@ -113,7 +113,7 @@ public class PfTimestampKey extends PfKeyImpl {
}
public void setInstant(final Instant instant) {
- setTimeStamp(Timestamp.from(instant));;
+ setTimeStamp(Timestamp.from(instant));
}
@Override
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,
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
index ad29a7199..675ec3258 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,12 +80,7 @@ public class ToscaServiceTemplateUtilsTest {
JpaToscaServiceTemplate compositeTemplate00 =
ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate00);
- assertEquals(compositeTemplate00,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate00));
- assertEquals(compositeTemplate00,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate00, new JpaToscaServiceTemplate()));
- assertEquals(compositeTemplate00,
- ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate00));
+ checkFragments(compositeTemplate00, fragmentTemplate00);
JpaToscaDataType dt0 = new JpaToscaDataType();
dt0.setKey(new PfConceptKey("dt0", "0.0.1"));
@@ -96,21 +91,11 @@ public class ToscaServiceTemplateUtilsTest {
JpaToscaServiceTemplate compositeTemplate01 =
ToscaServiceTemplateUtils.addFragment(originalTemplate, fragmentTemplate01);
- assertEquals(compositeTemplate01,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate01, fragmentTemplate01));
- assertEquals(compositeTemplate01,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate01, new JpaToscaServiceTemplate()));
- assertEquals(compositeTemplate01,
- ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate01));
+ checkFragments(compositeTemplate01, fragmentTemplate01);
JpaToscaServiceTemplate compositeTemplate02 =
ToscaServiceTemplateUtils.addFragment(compositeTemplate00, fragmentTemplate01);
- assertEquals(compositeTemplate02,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate02, fragmentTemplate01));
- assertEquals(compositeTemplate02,
- ToscaServiceTemplateUtils.addFragment(compositeTemplate02, new JpaToscaServiceTemplate()));
- assertEquals(compositeTemplate02,
- ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate02));
+ checkFragments(compositeTemplate02, fragmentTemplate01);
JpaToscaDataType otherDt0 = new JpaToscaDataType();
otherDt0.setKey(new PfConceptKey("dt0", "0.0.1"));
@@ -219,4 +204,13 @@ public class ToscaServiceTemplateUtilsTest {
ToscaServiceTemplateUtils.addFragment(compositeTemplate05, fragmentTemplate09);
assertEquals(compositeTemplate05.getTopologyTemplate(), compositeTemplate06.getTopologyTemplate());
}
+
+ private void checkFragments(JpaToscaServiceTemplate compositeTemplate, JpaToscaServiceTemplate fragmentTemplate) {
+ assertEquals(compositeTemplate,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate, fragmentTemplate));
+ assertEquals(compositeTemplate,
+ ToscaServiceTemplateUtils.addFragment(compositeTemplate, new JpaToscaServiceTemplate()));
+ assertEquals(compositeTemplate,
+ ToscaServiceTemplateUtils.addFragment(new JpaToscaServiceTemplate(), compositeTemplate));
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
index 0880fd97b..a40e9c298 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -174,6 +174,10 @@ public class ToscaUtilsTest {
assertThatThrownBy(() -> {
ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), new JpaToscaDataType(), null);
}).hasMessageMatching("result is marked .*on.*ull but is null");
+ }
+
+ @Test
+ public void testGetentityTypeAncestorsDataType() {
JpaToscaDataTypes dataTypes = new JpaToscaDataTypes();
JpaToscaDataType dt0 = new JpaToscaDataType();
@@ -181,22 +185,19 @@ public class ToscaUtilsTest {
dt0.setDescription("dt0 description");
BeanValidationResult result = new BeanValidationResult("", null);
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result)).isEmpty();
dataTypes.getConceptMap().put(dt0.getKey(), dt0);
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertTrue(result.isValid());
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt0, result);
dt0.setDerivedFrom(null);
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertTrue(result.isValid());
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt0, result);
dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertTrue(result.isValid());
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt0, result);
dt0.setDerivedFrom(new PfConceptKey("some.thing.Else", PfKey.NULL_KEY_VERSION));
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result)).isEmpty();
assertFalse(result.isValid());
assertThat(result.getResult()).contains("parent").contains("some.thing.Else:0.0.0")
.contains(Validated.NOT_FOUND);
@@ -208,32 +209,21 @@ public class ToscaUtilsTest {
dt1.setKey(new PfConceptKey("dt1", "0.0.1"));
dt1.setDescription("dt1 description");
dataTypes.getConceptMap().put(dt1.getKey(), dt1);
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
- assertTrue(result.isValid());
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt0, result);
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt1, result);
dt1.setDerivedFrom(dt0.getKey());
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
- assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
- assertTrue(result.isValid());
+ checkMultipleEmptyEntityTypeAncestors(dataTypes, dt0, dt1, result, 1);
JpaToscaDataType dt2 = new JpaToscaDataType();
dt2.setKey(new PfConceptKey("dt2", "0.0.1"));
dt2.setDescription("dt2 description");
dataTypes.getConceptMap().put(dt2.getKey(), dt2);
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
- assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
- assertTrue(result.isValid());
+ checkMultipleEmptyEntityTypeAncestors(dataTypes, dt0, dt1, result, 1);
dt2.setDerivedFrom(dt1.getKey());
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
- assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
- assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
- assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
- assertTrue(result.isValid());
+ checkMultipleEmptyEntityTypeAncestors(dataTypes, dt0, dt1, result, 1);
+ checkMultipleEmptyEntityTypeAncestors(dataTypes, dt0, dt2, result, 2);
dt0.setDerivedFrom(dt0.getKey());
assertThatThrownBy(() -> {
@@ -244,19 +234,38 @@ public class ToscaUtilsTest {
assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
dt1.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
- assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
- assertEquals(0, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
- assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
- assertTrue(result.isValid());
+ checkSingleEmptyEntityTypeAncestor(dataTypes, dt0, result);
+ checkMultipleEmptyEntityTypeAncestors(dataTypes, dt1, dt2, result, 1, 0);
dataTypes.getConceptMap().remove(dt1.getKey());
- assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result)).isEmpty();
assertFalse(result.isValid());
assertThat(result.getResult()).contains("parent").contains("dt1:0.0.1").contains(Validated.NOT_FOUND);
}
+ private void checkSingleEmptyEntityTypeAncestor(JpaToscaDataTypes dataTypes, JpaToscaDataType emptydt,
+ BeanValidationResult result) {
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, emptydt, result)).isEmpty();
+ assertTrue(result.isValid());
+ }
+
+ private void checkMultipleEmptyEntityTypeAncestors(JpaToscaDataTypes dataTypes, JpaToscaDataType emptydt,
+ JpaToscaDataType notemptydt, BeanValidationResult result, int size1) {
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, emptydt, result)).isEmpty();
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, notemptydt, result).isEmpty());
+ assertEquals(size1, ToscaUtils.getEntityTypeAncestors(dataTypes, notemptydt, result).size());
+ assertTrue(result.isValid());
+ }
+
+ private void checkMultipleEmptyEntityTypeAncestors(JpaToscaDataTypes dataTypes, JpaToscaDataType emptydt,
+ JpaToscaDataType notemptydt, BeanValidationResult result, int size1, int size2) {
+ assertThat(ToscaUtils.getEntityTypeAncestors(dataTypes, emptydt, result)).isEmpty();
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, notemptydt, result).isEmpty());
+ assertEquals(size1, ToscaUtils.getEntityTypeAncestors(dataTypes, notemptydt, result).size());
+ assertEquals(size2, ToscaUtils.getEntityTypeAncestors(dataTypes, emptydt, result).size());
+ assertTrue(result.isValid());
+ }
+
@Test
public void testGetPredefinedDataTypes() {
assertTrue(ToscaUtils.getPredefinedDataTypes().contains(new PfConceptKey("string", PfKey.NULL_KEY_VERSION)));
@@ -278,7 +287,7 @@ public class ToscaUtilsTest {
filteredDataTypes.getConceptMap().put(dt0.getKey(), dt0);
ToscaUtils.getEntityTree(filteredDataTypes, "IDontExist", "0.0.0");
assertNotEquals(dataTypes, filteredDataTypes);
- assertTrue(filteredDataTypes.getConceptMap().isEmpty());
+ assertThat(filteredDataTypes.getConceptMap()).isEmpty();
filteredDataTypes.getConceptMap().put(dt0.getKey(), dt0);
ToscaUtils.getEntityTree(filteredDataTypes, dt0.getKey().getName(), dt0.getKey().getVersion());