Null check for ClientResponse in PolicyUril.java
[portal.git] / ecomp-portal-BE-common / src / test / java / org / openecomp / portalapp / portal / service / EPRoleFunctionServiceCentralizedImplTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.portal.service;
39
40 import static org.junit.Assert.*;
41
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.Set;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpSession;
50
51 import org.hibernate.SessionFactory;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
55 import org.mockito.InjectMocks;
56 import org.mockito.Mock;
57 import org.mockito.Mockito;
58 import org.mockito.MockitoAnnotations;
59 import org.openecomp.portalapp.portal.domain.CentralRoleFunction;
60 import org.openecomp.portalapp.portal.domain.EPUser;
61 import org.openecomp.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl;
62 import org.openecomp.portalapp.portal.core.MockEPUser;
63 import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
64 import org.openecomp.portalsdk.core.domain.RoleFunction;
65 import org.openecomp.portalsdk.core.service.DataAccessService;
66 import org.openecomp.portalsdk.core.util.SystemProperties;
67 import org.powermock.core.classloader.annotations.PrepareForTest;
68 import org.powermock.modules.junit4.PowerMockRunner;
69
70 @RunWith(PowerMockRunner.class)
71 @PrepareForTest(SystemProperties.class)
72 public class EPRoleFunctionServiceCentralizedImplTest {
73
74         
75         @Mock
76         DataAccessService dataAccessService;
77         
78         @Mock
79         SessionFactory sessionFactory;
80
81         @InjectMocks
82         EPRoleFunctionServiceCentralizedImpl ePRoleFunctionServiceCentralizedImpl = new EPRoleFunctionServiceCentralizedImpl();
83
84         @Before
85         public void setup() {
86                 MockitoAnnotations.initMocks(this);
87         }
88
89         NullPointerException nullPointerException = new NullPointerException();
90         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
91         MockEPUser mockUser = new MockEPUser();
92
93         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
94         
95         @Test
96         public void getRoleFunctions()
97         {
98                 List<CentralRoleFunction> getRoleFuncList = new ArrayList<>();
99                 CentralRoleFunction centralRoleFunction = new CentralRoleFunction();
100                 getRoleFuncList.add(centralRoleFunction);
101                 List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>();
102                 RoleFunction roleFunction = new RoleFunction();
103                 getRoleFuncListOfPortal.add(roleFunction);
104                 final Map<String, Long> params = new HashMap<>();
105                 params.put("appId", (long) 1);
106                 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(getRoleFuncList);
107                 List<RoleFunction> expectedGetRoleFuncListOfPortal = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions();
108                 assertEquals(expectedGetRoleFuncListOfPortal.size(),getRoleFuncListOfPortal.size());
109         }
110         
111         @Test
112         public void getRoleFunctionsNewTest()
113         {
114                 HttpSession session = mockedRequest.getSession();
115                 EPUser user = mockUser.mockEPUser();
116                 user.setId((long) 1);
117                 String userId = user.getId().toString();
118                 final Map<String, String> params = new HashMap<>();
119                 params.put("userId", userId);           
120                 @SuppressWarnings("unused")
121                 List getRoleFuncListOfPortal = new ArrayList<>();
122                 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null)).thenReturn(getRoleFuncListOfPortal);
123                 Set<String> getRoleFuncListOfPortalSet = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(mockedRequest, user);
124                 assertTrue(getRoleFuncListOfPortalSet.size() == 0);
125         }
126 }