summaryrefslogtreecommitdiffstats
path: root/models-base/src/test/java/org/onap
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-04-07 00:20:08 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-07 00:20:08 +0000
commit82699a970d5f06c6dc1391d8beb0efe76bf84089 (patch)
tree7b044561032482b0fbb7c47e92139a3f4fb84314 /models-base/src/test/java/org/onap
parentc7ebd4c91bdbf00faed2b9935b818c781803edd1 (diff)
parent422412ec8f21017aff1641f133c2258f52f7d706 (diff)
Merge "Fix bugs on filters"
Diffstat (limited to 'models-base/src/test/java/org/onap')
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java63
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java108
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java36
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java54
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java41
5 files changed, 302 insertions, 0 deletions
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
new file mode 100644
index 000000000..7152b12f1
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.DummyPfNameVersion;
+
+/**
+ * Test the {@link PfNameVersion} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfNameVersionTest {
+
+ @Test
+ public void testPfNameVersion() {
+ DummyPfNameVersion dnv0 = new DummyPfNameVersion();
+ DummyPfNameVersion dnv1 = new DummyPfNameVersion();
+
+ assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1));
+ assertEquals(0, dnv0.compareNameVersion(null, null));
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, null));
+ assertEquals(1, dnv0.compareNameVersion(null, dnv1));
+
+ dnv1.setName("name1");
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv0.setName("name0");
+ assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv1.setName("name0");
+ assertEquals(0, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv1.setVersion("4.5.6");
+ assertEquals(1, dnv0.compareNameVersion(dnv0, dnv1));
+
+ dnv0.setVersion("1.2.3");
+ 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
new file mode 100644
index 000000000..c3ccb4aa5
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import org.onap.policy.models.base.testconcepts.DummyPfObject;
+import org.onap.policy.models.base.testconcepts.DummyPfObjectFilter;
+
+/**
+ * Test the {@link PfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfObjectFilterTest {
+
+ @Test
+ public void testPfObjectInterface() {
+ DummyPfObject do0 = new DummyPfObject();
+ do0.setName("name0");
+ do0.setVersion("1.0.0");
+ do0.setDescription("desc0 ");
+
+ DummyPfObject do1 = new DummyPfObject();
+ do1.setName("name0");
+ do1.setVersion("0.0.1");
+ do1.setDescription("Desc 1");
+
+ DummyPfObject do2 = new DummyPfObject();
+ do2.setName("name0");
+ do2.setVersion("0.0.2");
+ do2.setDescription("Desc 1");
+
+ DummyPfObject do3 = new DummyPfObject();
+ do3.setName("name1");
+ do3.setVersion("0.0.1");
+ do3.setDescription("desc0 ");
+
+ DummyPfObject do4 = new DummyPfObject();
+ do4.setName("name1");
+ do4.setVersion("0.1.2");
+ do4.setDescription("Desc 1");
+
+ DummyPfObject do5 = new DummyPfObject();
+ do5.setName("aaaaa");
+ do5.setVersion("0.0.2");
+ do5.setDescription("Desc 1");
+
+ List<DummyPfObject> doList = new ArrayList<>();
+ doList.add(do0);
+ doList.add(do1);
+ doList.add(do2);
+ doList.add(do3);
+ doList.add(do4);
+ doList.add(do5);
+
+ DummyPfObjectFilter dof = new DummyPfObjectFilter();
+ assertFalse(dof.filterOnRegexp("Hello", "Goodbye"));
+ assertTrue(dof.filterOnRegexp("Hello", "Hello"));
+
+ assertThatThrownBy(() -> {
+ dof.filterOnRegexp(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");
+ }).hasMessage("value is marked @NonNull but is null");
+
+ List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList);
+ assertEquals(3, latestVersionList.size());
+ assertEquals("aaaaa", latestVersionList.get(0).getName());
+ assertEquals("0.0.2", latestVersionList.get(0).getVersion());
+ assertEquals("name0", latestVersionList.get(1).getName());
+ assertEquals("1.0.0", latestVersionList.get(1).getVersion());
+ assertEquals("name1", latestVersionList.get(2).getName());
+ assertEquals("0.1.2", latestVersionList.get(2).getVersion());
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java
new file mode 100644
index 000000000..23179d7de
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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 lombok.Data;
+
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy implementation of the {@link PfNameVersion} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+public class DummyPfNameVersion implements PfNameVersion {
+ public String name;
+ public String version;
+}
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
new file mode 100644
index 000000000..fcf4f7790
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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 lombok.Data;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Dummy object for filtering using the {@link DummyPfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@RequiredArgsConstructor
+public class DummyPfObject implements PfNameVersion, Comparable<DummyPfObject> {
+ 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/DummyPfObjectFilter.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java
new file mode 100644
index 000000000..a41c9dcdd
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectFilter.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.List;
+
+import lombok.Data;
+
+import org.onap.policy.models.base.PfObjectFilter;
+
+/**
+ * Dummy implementation of the {@link PfObjectFilter} interface.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+public class DummyPfObjectFilter implements PfObjectFilter<DummyPfObject> {
+ @Override
+ public List<DummyPfObject> filter(List<DummyPfObject> originalList) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}