summaryrefslogtreecommitdiffstats
path: root/models-pap/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2021-01-04 12:15:18 +0000
committerliamfallon <liam.fallon@est.tech>2021-01-06 14:20:06 +0000
commitf2b0318f53abf9f2345a5cdca74f3dd635aa9b60 (patch)
tree0a5d64add719e43596f95b9415db04257c037988 /models-pap/src
parent8ad3f95cdcec48b8315a5febfd4ec07bae7aabba (diff)
Changed identifiers to concept identifiers
The policy models tosca classes ToscaPolicyIdentifier and ToscaPolicyIdentifierOptVersion can be used to identify any TOSCA concept, not just TOSCA policies so they are renamed to ToscaConceptIdentifier and ToscaCinceptIdentifierOptVersion respectively. The class ToscaPolicyTypeIdentifier is redundant and is replaced by ToscaConceptIdentifier. Issue-ID: POLICY-2900 Change-Id: Id0a37c42ea4e74f07b47e1694c4f8291c35879c9 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pap/src')
-rw-r--r--models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java62
-rw-r--r--models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java37
-rw-r--r--models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java14
-rw-r--r--models-pap/src/test/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifierTest.java78
-rw-r--r--models-pap/src/test/java/org/onap/policy/models/pap/concepts/PdpDeployPoliciesTest.java90
-rw-r--r--models-pap/src/test/java/org/onap/policy/models/pap/concepts/PolicyStatusTest.java8
-rw-r--r--models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestModels.java23
-rw-r--r--models-pap/src/test/resources/json/PapPoliciesList.json16
-rw-r--r--models-pap/src/test/resources/json/PapPolicyIdentifier.json4
9 files changed, 306 insertions, 26 deletions
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java
new file mode 100644
index 000000000..7bd78a222
--- /dev/null
+++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifier.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2021 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.NonNull;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
+
+/**
+ * Policy identifier with an optional version; only the "name" is required.
+ *
+ * <p>Note that there are deliberately no setters or getters on this class, it is use purely for GSON serialization and
+ * deserializaiton
+ */
+public class PapPolicyIdentifier {
+ @NonNull
+ @ApiModelProperty(name = "policy-id")
+ @SerializedName("policy-id")
+ private String name;
+
+ @ApiModelProperty(name = "policy-version")
+ @SerializedName("policy-version")
+ private String version;
+
+ public PapPolicyIdentifier(final String name, final String version) {
+ this.name = name;
+ this.version = version;
+ }
+
+ public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifier identifier) {
+ this(identifier.getName(), identifier.getVersion());
+ }
+
+ public PapPolicyIdentifier(@NonNull final ToscaConceptIdentifierOptVersion identifier) {
+ this(identifier.getName(), identifier.getVersion());
+ }
+
+ public ToscaConceptIdentifierOptVersion getGenericIdentifier() {
+ return name == null ? new ToscaConceptIdentifierOptVersion()
+ : new ToscaConceptIdentifierOptVersion(name, version);
+ }
+}
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java
index 7bc8892f2..6ab41ddf8 100644
--- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java
+++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PdpDeployPolicies.java
@@ -1,8 +1,9 @@
-/*
+/*-
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,19 +22,35 @@
package org.onap.policy.models.pap.concepts;
import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
+import java.util.stream.Collectors;
import lombok.ToString;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
/**
- * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment
- * REST API. Only the "name" and "version" fields of a Policy are used, and only the
- * "name" field is actually required.
+ * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment REST API. Only the "name" and
+ * "version" fields of a Policy are used, and only the "name" field is actually required.
*/
-@Getter
-@Setter
@ToString
public class PdpDeployPolicies {
- private List<ToscaPolicyIdentifierOptVersion> policies;
+ private List<PapPolicyIdentifier> policies;
+
+ /**
+ * Get the identifiers of the policies on the list.
+ *
+ * @return The list of identifiers
+ */
+ public List<ToscaConceptIdentifierOptVersion> getPolicies() {
+ return policies == null ? null
+ : policies.stream().map(PapPolicyIdentifier::getGenericIdentifier).collect(Collectors.toList());
+ }
+
+ /**
+ * Set the identifiers of the policies on the list.
+ *
+ * @param policies The list of identifiers
+ */
+ public void setPolicies(final List<ToscaConceptIdentifierOptVersion> policies) {
+ this.policies =
+ policies == null ? null : policies.stream().map(PapPolicyIdentifier::new).collect(Collectors.toList());
+ }
}
diff --git a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java
index 427f168ea..b05af9204 100644
--- a/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java
+++ b/models-pap/src/main/java/org/onap/policy/models/pap/concepts/PolicyStatus.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +22,7 @@ package org.onap.policy.models.pap.concepts;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.NoArgsConstructor;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@Data
@NoArgsConstructor
@@ -66,18 +66,18 @@ public class PolicyStatus {
* @param policy policy identifier, from which the name and version are to be
* extracted
*/
- public PolicyStatus(ToscaPolicyTypeIdentifier policyType, ToscaPolicyIdentifier policy) {
+ public PolicyStatus(ToscaConceptIdentifier policyType, ToscaConceptIdentifier policy) {
this.policyTypeId = policyType.getName();
this.policyTypeVersion = policyType.getVersion();
this.policyId = policy.getName();
this.policyVersion = policy.getVersion();
}
- public ToscaPolicyTypeIdentifier getPolicyType() {
- return new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion);
+ public ToscaConceptIdentifier getPolicyType() {
+ return new ToscaConceptIdentifier(policyTypeId, policyTypeVersion);
}
- public ToscaPolicyIdentifier getPolicy() {
- return new ToscaPolicyIdentifier(policyId, policyVersion);
+ public ToscaConceptIdentifier getPolicy() {
+ return new ToscaConceptIdentifier(policyId, policyVersion);
}
}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifierTest.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifierTest.java
new file mode 100644
index 000000000..2ab315ddd
--- /dev/null
+++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PapPolicyIdentifierTest.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
+
+/**
+ * This only tests the methods that aren't already tested via TestModels.
+ */
+public class PapPolicyIdentifierTest {
+
+ @Test
+ public void testPapPolicyIdentifier() throws CoderException {
+ assertNotNull(new PapPolicyIdentifier("Name", "Version"));
+ assertNotNull(new PapPolicyIdentifier("Name", null));
+ assertNotNull(new PapPolicyIdentifier(null, null));
+
+ assertNotNull(new PapPolicyIdentifier(new ToscaConceptIdentifier("Name", "Version")));
+ assertNotNull(new PapPolicyIdentifier(new ToscaConceptIdentifierOptVersion("Name", "Version")));
+
+ assertThatThrownBy(() -> new PapPolicyIdentifier((ToscaConceptIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
+
+ assertThatThrownBy(() -> new PapPolicyIdentifier((ToscaConceptIdentifierOptVersion) null))
+ .isInstanceOf(NullPointerException.class);
+
+ PapPolicyIdentifier ppi = new PapPolicyIdentifier("myname", "1.2.3");
+
+ assertEquals("myname", ppi.getGenericIdentifier().getName());
+ assertEquals("1.2.3", ppi.getGenericIdentifier().getVersion());
+
+ PapPolicyIdentifier ppi2 = new PapPolicyIdentifier(null, null);
+ assertNull(ppi2.getGenericIdentifier().getName());
+ assertNull(ppi2.getGenericIdentifier().getVersion());
+ }
+
+ @Test
+ public void testPapPolicyIdentifierSerialization() throws CoderException, IOException {
+ String idString = TextFileUtils.getTextFileAsString("src/test/resources/json/PapPolicyIdentifier.json");
+
+ StandardCoder coder = new StandardCoder();
+
+ PapPolicyIdentifier ppi = coder.decode(idString, PapPolicyIdentifier.class);
+
+ assertEquals("MyPolicy", ppi.getGenericIdentifier().getName());
+ assertEquals("1.2.6", ppi.getGenericIdentifier().getVersion());
+
+ String idStringBack = coder.encode(ppi);
+ assertEquals(idString.replaceAll("\\s+", ""), idStringBack.replaceAll("\\s+", ""));
+ }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PdpDeployPoliciesTest.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PdpDeployPoliciesTest.java
new file mode 100644
index 000000000..3664cc39c
--- /dev/null
+++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PdpDeployPoliciesTest.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pap.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
+
+/**
+ * This only tests the methods that aren't already tested via TestModels.
+ */
+public class PdpDeployPoliciesTest {
+ @Test
+ public void testPapPolicyIdentifier() throws CoderException, IOException {
+ assertNotNull(new PdpDeployPolicies());
+
+ List<ToscaConceptIdentifierOptVersion> tciListIn = new ArrayList<>();
+
+ ToscaConceptIdentifierOptVersion tci0 = new ToscaConceptIdentifierOptVersion("MyPolicy0", "1.2.0");
+ tciListIn.add(tci0);
+ ToscaConceptIdentifierOptVersion tci1 = new ToscaConceptIdentifierOptVersion("MyPolicy1", "1.2.1");
+ tciListIn.add(tci1);
+ ToscaConceptIdentifierOptVersion tci2 = new ToscaConceptIdentifierOptVersion("MyPolicy2", "1.2.2");
+ tciListIn.add(tci2);
+
+ PdpDeployPolicies policies = new PdpDeployPolicies();
+ policies.setPolicies(null);
+ assertNull(policies.getPolicies());
+
+ policies.setPolicies(tciListIn);
+
+ assertEquals(3, policies.getPolicies().size());
+
+ assertEquals("MyPolicy0", policies.getPolicies().get(0).getName());
+ assertEquals("1.2.0", policies.getPolicies().get(0).getVersion());
+ assertEquals("MyPolicy1", policies.getPolicies().get(1).getName());
+ assertEquals("1.2.1", policies.getPolicies().get(1).getVersion());
+ assertEquals("MyPolicy2", policies.getPolicies().get(2).getName());
+ assertEquals("1.2.2", policies.getPolicies().get(2).getVersion());
+
+ List<ToscaConceptIdentifierOptVersion> tciListOut = policies.getPolicies();
+ assertEquals(tciListIn, tciListOut);
+ }
+
+ @Test
+ public void testPapPolicyIdentifierSerialization() throws CoderException, IOException {
+ String idListString = TextFileUtils.getTextFileAsString("src/test/resources/json/PapPoliciesList.json");
+
+ StandardCoder coder = new StandardCoder();
+
+ PdpDeployPolicies policies = coder.decode(idListString, PdpDeployPolicies.class);
+
+ assertEquals(3, policies.getPolicies().size());
+
+ assertEquals("MyPolicy0", policies.getPolicies().get(0).getName());
+ assertEquals("1.2.0", policies.getPolicies().get(0).getVersion());
+ assertEquals("MyPolicy1", policies.getPolicies().get(1).getName());
+ assertEquals("1.2.1", policies.getPolicies().get(1).getVersion());
+ assertEquals("MyPolicy2", policies.getPolicies().get(2).getName());
+ assertEquals("1.2.2", policies.getPolicies().get(2).getVersion());
+
+ String idListStringBack = coder.encode(policies);
+ assertEquals(idListString.replaceAll("\\s+", ""), idListStringBack.replaceAll("\\s+", ""));
+ }
+}
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PolicyStatusTest.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PolicyStatusTest.java
index 869bd1dbf..997c30414 100644
--- a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PolicyStatusTest.java
+++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/PolicyStatusTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +24,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* This only tests the methods that aren't already tested via TestModels.
@@ -33,8 +33,8 @@ public class PolicyStatusTest {
@Test
public void test() throws CoderException {
- ToscaPolicyTypeIdentifier type = new ToscaPolicyTypeIdentifier("my-type", "3.2.1");
- ToscaPolicyIdentifier policy = new ToscaPolicyIdentifier("my-name", "1.2.3");
+ ToscaConceptIdentifier type = new ToscaConceptIdentifier("my-type", "3.2.1");
+ ToscaConceptIdentifier policy = new ToscaConceptIdentifier("my-name", "1.2.3");
// test constructor with arguments
PolicyStatus status = new PolicyStatus(type, policy);
diff --git a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestModels.java b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestModels.java
index ae41a5c4f..1658ccbd0 100644
--- a/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestModels.java
+++ b/models-pap/src/test/java/org/onap/policy/models/pap/concepts/TestModels.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,13 @@
package org.onap.policy.models.pap.concepts;
-import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.impl.PojoClassFactory;
import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
+import java.util.List;
import org.junit.Test;
import org.onap.policy.common.utils.test.ToStringTester;
@@ -37,8 +39,19 @@ public class TestModels {
@Test
public void testPapModels() {
- final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
- .with(new GetterTester()).build();
- validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
+ List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(TestModels.class.getPackage().getName());
+
+ // @formatter:off
+ final Validator validator =
+ ValidatorBuilder.create()
+ .with(new ToStringTester())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+ // @formatter:on
+
+ pojoClasses.remove(PojoClassFactory.getPojoClass(PdpDeployPolicies.class));
+
+ validator.validate(pojoClasses);
}
}
diff --git a/models-pap/src/test/resources/json/PapPoliciesList.json b/models-pap/src/test/resources/json/PapPoliciesList.json
new file mode 100644
index 000000000..39f387ced
--- /dev/null
+++ b/models-pap/src/test/resources/json/PapPoliciesList.json
@@ -0,0 +1,16 @@
+{
+ "policies": [
+ {
+ "policy-id" : "MyPolicy0",
+ "policy-version": "1.2.0"
+ },
+ {
+ "policy-id" : "MyPolicy1",
+ "policy-version": "1.2.1"
+ },
+ {
+ "policy-id" : "MyPolicy2",
+ "policy-version": "1.2.2"
+ }
+ ]
+}
diff --git a/models-pap/src/test/resources/json/PapPolicyIdentifier.json b/models-pap/src/test/resources/json/PapPolicyIdentifier.json
new file mode 100644
index 000000000..36fa259ba
--- /dev/null
+++ b/models-pap/src/test/resources/json/PapPolicyIdentifier.json
@@ -0,0 +1,4 @@
+{
+ "policy-id" : "MyPolicy",
+ "policy-version": "1.2.6"
+} \ No newline at end of file