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.openecomp.policy.controller;
22 import static org.junit.Assert.assertTrue;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
26 import java.io.UnsupportedEncodingException;
27 import java.util.ArrayList;
28 import java.util.List;
30 import javax.servlet.http.HttpServletRequest;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
35 import org.openecomp.policy.common.logging.flexlogger.Logger;
36 import org.openecomp.policy.rest.dao.CommonClassDao;
37 import org.openecomp.policy.rest.jpa.GlobalRoleSettings;
38 import org.springframework.mock.web.MockHttpServletResponse;
40 public class AdminTabControllerTest {
42 private static Logger logger = FlexLogger.getLogger(AdminTabControllerTest.class);
43 private static CommonClassDao commonClassDao;
46 public void setUp() throws Exception {
48 logger.info("setUp: Entering");
49 commonClassDao = mock(CommonClassDao.class);
50 GlobalRoleSettings globalRole = new GlobalRoleSettings();
51 globalRole.setLockdown(true);
52 globalRole.setRole("super-admin");
53 List<Object> globalRoles = new ArrayList<>();
54 globalRoles.add(globalRole);
55 when(commonClassDao.getData(GlobalRoleSettings.class)).thenReturn(globalRoles);
59 public void testGetAdminRole(){
60 HttpServletRequest request = mock(HttpServletRequest.class);
61 MockHttpServletResponse response = new MockHttpServletResponse();
63 AdminTabController admin = new AdminTabController();
64 AdminTabController.setCommonClassDao(commonClassDao);
65 admin.getAdminTabEntityData(request, response);
68 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("lockdowndata"));
69 } catch (UnsupportedEncodingException e) {
70 logger.error("Exception Occured"+e);