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.onap.portalapp.controller.core;
40 import static org.junit.Assert.assertEquals;
42 import java.io.IOException;
43 import java.io.PrintWriter;
44 import java.io.StringWriter;
45 import java.util.ArrayList;
46 import java.util.List;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.mockito.InjectMocks;
54 import org.mockito.Mock;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalapp.framework.MockitoTestSuite;
58 import org.onap.portalsdk.core.domain.User;
59 import org.onap.portalsdk.core.restful.client.SharedContextRestClient;
60 import org.onap.portalsdk.core.service.RoleService;
61 import org.onap.portalsdk.core.service.UserProfileService;
62 import org.onap.portalsdk.core.service.UserService;
63 import org.onap.portalsdk.core.web.support.UserUtils;
64 import org.springframework.web.servlet.ModelAndView;
66 public class ProfileSearchControllerTest {
69 ProfileSearchController profileSearchController = new ProfileSearchController();
72 UserProfileService service;
75 UserService userService;
78 RoleService roleService;
81 private SharedContextRestClient sharedContextRestClient;
85 MockitoAnnotations.initMocks(this);
88 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
90 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
91 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
93 NullPointerException nullPointerException = new NullPointerException();
95 User user = new User();
98 UserUtils userUtils = new UserUtils();
101 public void profileSearchTest(){
102 ModelAndView actualModelAndView = new ModelAndView();
103 List<User> userList = new ArrayList<User>();
104 Mockito.when(service.findAll()).thenReturn(userList);
105 ModelAndView expectedModelAndView = profileSearchController.profileSearch(mockedRequest);
106 assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName());
110 public void profileSearchExceptionTest(){
111 ModelAndView actualModelAndView = new ModelAndView();
112 List<User> userList = new ArrayList<User>();
113 Mockito.when(service.findAll()).thenThrow(nullPointerException);
114 profileSearchController.profileSearch(mockedRequest);
118 public void getUserTest() throws IOException{
119 List<User> profileList = null;
120 StringWriter sw = new StringWriter();
121 PrintWriter writer = new PrintWriter(sw);
122 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
123 Mockito.when(service.findAll()).thenReturn(profileList);
124 profileSearchController.getUser(mockedRequest, mockedResponse);
128 public void getUserExceptionTest(){
129 List<User> profileList = null;
130 Mockito.when(service.findAll()).thenReturn(profileList);
131 profileSearchController.getUser(mockedRequest, mockedResponse);
135 public void getUserPaginationTest() throws IOException{
136 List<User> profileList = new ArrayList<User>();
137 Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1");
138 Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1");
139 Mockito.when(service.findAll()).thenReturn(profileList);
140 StringWriter sw = new StringWriter();
141 PrintWriter writer = new PrintWriter(sw);
142 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
143 profileSearchController.getUserPagination(mockedRequest, mockedResponse);
147 public void getUserPaginationExceptionTest(){
148 List<User> profileList = null;
149 Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1");
150 Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1");
151 Mockito.when(service.findAll()).thenReturn(profileList);
152 profileSearchController.getUserPagination(mockedRequest, mockedResponse);
156 public void toggleProfileActiveTest() throws IOException{
157 User user = new User();
158 Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("1");
159 Mockito.when(userService.getUser("1")).thenReturn(user);
160 StringWriter sw = new StringWriter();
161 PrintWriter writer = new PrintWriter(sw);
162 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
163 profileSearchController.toggleProfileActive(mockedRequest, mockedResponse);
167 public void toggleProfileActiveExceptionTest() throws IOException{
168 profileSearchController.toggleProfileActive(mockedRequest, mockedResponse);