summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'models-pdp/src/test/java')
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java77
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java52
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java75
3 files changed, 204 insertions, 0 deletions
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java
new file mode 100644
index 000000000..22c7a71ac
--- /dev/null
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java
@@ -0,0 +1,77 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpState;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpGroup {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class);
+
+ PdpGroup orig = new PdpGroup();
+
+ // verify with null values
+ assertEquals(orig.toString(), new PdpGroup(orig).toString());
+
+ // verify with all values
+ orig.setDescription("my-descript");
+ orig.getKey().setName("my-name");
+ orig.setPdpGroupState(PdpState.SAFE);
+
+ PdpSubGroup sub1 = new PdpSubGroup();
+ sub1.setCurrentInstanceCount(10);
+ PdpSubGroup sub2 = new PdpSubGroup();
+ sub2.setCurrentInstanceCount(11);
+ orig.setPdpSubgroups(Arrays.asList(sub1, sub2));
+
+ Map<String, String> props = new TreeMap<>();
+ props.put("key-A", "value-A");
+ props.put("key-B", "value-B");
+ orig.setProperties(props);
+
+ assertEquals(orig.toString(), new PdpGroup(orig).toString());
+ }
+
+ @Test
+ public void testHashCode() {
+ PdpGroup group = new PdpGroup();
+ group.setDescription("A");
+ int hash = group.hashCode();
+
+ assertEquals(hash, group.hashCode());
+
+ group.setDescription("B");
+ assertTrue(hash != group.hashCode());
+ }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java
new file mode 100644
index 000000000..2220ae126
--- /dev/null
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.models.pdp.enums.PdpHealthStatus;
+import org.onap.policy.models.pdp.enums.PdpState;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpInstanceDetails {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new PdpInstanceDetails(null)).isInstanceOf(NullPointerException.class);
+
+ PdpInstanceDetails orig = new PdpInstanceDetails();
+
+ // verify with null values
+ assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
+
+ // verify with all values
+ orig.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
+ orig.setInstanceId("my-instance");
+ orig.setMessage("my-message");
+ orig.setPdpState(PdpState.SAFE);
+
+ assertEquals(orig.toString(), new PdpInstanceDetails(orig).toString());
+ }
+}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
new file mode 100644
index 000000000..2a20d2f7b
--- /dev/null
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
@@ -0,0 +1,75 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Test;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+
+/**
+ * Test the copy constructor, as {@link TestModels} tests the other methods.
+ */
+public class TestPdpSubGroup {
+
+ @Test
+ public void testCopyConstructor() {
+ assertThatThrownBy(() -> new PdpSubGroup(null)).isInstanceOf(NullPointerException.class);
+
+ PdpSubGroup orig = new PdpSubGroup();
+
+ // verify with null values
+ assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
+
+ // verify with all values
+ orig.setCurrentInstanceCount(10);
+ orig.setDesiredInstanceCount(11);
+
+ PdpInstanceDetails inst1 = new PdpInstanceDetails();
+ inst1.setInstanceId("my-id-A");
+ PdpInstanceDetails inst2 = new PdpInstanceDetails();
+ inst2.setInstanceId("my-id-B");
+ orig.setPdpInstances(Arrays.asList(inst1, inst2));
+
+ orig.setPdpType("my-type");
+
+ ToscaPolicy pol1 = new ToscaPolicy();
+ pol1.setDescription("policy-A");
+ ToscaPolicy pol2 = new ToscaPolicy();
+ pol2.setDescription("policy-B");
+ orig.setPolicies(Arrays.asList(pol1, pol2));
+
+ Map<String, String> props = new TreeMap<>();
+ props.put("key-A", "value-A");
+ props.put("key-B", "value-B");
+ orig.setProperties(props);
+
+ PolicyTypeIdent supp1 = new PolicyTypeIdent("supp-A", "1.2");
+ PolicyTypeIdent supp2 = new PolicyTypeIdent("supp-B", "3.4");
+ orig.setSupportedPolicyTypes(Arrays.asList(supp1, supp2));
+
+ assertEquals(orig.toString(), new PdpSubGroup(orig).toString());
+ }
+}