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;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNull;
43 import java.io.IOException;
44 import java.io.PrintWriter;
45 import java.io.StringWriter;
46 import java.util.ArrayList;
47 import java.util.List;
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
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.controller.sample.CollaborateListController;
59 import org.onap.portalapp.framework.MockitoTestSuite;
60 import org.onap.portalsdk.core.domain.User;
61 import org.onap.portalsdk.core.service.UserProfileService;
62 import org.onap.portalsdk.core.web.support.UserUtils;
63 import org.springframework.web.servlet.ModelAndView;
65 public class CollaborateListControllerTest {
69 CollaborateListController collaborateListController = new CollaborateListController();
73 MockitoAnnotations.initMocks(this);
76 UserProfileService service;
79 UserUtils userUtils = new UserUtils();
82 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
83 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
84 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
85 NullPointerException nullPointerException = new NullPointerException();
89 public void profileSearchTest()
91 List<User> userList = new ArrayList<>();
92 User user = new User();
93 user.setOrgUserId("test12");
95 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
96 Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenReturn(userList);
97 ModelAndView expectedResult = collaborateListController.ProfileSearch(mockedRequest);
98 assertEquals(expectedResult.getModel().size(), userList.size());
102 public void profileSearchExceptionTest()
104 List<User> userList = new ArrayList<>();
105 User user = new User();
106 user.setOrgUserId("test12");
108 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
109 Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenThrow(nullPointerException);
110 ModelAndView expectedResult = collaborateListController.ProfileSearch(mockedRequest);
111 assertNull(expectedResult.getViewName());
115 public void getCollaborateListTest() throws IOException
117 List<User> userList = new ArrayList<>();
118 User user = new User();
119 user.setOrgUserId("test12");
121 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
122 Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenReturn(userList);
123 StringWriter sw = new StringWriter();
124 PrintWriter writer = new PrintWriter(sw);
125 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
126 collaborateListController.getCollaborateList(mockedRequest,mockedResponse);
131 public void getCollaborateListExceptionTest() throws IOException
133 List<User> userList = new ArrayList<>();
134 User user = new User();
135 user.setOrgUserId("test12");
137 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
138 Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenThrow(nullPointerException);
139 collaborateListController.getCollaborateList(mockedRequest,mockedResponse);