Update css file name in conf.py
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / controller / PDPControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.policy.controller;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Set;
33
34 import javax.servlet.http.HttpServletRequest;
35
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.model.Roles;
42 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
43 import org.onap.policy.xacml.std.pap.StdPDPGroup;
44 import org.onap.policy.xacml.std.pap.StdPDPGroupStatus;
45 import org.springframework.mock.web.MockHttpServletResponse;
46
47 public class PDPControllerTest extends Mockito {
48
49     private static Logger logger = FlexLogger.getLogger(PDPControllerTest.class);
50     private Set<OnapPDPGroup> groupsData;
51     private Set<StdPDPGroup> groups;
52     private static List<Object> rolesdata;
53
54     /**
55      * Before.
56      *
57      * @throws Exception Exception
58      */
59     @Before
60     public void setUp() throws Exception {
61         logger.info("setUp: Entering");
62         rolesdata = new ArrayList<>();
63         Roles roles = new Roles();
64         roles.setLoginId("Test");
65         roles.setRole("super-admin");
66         Roles roles1 = new Roles();
67         roles1.setLoginId("Test");
68         roles1.setRole("admin");
69         roles1.setScope("['com','Test']");
70         rolesdata.add(roles);
71         rolesdata.add(roles1);
72
73         groups = new HashSet<>();
74         StdPDPGroup group = new StdPDPGroup();
75         group.setId("default");
76         group.setDefault(true);
77         group.setName("default");
78         group.setDescription("The default group where new PDP's are put.");
79         group.setStatus(new StdPDPGroupStatus());
80         groups.add(group);
81         groupsData = new HashSet<>();
82         for (OnapPDPGroup g : this.groups) {
83             groupsData.add(g);
84         }
85     }
86
87     @Test
88     public void testPdpGroupData() {
89         final HttpServletRequest request = mock(HttpServletRequest.class);
90         final MockHttpServletResponse response = new MockHttpServletResponse();
91         PolicyController controller = mock(PolicyController.class);
92         PDPController pdpController = new PDPController();
93         pdpController.setJunit(true);;
94         pdpController.setPolicyController(controller);
95         pdpController.setGroupsData(groupsData);
96         when(controller.getRoles("Test")).thenReturn(rolesdata);
97         pdpController.getPDPGroupEntityData(request, response);
98         try {
99             assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("data"));
100         } catch (UnsupportedEncodingException e) {
101             logger.error("Exception Occured" + e);
102         }
103     }
104
105     @Test
106     public void testPdpData() {
107         PdpData data = new PdpData();
108         data.setId("id");
109         assertEquals("id", data.getId());
110         data.setDescription("foo");
111         assertEquals("foo", data.getDescription());
112         data.setJmxPort(0);
113         assertEquals(0, data.getJmxPort());
114         data.setName("name");
115         assertEquals("name", data.getName());
116     }
117 }