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.assertEquals;
26 import static org.junit.Assert.assertTrue;
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.HashSet;
31 import java.util.List;
34 import javax.servlet.http.HttpServletRequest;
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;
47 public class PDPControllerTest extends Mockito {
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;
57 * @throws Exception Exception
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']");
71 rolesdata.add(roles1);
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());
81 groupsData = new HashSet<>();
82 for (OnapPDPGroup g : this.groups) {
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);
99 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("data"));
100 } catch (UnsupportedEncodingException e) {
101 logger.error("Exception Occured" + e);
106 public void testPdpData() {
107 PdpData data = new PdpData();
109 assertEquals("id", data.getId());
110 data.setDescription("foo");
111 assertEquals("foo", data.getDescription());
113 assertEquals(0, data.getJmxPort());
114 data.setName("name");
115 assertEquals("name", data.getName());