2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.policy.rest.util.PolicyContainer.ItemSetChangeListener;
30 import org.onap.policy.xacml.api.pap.OnapPDP;
31 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
32 import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
33 import com.att.research.xacml.api.pap.PAPException;
35 public class PDPGroupContainerTest {
36 private PAPPolicyEngine engine = Mockito.mock(PAPPolicyEngine.class);
37 private PDPGroupContainer container = new PDPGroupContainer(engine);
40 public void testContainer() throws PAPException {
41 Object itemId = new Object();
42 assertEquals(container.isSupported(itemId), false);
44 container.refreshGroups();
45 assertEquals(container.getGroups().size(), 0);
47 OnapPDPGroup group = Mockito.mock(OnapPDPGroup.class);
48 container.makeDefault(group);
49 OnapPDPGroup newGroup = Mockito.mock(OnapPDPGroup.class);
50 container.removeGroup(group, newGroup);
51 OnapPDP pdp = Mockito.mock(OnapPDP.class);
52 container.updatePDP(pdp);
53 container.updateGroup(group);
54 assertNull(container.getContainerPropertyIds());
55 assertEquals(container.getItemIds().size(), 0);
56 assertEquals(container.getType(itemId), null);
57 assertEquals(container.size(), 0);
58 assertEquals(container.containsId(itemId), false);
59 String name = "testName";
60 String description = "testDescription";
61 container.addNewGroup(name, description);
64 container.addNewPDP(id, newGroup, name, description, jmxport);
65 container.movePDP(pdp, newGroup);
66 ItemSetChangeListener listener = null;
67 container.addItemSetChangeListener(listener);
68 container.nextItemId(itemId);
69 container.prevItemId(itemId);
70 container.firstItemId();
71 container.lastItemId();
72 container.isFirstId(itemId);
73 container.isLastId(itemId);
74 container.indexOfId(itemId);
75 assertEquals(container.getItemIds().size(), 0);
76 container.removeItem(itemId);
77 container.removePDP(pdp, newGroup);
80 @Test(expected = UnsupportedOperationException.class)
81 public void testAddItem() {
85 @Test(expected = UnsupportedOperationException.class)
86 public void testAddContainerProperty() {
87 container.addContainerProperty(null, null, null);
90 @Test(expected = UnsupportedOperationException.class)
91 public void testRemoveContainerProperty() {
92 container.removeContainerProperty(null);
95 @Test(expected = UnsupportedOperationException.class)
96 public void testRemoveAllItems() {
97 container.removeAllItems();
100 @Test(expected = UnsupportedOperationException.class)
101 public void testAddItemAfter() {
102 container.addItemAfter(null);
105 @Test(expected = IndexOutOfBoundsException.class)
106 public void testGetIdByIndex() {
107 container.getIdByIndex(0);
110 @Test(expected = UnsupportedOperationException.class)
111 public void testAddItemAt() {
112 container.addItemAt(0);
115 @Test(expected = IllegalArgumentException.class)
116 public void testGetItemIds() {
117 container.getItemIds(0, 1);