2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software 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.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.controller;
40 import static org.junit.Assert.assertEquals;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
45 import org.junit.Before;
46 import org.junit.Test;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.Mockito;
50 import org.mockito.MockitoAnnotations;
51 import org.openecomp.portalapp.controller.core.RoleController;
52 import org.openecomp.portalapp.controller.core.RoleFunctionListController;
53 import org.openecomp.portalapp.controller.core.RoleListController;
54 import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
55 import org.openecomp.portalapp.portal.controller.RoleManageController;
56 import org.openecomp.portalapp.portal.core.MockEPUser;
57 import org.openecomp.portalapp.portal.domain.EPApp;
58 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
59 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
60 import org.openecomp.portalapp.portal.service.ExternalAccessRolesService;
61 import org.springframework.web.servlet.ModelAndView;
63 public class RoleManageControllerTest {
68 RoleController roleController;
71 RoleListController roleListController;
74 RoleFunctionListController roleFunctionListController;
78 ExternalAccessRolesService externalAccessRolesService;
81 ExternalAccessRolesService externalAccessRolesService1 = null;
84 RoleManageController roleManageController = new RoleManageController();
88 MockitoAnnotations.initMocks(this);
92 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
94 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
95 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
96 NullPointerException nullPointerException = new NullPointerException();
97 MockEPUser mockUser = new MockEPUser();
100 public void toggleRoleTest()
102 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<String>();
103 portalRestResponse.setMessage("success");
104 portalRestResponse.setResponse(null);
105 PortalRestStatusEnum portalRestStatusEnum = null;
106 portalRestResponse.setStatus(portalRestStatusEnum.OK);
108 PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse);
109 assertEquals(portalRestResponse,expectedpPortalRestResponse);
114 // public void toggleRoleExceptionTest()
116 // PortalRestResponse<String> portalRestResponse = new PortalRestResponse<String>();
117 // portalRestResponse.setMessage("success");
118 // portalRestResponse.setResponse(null);
119 // PortalRestStatusEnum portalRestStatusEnum = null;
120 // portalRestResponse.setStatus(portalRestStatusEnum.OK);
121 // Mockito.doNothing().when(roleListController).toggleRole(mockedRequest, mockedResponse))).th
122 // getRoleListController().toggleRole(request, response)
124 // PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse);
125 // assertEquals(portalRestResponse,expectedpPortalRestResponse);
129 public void removeRoleTest() throws Exception
131 ModelAndView modelandView = new ModelAndView("login.htm");
132 Mockito.when(roleListController.removeRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
133 ModelAndView expectedModelandView = roleManageController.removeRole(mockedRequest, mockedResponse);
134 assertEquals(expectedModelandView, modelandView);
138 public void saveRoleTest() throws Exception
140 ModelAndView modelandView = new ModelAndView("login.htm");
141 Mockito.when(roleController.saveRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
142 ModelAndView expectedModelandView = roleManageController.saveRole(mockedRequest, mockedResponse);
143 assertEquals(expectedModelandView, modelandView);
147 public void removeRoleRoleFunctionTest() throws Exception
149 ModelAndView modelandView = new ModelAndView("login.htm");
150 Mockito.when(roleController.removeRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
151 ModelAndView expectedModelandView = roleManageController.removeRoleRoleFunction(mockedRequest, mockedResponse);
152 assertEquals(expectedModelandView, modelandView);
156 public void addRoleRoRoleFunctionTest() throws Exception
158 ModelAndView modelandView = new ModelAndView("login.htm");
159 Mockito.when(roleController.addRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
160 ModelAndView expectedModelandView = roleManageController.addRoleRoRoleFunction(mockedRequest, mockedResponse);
161 assertEquals(expectedModelandView, modelandView);
165 public void removeChildRoleTest() throws Exception
167 ModelAndView modelandView = new ModelAndView("login.htm");
168 Mockito.when(roleController.removeChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
169 ModelAndView expectedModelandView = roleManageController.removeChildRole(mockedRequest, mockedResponse);
170 assertEquals(expectedModelandView, modelandView);
175 public void getRoleTest() throws Exception
177 Mockito.doNothing().when(roleController).getRole(mockedRequest, mockedResponse);
178 roleManageController.getRole(mockedRequest, mockedResponse);
182 public void getRolesTest() throws Exception
184 Mockito.doNothing().when(roleListController).getRoles(mockedRequest, mockedResponse);
185 roleManageController.getRoles(mockedRequest, mockedResponse);
189 public void getRoleFunctionListTest() throws Exception
191 Mockito.doNothing().when(roleFunctionListController).getRoleFunctionList(mockedRequest, mockedResponse);
192 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse);
196 public void saveRoleFunctionTest() throws Exception
198 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
199 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, "test");
203 public void removeRoleFunctionTest() throws Exception
205 Mockito.doNothing().when(roleFunctionListController).removeRoleFunction(mockedRequest, mockedResponse, "test");
206 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, "test");
210 public void syncRolesTest() throws Exception
212 EPApp app = new EPApp();
213 Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
214 roleManageController.syncRoles(app);
219 public void addeChildRoleTest() throws Exception
221 ModelAndView modelandView = new ModelAndView("login.htm");
222 Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
223 ModelAndView expectedModelandView = roleManageController.addChildRole(mockedRequest, mockedResponse);
224 assertEquals(expectedModelandView, modelandView);