2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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.portal.service;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertNotEquals;
42 import static org.junit.Assert.assertNull;
44 import java.util.ArrayList;
45 import java.util.List;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.mockito.InjectMocks;
51 import org.mockito.Matchers;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.onap.portalapp.portal.core.MockEPUser;
56 import org.onap.portalapp.portal.domain.EPUser;
57 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
58 import org.onap.portalapp.portal.utils.EcompPortalUtils;
59 import org.onap.portalapp.portal.utils.PortalConstants;
60 import org.onap.portalsdk.core.command.support.SearchResult;
61 import org.onap.portalsdk.core.util.SystemProperties;
62 import org.powermock.api.mockito.PowerMockito;
63 import org.powermock.core.classloader.annotations.PrepareForTest;
64 import org.powermock.modules.junit4.PowerMockRunner;
67 @RunWith(PowerMockRunner.class)
68 @PrepareForTest({ EcompPortalUtils.class, PortalConstants.class, SystemProperties.class,
69 EPCommonSystemProperties.class })
70 public class SearchServiceImplTest {
73 SearchServiceImpl searchServiceImpl = new SearchServiceImpl();
76 EPLdapService epLdapService;
80 MockitoAnnotations.initMocks(this);
83 MockEPUser mockUser = new MockEPUser();
85 @SuppressWarnings("unchecked")
87 public void searchUsersInPhoneBookTest() throws Exception {
88 PowerMockito.mockStatic(EcompPortalUtils.class);
89 List<String> tokens = new ArrayList<>();
91 tokens.add("TestName");
92 EPUser user = new EPUser();
93 user.setOrgUserId("ts1234");
94 user.setFirstName("TestName");
95 Mockito.when(EcompPortalUtils.parsingByRegularExpression(Matchers.anyString(), Matchers.anyString())).thenReturn(tokens);
96 SearchResult searchResult = new SearchResult();
97 searchResult.add(user);
98 Mockito.when(epLdapService.searchPost(Matchers.any(EPUser.class), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt())).thenReturn(searchResult);
99 String actual = searchServiceImpl.searchUsersInPhoneBook("ts1234");
100 assertNotEquals("[]", actual);
103 @SuppressWarnings("unchecked")
105 public void searchUsersInPhoneBookFirtAndLastNameTest() throws Exception {
106 PowerMockito.mockStatic(EcompPortalUtils.class);
107 List<String> tokens = new ArrayList<>();
108 tokens.add("ts1234");
109 tokens.add("TestFirstName");
110 tokens.add("TestLastName");
111 EPUser user = new EPUser();
112 user.setOrgUserId("ts1234");
113 user.setFirstName("TestFirstName");
114 user.setLastName("TestLastName");
115 Mockito.when(EcompPortalUtils.parsingByRegularExpression(Matchers.anyString(), Matchers.anyString())).thenReturn(tokens);
116 SearchResult searchResult = new SearchResult();
117 searchResult.add(user);
118 Mockito.when(epLdapService.searchPost(Matchers.any(EPUser.class), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt())).thenReturn(searchResult);
119 String actual = searchServiceImpl.searchUsersInPhoneBook("ts1234");
120 assertNotEquals("[]", actual);
123 @SuppressWarnings("unchecked")
125 public void searchUserByUserIdTest() throws Exception {
126 EPUser user = new EPUser();
127 user.setOrgUserId("ts1234");
128 SearchResult searchResult = new SearchResult();
129 searchResult.add(user);
130 Mockito.when(epLdapService.searchPost(Matchers.any(EPUser.class), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt())).thenReturn(searchResult);
131 EPUser actual = searchServiceImpl.searchUserByUserId("ts1234");
132 assertEquals(user, actual);
136 public void searchUserByUserIdExceptionTest() throws Exception {
137 Mockito.doThrow(new NullPointerException()).when(epLdapService).searchPost(Matchers.any(EPUser.class), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt());
138 EPUser actual = searchServiceImpl.searchUserByUserId("ts1234");