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============================================
38 package org.onap.portalapp.controller.core;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
43 import javax.servlet.http.HttpServletRequest;
44 import javax.servlet.http.HttpServletResponse;
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;
67 import com.fasterxml.jackson.databind.ObjectMapper;
69 @RunWith(PowerMockRunner.class)
70 @PrepareForTest({PortalApiProperties.class, PortalApiConstants.class, PortalApiConstants.class,RequestContextHolder.class})
71 public class LogoutControllerTest {
74 LogoutController logoutController = new LogoutController();
77 AppService appService;
80 UebManager uebManager;
84 MockitoAnnotations.initMocks(this);
87 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
89 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
90 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
92 NullPointerException nullPointerException = new NullPointerException();
94 User user = new User();
97 UserUtils userUtils = new UserUtils();
100 ObjectMapper mapper = new ObjectMapper();
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);
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));
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());
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));
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());