08cddd69451a9a708dede49888e3a459ca0d40f4
[portal.git] / ecomp-portal-BE-common / src / test / java / org / openecomp / portalapp / portal / controller / RoleManageControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.portal.controller;
39
40 import static org.junit.Assert.assertEquals;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44
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;
62
63 public class RoleManageControllerTest {
64
65         
66         
67         @Mock
68          RoleController roleController;
69
70         @Mock
71     RoleListController roleListController;
72
73         @Mock
74     RoleFunctionListController roleFunctionListController;
75
76
77         @Mock
78         ExternalAccessRolesService externalAccessRolesService;
79         
80         @Mock
81         ExternalAccessRolesService externalAccessRolesService1 = null;
82         
83         @InjectMocks
84         RoleManageController roleManageController = new RoleManageController(); 
85
86         @Before
87         public void setup() {
88                 MockitoAnnotations.initMocks(this);
89         }
90         
91         
92         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
93
94         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
95         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
96         NullPointerException nullPointerException = new NullPointerException();
97         MockEPUser mockUser = new MockEPUser();
98         
99         @Test
100         public void toggleRoleTest()
101         {
102                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<String>();
103                 portalRestResponse.setMessage("success");
104                 portalRestResponse.setResponse(null);
105                 PortalRestStatusEnum portalRestStatusEnum = null;
106                 portalRestResponse.setStatus(portalRestStatusEnum.OK);
107                 
108                 PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse);
109                 assertEquals(portalRestResponse,expectedpPortalRestResponse);
110                 
111         }
112         
113 //      @Test
114 //      public void toggleRoleExceptionTest()
115 //      {
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)
123 //              
124 //              PortalRestResponse<String> expectedpPortalRestResponse=roleManageController.toggleRole(mockedRequest, mockedResponse);
125 //              assertEquals(portalRestResponse,expectedpPortalRestResponse);
126 //              
127 //      }
128         @Test
129         public void removeRoleTest() throws Exception
130         {
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);
135         }
136         
137         @Test
138         public void saveRoleTest() throws Exception
139         {
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);
144         }
145         
146         @Test
147         public void removeRoleRoleFunctionTest() throws Exception
148         {
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);
153         }
154         
155         @Test
156         public void addRoleRoRoleFunctionTest() throws Exception
157         {
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);
162         }
163         
164         @Test
165         public void removeChildRoleTest() throws Exception
166         {
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);
171         }
172         
173         
174         @Test
175         public void getRoleTest() throws Exception
176         {
177                 Mockito.doNothing().when(roleController).getRole(mockedRequest, mockedResponse);
178                 roleManageController.getRole(mockedRequest, mockedResponse);
179         }
180         
181         @Test
182         public void getRolesTest() throws Exception
183         {
184                 Mockito.doNothing().when(roleListController).getRoles(mockedRequest, mockedResponse);
185                 roleManageController.getRoles(mockedRequest, mockedResponse);
186         }
187         
188         @Test
189         public void getRoleFunctionListTest() throws Exception
190         {
191                 Mockito.doNothing().when(roleFunctionListController).getRoleFunctionList(mockedRequest, mockedResponse);
192                 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse);
193         }
194         
195         @Test
196         public void saveRoleFunctionTest() throws Exception
197         {
198                 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
199                 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, "test");
200         }
201         
202         @Test
203         public void removeRoleFunctionTest() throws Exception
204         {
205                 Mockito.doNothing().when(roleFunctionListController).removeRoleFunction(mockedRequest, mockedResponse, "test");
206                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, "test");
207         }
208         
209         @Test
210         public void syncRolesTest() throws Exception
211         {
212                 EPApp app = new EPApp();
213                 Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
214                 roleManageController.syncRoles(app);
215         }
216         
217         
218         @Test
219         public void addeChildRoleTest() throws Exception
220         {
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);
225         }
226 }