aboutsummaryrefslogtreecommitdiffstats
path: root/models-base
diff options
context:
space:
mode:
Diffstat (limited to 'models-base')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java3
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java2
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java16
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java8
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java22
5 files changed, 45 insertions, 6 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
index e197e13a4..65a28cffe 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
@@ -170,6 +170,9 @@ public class PfConceptContainer<C extends PfConcept, A extends PfNameVersion> ex
if (incomingConceptEntry.getValue().getVersion() != null) {
conceptKey.setVersion(incomingConceptEntry.getValue().getVersion());
}
+ else {
+ conceptKey.setVersion(PfKey.NULL_KEY_VERSION);
+ }
// After all that, save the map entry
conceptMap.put(conceptKey, jpaConcept);
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java
index a377c24be..0fca00d39 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java
@@ -59,7 +59,7 @@ public interface PfObjectFilter<T extends Comparable<T>> {
* @return the filtered list
*/
public default List<T> latestVersionFilter(final List<T> originalList) {
- List<T> filteredList = new ArrayList<>();
+ List<T> filteredList = new ArrayList<>(originalList);
Collections.sort(filteredList);
List<T> filteredOutList = new ArrayList<>();
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 3ae7c4c9d..55f59f640 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
@@ -48,6 +48,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
*/
public class PfConceptContainerTest {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testConceptContainer() {
DummyPfConceptContainer container = new DummyPfConceptContainer();
@@ -63,6 +64,13 @@ public class PfConceptContainerTest {
assertNotNull(container);
try {
+ new PfConceptContainer((PfConceptKey) null, null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
container = new DummyPfConceptContainer((PfConceptKey) null, null);
fail("test should throw an exception here");
} catch (Exception exc) {
@@ -190,7 +198,7 @@ public class PfConceptContainerTest {
public void testAuthorative() {
Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>();
dacMap.put("name0", new DummyAuthorativeConcept("name0", "1.2.3", "Hello"));
- dacMap.put("name1", new DummyAuthorativeConcept("name1", "1.2.3", "Hi"));
+ dacMap.put("name1", new DummyAuthorativeConcept(null, null, "Hi"));
dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy"));
List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>();
@@ -200,12 +208,14 @@ public class PfConceptContainerTest {
container.fromAuthorative(authorativeList);
assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription());
- assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:1.2.3")).getDescription());
+ assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:0.0.0")).getDescription());
assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription());
List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative();
- assertEquals(dacMap, outMapList.get(0));
+ assertEquals(dacMap.get("name0"), outMapList.get(0).get("name0"));
+ assertEquals(dacMap.get("name1").getDescription(), outMapList.get(0).get("name1").getDescription());
+ assertEquals(dacMap.get("name2"), outMapList.get(0).get("name2"));
DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer();
assertThatThrownBy(() -> {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
index a4c504788..797dba0cf 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
@@ -48,6 +48,13 @@ public class PfKeyTest {
e.getMessage());
}
+ try {
+ new PfConceptKey((PfConceptKey) null);
+ fail("This test should throw an exception");
+ } catch (Exception e) {
+ assertEquals("copyConcept is marked @NonNull but is null", e.getMessage());
+ }
+
PfConceptKey someKey0 = new PfConceptKey();
assertEquals(PfConceptKey.getNullKey(), someKey0);
@@ -56,6 +63,7 @@ public class PfKeyTest {
PfConceptKey someKey3 = new PfConceptKey(someKey1.getId());
assertEquals(someKey1, someKey2);
assertEquals(someKey1, someKey3);
+ assertFalse(someKey1.isNullVersion());
assertEquals(someKey2, someKey1.getKey());
assertEquals(1, someKey1.getKeys().size());
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 72df28f04..68494309c 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,4 +1,4 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* ================================================================================
@@ -41,7 +41,7 @@ public class PfKeyUseTest {
assertNotNull(new PfKeyUse(new PfReferenceKey()));
try {
- new PfKeyUse((PfKeyUse)null);
+ new PfKeyUse((PfKeyUse) null);
fail("test should throw an exception");
} catch (Exception exc) {
assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
@@ -56,6 +56,14 @@ public class PfKeyUseTest {
assertFalse(keyUse.isNullKey());
assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
+
+ try {
+ key.getCompatibility(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
assertTrue(keyUse.isCompatible(key));
keyUse.clean();
@@ -132,6 +140,16 @@ public class PfKeyUseTest {
assertEquals("error copying concept key: Some error message", exc.getMessage());
}
+ try {
+ keyUse.isNewerThan(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(false, testKeyUse.isNewerThan(keyUse));
+ assertEquals(false, testKeyUse.isNewerThan(testKeyUse));
+
assertEquals(0, testKeyUse.getMajorVersion());
assertEquals(0, testKeyUse.getMinorVersion());
assertEquals(0, testKeyUse.getPatchVersion());