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.*;
 
  42 import java.util.ArrayList;
 
  43 import java.util.HashMap;
 
  44 import java.util.List;
 
  48 import javax.servlet.http.HttpServletRequest;
 
  49 import javax.servlet.http.HttpSession;
 
  51 import org.apache.commons.codec.DecoderException;
 
  52 import org.hibernate.SessionFactory;
 
  53 import org.junit.Before;
 
  54 import org.junit.Ignore;
 
  55 import org.junit.Test;
 
  56 import org.junit.runner.RunWith;
 
  57 import org.mockito.InjectMocks;
 
  58 import org.mockito.Mock;
 
  59 import org.mockito.Mockito;
 
  60 import org.mockito.MockitoAnnotations;
 
  61 import org.onap.portalapp.portal.core.MockEPUser;
 
  62 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
 
  63 import org.onap.portalapp.portal.domain.EPUser;
 
  64 import org.onap.portalapp.portal.exceptions.RoleFunctionException;
 
  65 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 
  66 import org.onap.portalapp.portal.service.EPRoleFunctionServiceCentralizedImpl;
 
  67 import org.onap.portalsdk.core.domain.RoleFunction;
 
  68 import org.onap.portalsdk.core.service.DataAccessService;
 
  69 import org.onap.portalsdk.core.util.SystemProperties;
 
  70 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  71 import org.powermock.modules.junit4.PowerMockRunner;
 
  73 @RunWith(PowerMockRunner.class)
 
  74 @PrepareForTest(SystemProperties.class)
 
  76 public class EPRoleFunctionServiceCentralizedImplTest {
 
  80         DataAccessService dataAccessService;
 
  83         SessionFactory sessionFactory;
 
  86         EPRoleFunctionServiceCentralizedImpl ePRoleFunctionServiceCentralizedImpl = new EPRoleFunctionServiceCentralizedImpl();
 
  90                 MockitoAnnotations.initMocks(this);
 
  93         NullPointerException nullPointerException = new NullPointerException();
 
  94         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
 
  95         MockEPUser mockUser = new MockEPUser();
 
  97         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
 
  99         @Test(expected = NullPointerException.class)
 
 100         public void getRoleFunctions()
 
 102                 List<CentralV2RoleFunction> getRoleFuncList = new ArrayList<>();
 
 103                 CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
 
 104                 getRoleFuncList.add(centralV2RoleFunction);
 
 105                 List<RoleFunction> getRoleFuncListOfPortal = new ArrayList<>();
 
 106                 RoleFunction roleFunction = new RoleFunction();
 
 107                 getRoleFuncListOfPortal.add(roleFunction);
 
 108                 final Map<String, Long> params = new HashMap<>();
 
 109                 params.put("appId", (long) 1);
 
 110                 Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params, null)).thenReturn(getRoleFuncList);
 
 111                 List<RoleFunction> expectedGetRoleFuncListOfPortal = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions();
 
 112                 assertEquals(expectedGetRoleFuncListOfPortal.size(),getRoleFuncListOfPortal.size());
 
 116         public void getRoleFunctionsNewTest() throws RoleFunctionException
 
 118                 HttpSession session = mockedRequest.getSession();
 
 119                 EPUser user = mockUser.mockEPUser();
 
 120                 user.setId((long) 1);
 
 121                 String userId = user.getId().toString();
 
 122                 final Map<String, String> params = new HashMap<>();
 
 123                 params.put("userId", userId);           
 
 124                 @SuppressWarnings("unused")
 
 125                 List getRoleFuncListOfPortal = new ArrayList<>();
 
 126                 Mockito.when(dataAccessService.executeNamedQuery("getRoleFunctionsOfUser", params, null)).thenReturn(getRoleFuncListOfPortal);
 
 127                 Set<String> getRoleFuncListOfPortalSet = ePRoleFunctionServiceCentralizedImpl.getRoleFunctions(mockedRequest, user);
 
 128                 assertTrue(getRoleFuncListOfPortalSet.size() == 0);