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.*;
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.drools.core.command.assertion.AssertEquals;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.mockito.InjectMocks;
55 import org.mockito.Mock;
56 import org.mockito.Mockito;
57 import org.mockito.MockitoAnnotations;
58 import org.onap.portalapp.framework.MockitoTestSuite;
59 import org.onap.portalsdk.core.domain.User;
60 import org.onap.portalsdk.core.restful.client.SharedContextRestClient;
61 import org.onap.portalsdk.core.service.RoleService;
62 import org.onap.portalsdk.core.service.UserProfileService;
63 import org.onap.portalsdk.core.service.UserService;
64 import org.onap.portalsdk.core.web.support.UserUtils;
65 import org.springframework.web.servlet.ModelAndView;
67 public class ProfileSearchControllerTest {
70 ProfileSearchController profileSearchController = new ProfileSearchController();
73 UserProfileService service;
76 UserService userService;
79 RoleService roleService;
82 private SharedContextRestClient sharedContextRestClient;
86 MockitoAnnotations.initMocks(this);
89 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
91 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
92 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
94 NullPointerException nullPointerException = new NullPointerException();
96 User user = new User();
99 UserUtils userUtils = new UserUtils();
102 public void profileSearchTest(){
103 ModelAndView actualModelAndView = new ModelAndView();
104 List<User> userList = new ArrayList<User>();
105 Mockito.when(service.findAll()).thenReturn(userList);
106 ModelAndView expectedModelAndView = profileSearchController.profileSearch(mockedRequest);
107 assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName());
111 public void profileSearchExceptionTest(){
112 ModelAndView actualModelAndView = new ModelAndView();
113 List<User> userList = new ArrayList<User>();
114 Mockito.when(service.findAll()).thenThrow(nullPointerException);
115 profileSearchController.profileSearch(mockedRequest);
119 public void getUserTest() throws IOException{
120 List<User> profileList = null;
121 StringWriter sw = new StringWriter();
122 PrintWriter writer = new PrintWriter(sw);
123 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
124 Mockito.when(service.findAll()).thenReturn(profileList);
125 profileSearchController.getUser(mockedRequest, mockedResponse);
129 public void getUserExceptionTest(){
130 List<User> profileList = null;
131 Mockito.when(service.findAll()).thenReturn(profileList);
132 profileSearchController.getUser(mockedRequest, mockedResponse);
136 public void getUserPaginationTest() throws IOException{
137 List<User> profileList = new ArrayList<User>();
138 Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1");
139 Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1");
140 Mockito.when(service.findAll()).thenReturn(profileList);
141 StringWriter sw = new StringWriter();
142 PrintWriter writer = new PrintWriter(sw);
143 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
144 profileSearchController.getUserPagination(mockedRequest, mockedResponse);
148 public void getUserPaginationExceptionTest(){
149 List<User> profileList = null;
150 Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1");
151 Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1");
152 Mockito.when(service.findAll()).thenReturn(profileList);
153 profileSearchController.getUserPagination(mockedRequest, mockedResponse);
157 public void toggleProfileActiveTest() throws IOException{
158 User user = new User();
159 Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("1");
160 Mockito.when(userService.getUser("1")).thenReturn(user);
161 StringWriter sw = new StringWriter();
162 PrintWriter writer = new PrintWriter(sw);
163 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
164 profileSearchController.toggleProfileActive(mockedRequest, mockedResponse);
168 public void toggleProfileActiveExceptionTest() throws IOException{
169 profileSearchController.toggleProfileActive(mockedRequest, mockedResponse);