2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.model;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.Mockito.doThrow;
27 import com.att.research.xacml.api.pap.PAPException;
28 import java.awt.Checkbox;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeListener;
33 import org.onap.policy.xacml.api.pap.OnapPDP;
34 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
35 import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
37 public class PDPGroupContainerTest {
38 private OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
39 private OnapPDPGroup newGroup = Mockito.mock(OnapPDPGroup.class);
40 private OnapPDP pdp = Mockito.mock(OnapPDP.class);
41 private PAPPolicyEngine engine = Mockito.mock(PAPPolicyEngine.class);
42 private PDPGroupContainer container = new PDPGroupContainer(engine);
45 public void testContainer() throws PAPException {
46 Object itemId = new Object();
47 assertEquals(container.isSupported(itemId), false);
49 container.refreshGroups();
50 assertEquals(container.getGroups().size(), 0);
52 container.makeDefault(group);
53 container.removeGroup(group, newGroup);
54 container.updatePDP(pdp);
55 container.updateGroup(group);
56 container.updateGroup(group, "testUserName");
57 assertNull(container.getContainerPropertyIds());
58 assertEquals(container.getItemIds().size(), 0);
59 assertEquals(container.getType(itemId), null);
60 assertEquals(container.size(), 0);
61 assertEquals(container.containsId(itemId), false);
62 String name = "testName";
63 String description = "testDescription";
64 container.addNewGroup(name, description);
67 container.addNewPDP(id, newGroup, name, description, jmxport);
68 container.movePDP(pdp, newGroup);
69 ItemSetChangeListener listener = null;
70 container.addItemSetChangeListener(listener);
71 container.nextItemId(itemId);
72 container.prevItemId(itemId);
73 container.firstItemId();
74 container.lastItemId();
75 container.isFirstId(itemId);
76 container.isLastId(itemId);
77 container.indexOfId(itemId);
78 assertEquals(container.getItemIds().size(), 0);
79 container.removeItem(itemId);
80 container.removePDP(pdp, newGroup);
83 @Test(expected = UnsupportedOperationException.class)
84 public void testAddItem() {
88 @Test(expected = UnsupportedOperationException.class)
89 public void testAddContainerProperty() {
90 container.addContainerProperty(null, null, null);
93 @Test(expected = UnsupportedOperationException.class)
94 public void testRemoveContainerProperty() {
95 container.removeContainerProperty(null);
98 @Test(expected = UnsupportedOperationException.class)
99 public void testRemoveAllItems() {
100 container.removeAllItems();
103 @Test(expected = UnsupportedOperationException.class)
104 public void testAddItemAfter() {
105 container.addItemAfter(null);
108 @Test(expected = IndexOutOfBoundsException.class)
109 public void testGetIdByIndex() {
110 container.getIdByIndex(0);
113 @Test(expected = UnsupportedOperationException.class)
114 public void testAddItemAt() {
115 container.addItemAt(0);
118 @Test(expected = IllegalArgumentException.class)
119 public void testGetItemIds() {
120 container.getItemIds(0, 1);
124 public void testGetType() {
125 assertEquals(Boolean.class, container.getType("Default"));
126 assertEquals(Checkbox.class, container.getType("Selected"));
127 assertEquals(Set.class, container.getType("PDPs"));
128 assertEquals(Set.class, container.getType("Policies"));
129 assertEquals(Set.class, container.getType("PIP Configurations"));
130 assertEquals(String.class, container.getType("Id"));
131 assertEquals(String.class, container.getType("Name"));
132 assertEquals(String.class, container.getType("Description"));
133 assertEquals(String.class, container.getType("Status"));
137 public void testContainerPAPExceptions() throws PAPException {
138 doThrow(PAPException.class).when(engine).getOnapPDPGroups();
139 container.refreshGroups();
141 doThrow(PAPException.class).when(engine).setDefaultGroup(group);
142 container.makeDefault(group);
144 doThrow(PAPException.class).when(engine).updatePDP(pdp);
145 container.updatePDP(pdp);
147 doThrow(PAPException.class).when(engine).updateGroup(group);
148 container.updateGroup(group);
150 doThrow(PAPException.class).when(engine).updateGroup(group, "testUserName");
151 container.updateGroup(group, "testUserName");
153 doThrow(PAPException.class).when(engine).movePDP(pdp, group);
154 container.movePDP(pdp, group);
157 @Test(expected = PAPException.class)
158 public void testContainerRemoveGroup() throws PAPException {
159 doThrow(PAPException.class).when(engine).removeGroup(group, newGroup);
160 container.removeGroup(group, newGroup);
163 @Test(expected = PAPException.class)
164 public void testContainerRemovePDP() throws PAPException {
165 doThrow(PAPException.class).when(engine).removePDP(pdp);
166 container.removePDP(pdp, group);