Merge "Fix sql injection vulnerability"
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / EPProfileServiceImplTest.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP  PORTAL
4 * ================================================================================
5 * Copyright 2018 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20 package org.onap.portalapp.portal.service;
21
22 import static org.junit.Assert.*;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.onap.portalapp.portal.core.MockEPUser;
33 import org.onap.portalapp.portal.domain.EPUser;
34 import org.onap.portalapp.service.EPProfileServiceImpl;
35 import org.onap.portalsdk.core.dao.ProfileDao;
36 import org.onap.portalsdk.core.domain.Profile;
37 import org.onap.portalsdk.core.service.DataAccessService;
38 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
39
40 public class EPProfileServiceImplTest {
41
42         @Mock
43         DataAccessService dataAccessService = new DataAccessServiceImpl();
44         
45         @Mock
46         ProfileDao profileDao;
47         
48         @Before
49         public void setup() {
50                 MockitoAnnotations.initMocks(this);
51         }
52
53         @InjectMocks
54         EPProfileServiceImpl epProfileServiceImpl = new EPProfileServiceImpl();
55
56         MockEPUser mockUser = new MockEPUser();
57         
58         @Test
59         public void findAllTest() {
60                 List<Profile> profileList = new ArrayList<>();
61                 Mockito.when(dataAccessService.getList(Profile.class, null)).thenReturn(profileList);
62                 List<Profile> expectedRoleList = epProfileServiceImpl.findAll();
63                 assertEquals(expectedRoleList, profileList);
64         }
65         
66         @Test(expected = java.lang.NumberFormatException.class)
67         public void getUserTest() {
68                 EPUser epUser = new EPUser();
69                 Mockito.when(dataAccessService.getDomainObject(EPUser.class, Long.parseLong("test"), null)).thenReturn(epUser);
70                 epProfileServiceImpl.getUser("test");
71         }
72         
73         @Test
74         public void saveUserTest() {
75                 EPUser user = mockUser.mockEPUser();
76                 Mockito.doNothing().when(dataAccessService).saveDomainObject(user,  null);
77                 epProfileServiceImpl.saveUser(user);
78         }
79         
80         @Test
81         public void getProfileTest() {
82                 epProfileServiceImpl.getProfile(1);
83         
84         }
85
86 }