aboutsummaryrefslogtreecommitdiffstats
path: root/models-pap/src/test/java
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/test/java
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/test/java')
-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
4 files changed, 190 insertions, 9 deletions
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);
}
}