a6ffb0388c61e6c7be97ec5122a06ceb5591c163
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
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  * 
37  */
38 package org.onap.portalapp.controller.core;
39
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
42
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
45
46 import org.junit.Before;
47 import org.junit.Test;
48 import org.junit.runner.RunWith;
49 import org.mockito.InjectMocks;
50 import org.mockito.Mock;
51 import org.mockito.Mockito;
52 import org.mockito.MockitoAnnotations;
53 import org.onap.portalapp.framework.MockitoTestSuite;
54 import org.onap.portalsdk.core.domain.User;
55 import org.onap.portalsdk.core.onboarding.ueb.UebManager;
56 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
57 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
58 import org.onap.portalsdk.core.service.AppService;
59 import org.onap.portalsdk.core.web.support.UserUtils;
60 import org.powermock.api.mockito.PowerMockito;
61 import org.powermock.core.classloader.annotations.PrepareForTest;
62 import org.powermock.modules.junit4.PowerMockRunner;
63 import org.springframework.web.context.request.RequestContextHolder;
64 import org.springframework.web.context.request.ServletRequestAttributes;
65 import org.springframework.web.servlet.ModelAndView;
66
67 import com.fasterxml.jackson.databind.ObjectMapper;
68
69 @RunWith(PowerMockRunner.class)
70 @PrepareForTest({PortalApiProperties.class, PortalApiConstants.class, PortalApiConstants.class,RequestContextHolder.class})
71 public class LogoutControllerTest {
72
73         @InjectMocks
74         LogoutController logoutController = new LogoutController();
75         
76         @Mock
77         AppService appService;
78         
79         @Mock
80         UebManager uebManager;
81
82         @Before
83         public void setup() {
84                 MockitoAnnotations.initMocks(this);
85         }
86         
87         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
88         
89         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
90         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
91         
92         NullPointerException nullPointerException = new NullPointerException();
93         
94         User user = new User();
95         
96         @Mock
97         UserUtils userUtils = new UserUtils();
98          
99         @Mock
100         ObjectMapper mapper = new ObjectMapper();
101         
102         @Test
103         public void globalLogoutTest(){
104                 ModelAndView modelView = null;
105                 PowerMockito.mockStatic(PortalApiProperties.class);
106                 PowerMockito.mockStatic(PortalApiConstants.class);
107                 PowerMockito.mockStatic(RequestContextHolder.class);
108                 ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest);
109                 Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes);
110                 Mockito.when(PortalApiProperties
111                                                 .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp");
112                 logoutController.globalLogout(mockedRequest);
113         }
114         
115         @Test
116         public void globalLogoutExceptionTest(){
117                 PowerMockito.mockStatic(PortalApiProperties.class);
118                 PowerMockito.mockStatic(PortalApiConstants.class);
119                 Mockito.when(PortalApiProperties
120                                                 .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp");                
121                 assertNull(logoutController.globalLogout(mockedRequest));
122         }
123         
124         @Test
125         public void appLogoutTest(){
126                 ModelAndView actualModelView = new ModelAndView("redirect:https://portal.openecomp.org/ecompportal/process_csp");
127                 PowerMockito.mockStatic(PortalApiProperties.class);
128                 PowerMockito.mockStatic(PortalApiConstants.class);
129                 PowerMockito.mockStatic(RequestContextHolder.class);
130                 ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest);
131                 Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes);
132                 Mockito.when(PortalApiProperties
133                                                 .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp");                
134                 ModelAndView expectedModelView = logoutController.appLogout(mockedRequest);
135                 assertEquals(actualModelView.getViewName(), expectedModelView.getViewName());
136         }
137         
138         @Test
139         public void appLogoutExceptionTest(){
140                 PowerMockito.mockStatic(PortalApiProperties.class);
141                 PowerMockito.mockStatic(PortalApiConstants.class);
142                 Mockito.when(PortalApiProperties
143                                                 .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp");                
144                 assertNull(logoutController.appLogout(mockedRequest));
145         }
146         
147         @Test
148         public void getUserTest(){
149                 User expectedUser = new User();
150                 expectedUser.setActive(false);
151                 user.setActive(false);
152                 logoutController.setUser(user);
153                 User actualUser = logoutController.getUser();
154                 assertEquals(expectedUser.getActive(), actualUser.getActive());
155         }
156 }