2 * ============LICENSE_START=======================================================
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
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.controller;
25 import static org.junit.Assert.assertTrue;
27 import java.io.UnsupportedEncodingException;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
33 import javax.servlet.http.HttpServletRequest;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.onap.policy.common.logging.flexlogger.FlexLogger;
39 import org.onap.policy.common.logging.flexlogger.Logger;
40 import org.onap.policy.model.Roles;
41 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
42 import org.onap.policy.xacml.std.pap.StdPDPGroup;
43 import org.onap.policy.xacml.std.pap.StdPDPGroupStatus;
44 import org.springframework.mock.web.MockHttpServletResponse;
46 public class PDPControllerTest extends Mockito {
48 private static Logger logger = FlexLogger.getLogger(PDPControllerTest.class);
49 private Set<OnapPDPGroup> groupsData;
50 private Set<StdPDPGroup> groups;
51 private static List<Object> rolesdata;
54 public void setUp() throws Exception {
55 logger.info("setUp: Entering");
56 rolesdata = new ArrayList<>();
57 Roles roles = new Roles();
58 roles.setLoginId("Test");
59 roles.setRole("super-admin");
60 Roles roles1 = new Roles();
61 roles1.setLoginId("Test");
62 roles1.setRole("admin");
63 roles1.setScope("['com','Test']");
65 rolesdata.add(roles1);
67 groups = new HashSet<>();
68 StdPDPGroup group = new StdPDPGroup();
69 group.setId("default");
70 group.setDefault(true);
71 group.setName("default");
72 group.setDescription("The default group where new PDP's are put.");
73 group.setStatus(new StdPDPGroupStatus());
75 groupsData = new HashSet<>();
76 for (OnapPDPGroup g : this.groups) {
82 public void testPDPGroupData() {
83 HttpServletRequest request = mock(HttpServletRequest.class);
84 MockHttpServletResponse response = new MockHttpServletResponse();
85 PolicyController controller = mock(PolicyController.class);
86 PDPController pdpController = new PDPController();
87 pdpController.setJunit(true);;
88 pdpController.setPolicyController(controller);
89 pdpController.setGroupsData(groupsData);
90 when(controller.getRoles("Test")).thenReturn(rolesdata);
91 pdpController.getPDPGroupEntityData(request, response);
93 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("data"));
94 } catch (UnsupportedEncodingException e) {
95 logger.error("Exception Occured" + e);