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.*;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import java.io.BufferedReader;
27 import java.io.StringReader;
28 import java.io.UnsupportedEncodingException;
29 import java.util.ArrayList;
30 import java.util.List;
32 import javax.servlet.http.HttpServletRequest;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
37 import org.onap.policy.common.logging.flexlogger.Logger;
38 import org.onap.policy.rest.dao.CommonClassDao;
39 import org.onap.policy.rest.jpa.GlobalRoleSettings;
40 import org.springframework.mock.web.MockHttpServletResponse;
42 public class AdminTabControllerTest {
44 private static Logger logger = FlexLogger.getLogger(AdminTabControllerTest.class);
45 private static CommonClassDao commonClassDao;
46 private HttpServletRequest request;
47 private MockHttpServletResponse response;
50 public void setUp() throws Exception {
52 logger.info("setUp: Entering");
53 commonClassDao = mock(CommonClassDao.class);
55 request = mock(HttpServletRequest.class);
56 response = new MockHttpServletResponse();
58 AdminTabController.setCommonClassDao(commonClassDao);
60 GlobalRoleSettings globalRole = new GlobalRoleSettings();
61 globalRole.setLockdown(true);
62 globalRole.setRole("super-admin");
63 List<Object> globalRoles = new ArrayList<>();
64 globalRoles.add(globalRole);
65 when(commonClassDao.getData(GlobalRoleSettings.class)).thenReturn(globalRoles);
69 public void testGetAdminRole(){
70 AdminTabController admin = new AdminTabController();
72 admin.getAdminTabEntityData(request, response);
73 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("lockdowndata"));
74 } catch (UnsupportedEncodingException e) {
75 logger.error("Exception Occured"+e);
81 public void testSaveAdminRole() throws Exception{
82 AdminTabController admin = new AdminTabController();
83 String data = "{\"lockdowndata\":{\"lockdown\":true}}";
84 BufferedReader reader = new BufferedReader(new StringReader(data));
86 when(request.getReader()).thenReturn(reader);
87 admin.saveAdminTabLockdownValue(request, response);
88 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
89 } catch (UnsupportedEncodingException e) {
90 logger.error("Exception Occured"+e);