aboutsummaryrefslogtreecommitdiffstats
path: root/models-base/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-11-20 10:24:44 +0000
committerliamfallon <liam.fallon@est.tech>2020-12-01 12:27:54 +0000
commit950cbb8872fb2227f4a0382a756a7e1dff53b09c (patch)
treece493c7161872360f4d88c5065c0730d53987c82 /models-base/src
parent1dd41890f83702d47c5a957493046433989ef36c (diff)
Add extra authorative TOSCA concepts
This review brings in extra TOSCA concepts for Node types, nodes, and capabilities. The TOSCA handling is also amended to make the handling of equality consistent. Now, if filtering or ordering is required using an order rather than natural ordering, a comparator must be supplied by the user. Issue-ID: POLICY-2900 Change-Id: Ie40e86870b97eb993b1338bdc0666ac116f72f67 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java34
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java10
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java35
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java10
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java6
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java3
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfNameVersionTest.java5
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java9
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObject.java17
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java35
12 files changed, 145 insertions, 27 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java
new file mode 100644
index 000000000..36bff5fbc
--- /dev/null
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptComparator.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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 java.util.Comparator;
+
+/**
+ * Compare two PfNameVersion objects.
+ */
+public class PfConceptComparator implements Comparator<PfConcept> {
+
+ @Override
+ public int compare(PfConcept left, PfConcept right) {
+ return left.getKey().compareTo(right.getKey());
+ }
+}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
index 8cebcdb40..df6141b9b 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -58,7 +58,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> {
// @formatter:off
if (LATEST_VERSION.equals(version)) {
- return this.latestVersionFilter(returnList);
+ return this.latestVersionFilter(returnList, new PfConceptComparator());
} else {
return returnList;
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java
index 7bdced77b..f9fde53e5 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfNameVersion.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public interface PfNameVersion {
public void setVersion(final String version);
/**
- * COmpare two name version implementation objects.
+ * Compare two name version implementation objects.
*
* @param left the left name/version implementation
* @param right the right name/version implementation
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 f4e457192..f7e29f1b4 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@ package org.onap.policy.models.base;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -34,7 +35,7 @@ import java.util.regex.Pattern;
* @author Liam Fallon (liam.fallon@est.tech)
*/
@FunctionalInterface
-public interface PfObjectFilter<T extends Comparable<T>> {
+public interface PfObjectFilter<T> {
/**
* Filter an incoming list, removing items that do not match the filter.
*
@@ -118,15 +119,16 @@ public interface PfObjectFilter<T extends Comparable<T>> {
* Sort an incoming list and remove all but the latest version of each concept.
*
* @param originalList the incoming list
+ * @param versionComparator the comparator to use to order versions of the incoming object
* @return the filtered list
*/
- public default List<T> latestVersionFilter(final List<T> originalList) {
+ public default List<T> latestVersionFilter(final List<T> originalList, final Comparator<T> versionComparator) {
if (originalList.size() <= 1) {
return originalList;
}
List<T> filteredList = new ArrayList<>(originalList);
- Collections.sort(filteredList);
+ Collections.sort(filteredList, versionComparator);
int icur = 0;
for (int j = 1; j < filteredList.size(); j++) {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java
new file mode 100644
index 000000000..ea0762711
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptComparatorTest.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.DummyBadPfConcept;
+import org.onap.policy.models.base.testconcepts.DummyPfConcept;
+
+public class PfConceptComparatorTest {
+
+ @Test
+ public void testPfConceptComparator() {
+ assertEquals(0, new PfConceptComparator().compare(new DummyPfConcept(), new DummyPfConcept()));
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java
index 424293f78..6d02b2fdd 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptFilterTest.java
@@ -21,6 +21,7 @@
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.assertTrue;
import java.util.ArrayList;
@@ -50,5 +51,14 @@ public class PfConceptFilterTest {
final PfConceptFilter conceptFilterNull = new PfConceptFilter(null, null, null);
conceptFilterNull.filter(null);
}).hasMessageMatching("^originalList is marked .*on.*ull but is null$");
+
+ conceptFilter.setName("hello");
+ assertEquals("hello", conceptFilter.getName());
+
+ conceptFilter.setVersion("1.2.3");
+ assertEquals("1.2.3", conceptFilter.getVersion());
+
+ conceptFilter.setVersionPrefix("AAA");
+ assertEquals("AAA", conceptFilter.getVersionPrefix());
}
}
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 7bf270b5f..8b94a48c3 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
@@ -145,6 +145,12 @@ public class PfKeyImplTest {
MyKey someKey8 = new MyKey();
someKey8.setVersion(VERSION001);
assertFalse(someKey8.isNullKey());
+
+ someKey8.setVersion("10");
+ assertEquals(0, someKey8.getMinorVersion());
+
+ someKey8.setVersion("10.11");
+ assertEquals(0, someKey8.getPatchVersion());
}
@Test
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java
index 2e742c336..5cebf1e91 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelExceptionInfoTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.models.base;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import javax.ws.rs.core.Response;
import org.junit.Test;
@@ -39,10 +40,12 @@ public class PfModelExceptionInfoTest {
final PfModelException pfme = new PfModelException(Response.Status.ACCEPTED, "HELLO");
assertThat(pfme).hasMessage("HELLO");
assertEquals("Server returned: Accepted", getErrorMessage(pfme).substring(0, 25));
+ assertNotNull(pfme.toString());
final PfModelRuntimeException pfmr = new PfModelRuntimeException(Response.Status.ACCEPTED, "HELLO");
assertThat(pfmr).hasMessage("HELLO");
assertEquals("Server returned: Accepted", getErrorMessage(pfmr).substring(0, 25));
+ assertNotNull(pfmr.toString());
}
private String getErrorMessage(final ErrorResponseInfo eri) {
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
index 7152b12f1..2937b60ab 100644
--- 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,6 +57,9 @@ public class PfNameVersionTest {
dnv0.setVersion("1.2.3");
assertEquals(-1, dnv0.compareNameVersion(dnv0, dnv1));
+ dnv1.setVersion(null);
+ 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
index d6985e949..59d7ad70e 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 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,12 +26,14 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import org.junit.Test;
import org.onap.policy.models.base.testconcepts.DummyPfObject;
+import org.onap.policy.models.base.testconcepts.DummyPfObjectComparator;
import org.onap.policy.models.base.testconcepts.DummyPfObjectFilter;
/**
@@ -96,7 +98,7 @@ public class PfObjectFilterTest {
assertEquals(true, dof.filterString(HELLO, HELLO));
assertEquals(true, dof.filterString(HELLO, null));
- List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList);
+ List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList, new DummyPfObjectComparator());
assertEquals(3, latestVersionList.size());
assertEquals("aaaaa", latestVersionList.get(0).getName());
assertEquals(VERSION002, latestVersionList.get(0).getVersion());
@@ -107,7 +109,8 @@ public class PfObjectFilterTest {
latestVersionList.remove(2);
latestVersionList.remove(1);
- List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList);
+ List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList,
+ new DummyPfObjectComparator());
assertEquals(latestVersionList, newestVersionList);
MyFilter filter = new MyFilter();
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
index 53009ddc8..9759f4aef 100644
--- 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,21 +33,8 @@ import org.onap.policy.models.base.PfNameVersion;
*/
@Data
@RequiredArgsConstructor
-public class DummyPfObject implements PfNameVersion, Comparable<DummyPfObject> {
+public class DummyPfObject implements PfNameVersion {
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/DummyPfObjectComparator.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java
new file mode 100644
index 000000000..f83bce6a6
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfObjectComparator.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.Comparator;
+import org.onap.policy.models.base.PfNameVersion;
+
+/**
+ * Compare two PfNameVersion objects.
+ */
+public class DummyPfObjectComparator implements Comparator<DummyPfObject> {
+
+ @Override
+ public int compare(final DummyPfObject left, final DummyPfObject right) {
+ return left.compareNameVersion(left, right);
+ }
+}