Merge "Fix all bugs reported by Sonar in policy/engine"
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / model / PDPGroupContainerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.model;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeListener;
28 import org.onap.policy.xacml.api.pap.OnapPDP;
29 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
30 import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
31 import com.att.research.xacml.api.pap.PAPException;
32
33 public class PDPGroupContainerTest {
34         private PAPPolicyEngine engine = Mockito.mock(PAPPolicyEngine.class);
35         private PDPGroupContainer container = new PDPGroupContainer(engine);
36         
37         @Test
38         public void testContainer() throws PAPException {
39                 Object itemId = new Object();
40                 assertEquals(container.isSupported(itemId), false);
41                 
42                 container.refreshGroups();
43                 assertEquals(container.getGroups().size(), 0);
44                 
45                 OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
46                 container.makeDefault(group);
47                 OnapPDPGroup newGroup = Mockito.mock(OnapPDPGroup.class);
48                 container.removeGroup(group, newGroup);
49                 OnapPDP pdp = Mockito.mock(OnapPDP.class);
50                 container.updatePDP(pdp);
51                 container.updateGroup(group);
52                 assertNull(container.getContainerPropertyIds());
53                 assertEquals(container.getItemIds().size(), 0);
54                 assertEquals(container.getType(itemId), null);
55                 assertEquals(container.size(), 0);
56                 assertEquals(container.containsId(itemId), false);
57                 String name = "testName";
58                 String description = "testDescription";
59                 container.addNewGroup(name, description);
60                 String id = "testID";
61                 int jmxport = 0;
62                 container.addNewPDP(id, newGroup, name, description, jmxport);
63                 container.movePDP(pdp, newGroup);
64                 ItemSetChangeListener listener = null;
65                 container.addItemSetChangeListener(listener);
66                 container.nextItemId(itemId);
67                 container.prevItemId(itemId);
68                 container.firstItemId();
69                 container.lastItemId();
70                 container.isFirstId(itemId);
71                 container.isLastId(itemId);
72                 container.indexOfId(itemId);
73                 assertEquals(container.getItemIds().size(), 0);
74                 container.removeItem(itemId);
75                 container.removePDP(pdp, newGroup);
76         }
77
78         @Test(expected=UnsupportedOperationException.class)
79         public void testAddItem() {
80                 container.addItem();            
81         }
82         
83         @Test(expected=UnsupportedOperationException.class)
84         public void testAddContainerProperty() {
85                 container.addContainerProperty(null, null, null);
86         }
87
88         @Test(expected=UnsupportedOperationException.class)
89         public void testRemoveContainerProperty() {
90                 container.removeContainerProperty(null);
91         }
92
93         @Test(expected=UnsupportedOperationException.class)
94         public void testRemoveAllItems() {
95                 container.removeAllItems();
96         }
97
98         @Test(expected=UnsupportedOperationException.class)
99         public void testAddItemAfter() {
100                 container.addItemAfter(null);
101         }
102         
103         @Test(expected=IndexOutOfBoundsException.class)
104         public void testGetIdByIndex() {
105                 container.getIdByIndex(0);
106         }
107
108         @Test(expected=UnsupportedOperationException.class)
109         public void testAddItemAt() {
110                 container.addItemAt(0);
111         }
112
113         @Test(expected=IllegalArgumentException.class)
114         public void testGetItemIds() {
115                 container.getItemIds(0, 1);
116         }
117 }