aboutsummaryrefslogtreecommitdiffstats
path: root/models-base
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-08 13:58:53 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-08 13:58:53 +0000
commit9ce39af891ccf063d46e18ecf5a2a47eb1408930 (patch)
treeeb55cc63c83ea34f73aeaaae5039c96283b66ef8 /models-base
parenteb7127ac85b3df30a09277721a5f9271033843e7 (diff)
Add bug fixes and tests for filters
Fixed bugs on filtering where lack of null checks was blocking all results. Added unit test for PDP related JPA objects. Fixed cascading and orphan control on JPA objects. Added partial testing of PdpProvider. Added partial testing of filters. Changed tag for content of operational policies from "Content" to "content". Issue-ID: POLICY-1095 Change-Id: Ieb22e06955a8434b490bae7d0f6b77d4479515e8 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java12
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java8
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java21
4 files changed, 25 insertions, 20 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
index ee476e3b2..5d6ac13c1 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
@@ -51,10 +51,10 @@ public class PfConceptKey extends PfKey {
private static final String NAME_TOKEN = "name";
private static final String VERSION_TOKEN = "version";
- @Column(name = NAME_TOKEN, length = 128)
+ @Column(name = NAME_TOKEN, length = 120)
private String name;
- @Column(name = VERSION_TOKEN, length = 128)
+ @Column(name = VERSION_TOKEN, length = 20)
private String version;
/**
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 6ede4d9a3..501d9c353 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
@@ -46,11 +46,11 @@ public interface PfObjectFilter<T extends Comparable<T>> {
* Check if a value matches a regular expression.
*
* @param value the incoming value to check
- * @param regexp the regular expression to check against
+ * @param pattern the pattern to check against
* @return match or not
*/
- public default boolean filterOnRegexp(@NonNull final String value, @NonNull final String regexp) {
- return value.matches(regexp);
+ public default boolean filterString(@NonNull final String value, final String pattern) {
+ return pattern == null || value.equals(pattern);
}
/**
@@ -74,10 +74,10 @@ public interface PfObjectFilter<T extends Comparable<T>> {
T lastElement = filteredList.get(j);
/*
- * The list is sorted so if the last element name is the same as the current
- * element name, the current element should be removed.
+ * The list is sorted so if the last element name is the same as the current element name, the current
+ * element should be removed.
*/
- if (!((PfNameVersion)curElement).getName().equals(((PfNameVersion)lastElement).getName())) {
+ if (!((PfNameVersion) curElement).getName().equals(((PfNameVersion) lastElement).getName())) {
// have a new name - done comparing with the old "current"
++icur;
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
index 185ccfa69..bda5aed12 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
@@ -73,16 +73,16 @@ public class PfReferenceKey extends PfKey {
private static final int PARENT_LOCAL_NAME_FIELD = 2;
private static final int LOCAL_NAME_FIELD = 3;
- @Column(name = PARENT_KEY_NAME, length = 128)
+ @Column(name = PARENT_KEY_NAME, length = 120)
private String parentKeyName;
- @Column(name = PARENT_KEY_VERSION, length = 128)
+ @Column(name = PARENT_KEY_VERSION, length = 15)
private String parentKeyVersion;
- @Column(name = PARENT_LOCAL_NAME, length = 128)
+ @Column(name = PARENT_LOCAL_NAME, length = 120)
private String parentLocalName;
- @Column(name = LOCAL_NAME, length = 128)
+ @Column(name = LOCAL_NAME, length = 120)
private String localName;
/**
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 c3ccb4aa5..3d16f8e3f 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
@@ -81,21 +81,21 @@ public class PfObjectFilterTest {
doList.add(do5);
DummyPfObjectFilter dof = new DummyPfObjectFilter();
- assertFalse(dof.filterOnRegexp("Hello", "Goodbye"));
- assertTrue(dof.filterOnRegexp("Hello", "Hello"));
+ assertFalse(dof.filterString("Hello", "Goodbye"));
+ assertTrue(dof.filterString("Hello", "Hello"));
assertThatThrownBy(() -> {
- dof.filterOnRegexp(null, null);
+ dof.filterString(null, null);
}).hasMessage("value is marked @NonNull but is null");
assertThatThrownBy(() -> {
- dof.filterOnRegexp("hello", null);
- }).hasMessage("regexp is marked @NonNull but is null");
-
- assertThatThrownBy(() -> {
- dof.filterOnRegexp(null, "hello");
+ dof.filterString(null, "hello");
}).hasMessage("value is marked @NonNull but is null");
+ assertEquals(false, dof.filterString("Hello", "Goodbye"));
+ assertEquals(true, dof.filterString("Hello", "Hello"));
+ assertEquals(true, dof.filterString("Hello", null));
+
List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList);
assertEquals(3, latestVersionList.size());
assertEquals("aaaaa", latestVersionList.get(0).getName());
@@ -104,5 +104,10 @@ public class PfObjectFilterTest {
assertEquals("1.0.0", 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);
+ assertEquals(latestVersionList, newestVersionList);
}
}