2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.model;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
28 import com.att.research.xacml.api.pap.PAPException;
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 PAPPolicyEngine engine = Mockito.mock(PAPPolicyEngine.class);
39 private PDPGroupContainer container = new PDPGroupContainer(engine);
42 public void testContainer() throws PAPException {
43 Object itemId = new Object();
44 assertEquals(container.isSupported(itemId), false);
46 container.refreshGroups();
47 assertEquals(container.getGroups().size(), 0);
49 OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
50 container.makeDefault(group);
51 OnapPDPGroup newGroup = Mockito.mock(OnapPDPGroup.class);
52 container.removeGroup(group, newGroup);
53 OnapPDP pdp = Mockito.mock(OnapPDP.class);
54 container.updatePDP(pdp);
55 container.updateGroup(group);
56 assertNull(container.getContainerPropertyIds());
57 assertEquals(container.getItemIds().size(), 0);
58 assertEquals(container.getType(itemId), null);
59 assertEquals(container.size(), 0);
60 assertEquals(container.containsId(itemId), false);
61 String name = "testName";
62 String description = "testDescription";
63 container.addNewGroup(name, description);
66 container.addNewPDP(id, newGroup, name, description, jmxport);
67 container.movePDP(pdp, newGroup);
68 ItemSetChangeListener listener = null;
69 container.addItemSetChangeListener(listener);
70 container.nextItemId(itemId);
71 container.prevItemId(itemId);
72 container.firstItemId();
73 container.lastItemId();
74 container.isFirstId(itemId);
75 container.isLastId(itemId);
76 container.indexOfId(itemId);
77 assertEquals(container.getItemIds().size(), 0);
78 container.removeItem(itemId);
79 container.removePDP(pdp, newGroup);
82 @Test(expected = UnsupportedOperationException.class)
83 public void testAddItem() {
87 @Test(expected = UnsupportedOperationException.class)
88 public void testAddContainerProperty() {
89 container.addContainerProperty(null, null, null);
92 @Test(expected = UnsupportedOperationException.class)
93 public void testRemoveContainerProperty() {
94 container.removeContainerProperty(null);
97 @Test(expected = UnsupportedOperationException.class)
98 public void testRemoveAllItems() {
99 container.removeAllItems();
102 @Test(expected = UnsupportedOperationException.class)
103 public void testAddItemAfter() {
104 container.addItemAfter(null);
107 @Test(expected = IndexOutOfBoundsException.class)
108 public void testGetIdByIndex() {
109 container.getIdByIndex(0);
112 @Test(expected = UnsupportedOperationException.class)
113 public void testAddItemAt() {
114 container.addItemAt(0);
117 @Test(expected = IllegalArgumentException.class)
118 public void testGetItemIds() {
119 container.getItemIds(0, 1);