aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-REST
diff options
context:
space:
mode:
authorbobbymander <bobby.mander@att.com>2018-03-21 07:39:40 -0400
committerbobbymander <bobby.mander@att.com>2018-03-21 07:41:14 -0400
commit14c29a339a48f456d951e1e0b3aae7e89b37c18c (patch)
treef18473d67af90596be8c9d9cbf2354ba217f5939 /ONAP-REST
parent82b62ca5dd3ae30aab7999b5959e1c07eb1d3d1f (diff)
JUnit additions for PAP-REST,REST,Utils
Issue-ID: POLICY-600 Change-Id: I9a432f9e8af43184d116d5eeb2fbbac65472564e Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-REST')
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java54
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java165
2 files changed, 160 insertions, 59 deletions
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java
new file mode 100644
index 000000000..0cd89a40e
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/dao/PolicyDBExceptionTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * PolicyEngineUtils
+ * ================================================================================
+ * Copyright (C) 2018 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.rest.dao;
+
+import java.io.IOException;
+import org.junit.Test;
+
+public class PolicyDBExceptionTest {
+ @Test(expected = PolicyDBException.class)
+ public void testException1() throws PolicyDBException {
+ throw new PolicyDBException();
+ }
+
+ @Test(expected = PolicyDBException.class)
+ public void testException2() throws PolicyDBException {
+ throw new PolicyDBException("test");
+ }
+
+ @Test(expected = PolicyDBException.class)
+ public void testException3() throws PolicyDBException {
+ Throwable cause = new IOException();
+ throw new PolicyDBException(cause);
+ }
+
+ @Test(expected = PolicyDBException.class)
+ public void testException4() throws PolicyDBException {
+ Throwable cause = new IOException();
+ throw new PolicyDBException("test", cause);
+ }
+
+ @Test(expected = PolicyDBException.class)
+ public void testException5() throws PolicyDBException {
+ Throwable cause = new IOException();
+ throw new PolicyDBException("test", cause, true, true);
+ }
+}
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java
index 806816b12..457df7062 100644
--- a/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/util/PDPPolicyContainerTest.java
@@ -19,73 +19,120 @@
*/
package org.onap.policy.rest.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-
import java.util.HashSet;
-
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.rest.util.PDPPolicyContainer.PDPPolicyItem;
+import org.onap.policy.xacml.std.pap.StdPDP;
import org.onap.policy.xacml.std.pap.StdPDPGroup;
import org.onap.policy.xacml.std.pap.StdPDPPolicy;
-
+import com.att.research.xacml.api.pap.PDP;
import com.att.research.xacml.api.pap.PDPPolicy;
public class PDPPolicyContainerTest {
-
- StdPDPGroup group;
- PDPPolicyContainer container;
- StdPDPPolicy policy;
-
- @Before
- public void setUp(){
- group = new StdPDPGroup();
- group.setDefault(true);
- group.setDefaultGroup(true);
- group.setDescription("Test");
- group.setId("Test");
- group.setName("Test");
- group.setOnapPdps(new HashSet<>());
- group.setOperation("Test");
- group.setPipConfigs(new HashSet<>());
- HashSet<PDPPolicy> policies = new HashSet<>();
- policy = new StdPDPPolicy();
- policy.setName("Config_test.1.xml");
- policy.setId("Config_test");
- policies.add(policy);
- group.setPolicies(policies);
- group.setSelectedPolicies(new HashSet<>());
- container = new PDPPolicyContainer(group);
- }
+ StdPDPGroup group;
+ PDPPolicyContainer container;
+ StdPDPPolicy policy;
+
+ @Before
+ public void setUp() {
+ group = new StdPDPGroup();
+ group.setDefault(true);
+ group.setDefaultGroup(true);
+ group.setDescription("Test");
+ group.setId("Test");
+ group.setName("Test");
+ group.setOnapPdps(new HashSet<>());
+ group.setOperation("Test");
+ group.setPipConfigs(new HashSet<>());
+ HashSet<PDPPolicy> policies = new HashSet<>();
+ policy = new StdPDPPolicy();
+ policy.setName("Config_test.1.xml");
+ policy.setId("Config_test");
+ policy.setVersion("1.0");
+ policy.setDescription("testDescription");
+ policies.add(policy);
+ group.setPolicies(policies);
+ group.setSelectedPolicies(new HashSet<>());
+ container = new PDPPolicyContainer(group);
+ }
+
+ @Test
+ public void testPDPPolicyContainer() {
+ container.nextItemId(policy);
+ container.prevItemId(policy);
+ container.firstItemId();
+ container.lastItemId();
+ container.isFirstId(policy);
+ container.isLastId(policy);
+ container.addItemAfter(policy);
+ container.getContainerPropertyIds();
+ container.getItemIds();
+ container.getType("Id");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Name");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Version");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Description");
+ assertTrue(String.class.equals(String.class));
+ container.getType("Root");
+ assertTrue(Boolean.class.equals(Boolean.class));
+ assertTrue(container.size() == 1);
+ container.containsId(policy);
+ container.removeItem(policy);
+ container.addContainerProperty(null, null, null);
+ container.removeContainerProperty(policy);
+ container.removeAllItems();
+ container.addItemAt(0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testConstructor() {
+ // Test PDP based constructor
+ PDP pdp = new StdPDP();
+ PDPPolicyContainer container1 = new PDPPolicyContainer(pdp);
+ assertNotNull(container1);
+
+ // Test set based constructor
+ Set<PDPPolicy> set = new HashSet<PDPPolicy>();
+ PDPPolicyContainer container2 = new PDPPolicyContainer(set);
+ assertNotNull(container2);
+
+ // Test object based constructor
+ PDPPolicyContainer container3 = new PDPPolicyContainer("testObject");
+ assertNotNull(container3);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void testAddItem() {
+ container.addItem();
+ }
+
+ @Test
+ public void testGetters() {
+ assertNull(container.nextItemId("testItem"));
+ assertNull(container.prevItemId("testItem"));
+ assertNotNull(container.firstItemId());
+ assertNotNull(container.lastItemId());
+ assertEquals(container.indexOfId("testItem"), -1);
+ assertNotNull(container.getIdByIndex(0));
+ assertNotNull(container.getItemIds(0, 1));
+ }
-
- @Test
- public void testPDPPolicyContainer(){
- container.nextItemId(policy);
- container.prevItemId(policy);
- container.firstItemId();
- container.lastItemId();
- container.isFirstId(policy);
- container.isLastId(policy);
- container.addItemAfter(policy);
- container.getContainerPropertyIds();
- container.getItemIds();
- container.getType("Id");
- assertTrue(String.class.equals(String.class));
- container.getType("Name");
- assertTrue(String.class.equals(String.class));
- container.getType("Version");
- assertTrue(String.class.equals(String.class));
- container.getType("Description");
- assertTrue(String.class.equals(String.class));
- container.getType("Root");
- assertTrue(Boolean.class.equals(Boolean.class));
- assertTrue(container.size() == 1);
- container.containsId(policy);
- container.removeItem(policy);
- container.addContainerProperty(null, null, null);
- container.removeContainerProperty(policy);
- container.removeAllItems();
- container.addItemAt(0);
-
- }
+ @Test
+ public void testPDPPolicyItem() {
+ PDPPolicyItem item = container.new PDPPolicyItem(policy);
+ assertEquals(item.getId(), "Config_test");
+ assertEquals(item.getName(), "Config_test.1.xml");
+ assertEquals(item.getVersion(), "1.0");
+ assertEquals(item.getDescription(), "testDescription");
+ item.setRoot(true);
+ assertEquals(item.getRoot(), true);
+ }
}