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