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============================================
 
  36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  38 package org.onap.portalapp.portal.service;
 
  40 import static org.junit.Assert.*;
 
  42 import java.util.ArrayList;
 
  43 import java.util.List;
 
  45 import javax.servlet.http.HttpServletRequest;
 
  46 import javax.servlet.http.HttpServletResponse;
 
  48 import org.onap.portalsdk.core.util.SystemProperties;
 
  49 import org.junit.Before;
 
  50 import org.junit.Test;
 
  51 import org.junit.runner.RunWith;
 
  52 import org.mockito.InjectMocks;
 
  53 import org.mockito.Mock;
 
  54 import org.mockito.Mockito;
 
  55 import org.mockito.MockitoAnnotations;
 
  56 import org.onap.portalapp.portal.domain.EPApp;
 
  57 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 
  58 import org.onap.portalapp.portal.service.AppsCacheService;
 
  59 import org.onap.portalapp.portal.utils.EcompPortalUtils;
 
  60 import org.onap.portalapp.service.RemoteWebServiceCallServiceImpl;
 
  61 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
 
  62 import org.onap.portalsdk.core.service.DataAccessService;
 
  63 import org.powermock.api.mockito.PowerMockito;
 
  64 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  65 import org.powermock.modules.junit4.PowerMockRunner;
 
  67 @RunWith(PowerMockRunner.class)
 
  68 @PrepareForTest({ CipherUtil.class , SystemProperties.class})
 
  69 public class RemoteWebServiceCallServiceImplTest {
 
  73         RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
 
  76         AppsCacheService appCacheService;
 
  79         DataAccessService dataAccessService;
 
  84                 MockitoAnnotations.initMocks(this);
 
  87         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
 
  89         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
 
  90         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
 
  92         NullPointerException nullPointerException = new NullPointerException();
 
  95         public void verifyRESTCredentialTest() throws Exception
 
  97                 PowerMockito.mockStatic(CipherUtil.class);
 
  98                 PowerMockito.mockStatic(SystemProperties.class);
 
  99                 String criteria= " where ueb_key = 'requestUebKey'";
 
 100                 List<EPApp> appList = new ArrayList<>();
 
 101                 EPApp app = new EPApp();
 
 102                 app.setAppPassword("password");
 
 104                 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
 
 105                 String secretKey = null;
 
 106                 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
 
 107                 Mockito.when(CipherUtil.decryptPKC("password",
 
 108                                 secretKey == null ? null : secretKey)).thenReturn("pwd");
 
 109                 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword"));
 
 113         public void verifyRESTCredentialExceptionTest() throws Exception
 
 115                 PowerMockito.mockStatic(CipherUtil.class);
 
 116                 PowerMockito.mockStatic(SystemProperties.class);
 
 117                 String criteria= " where ueb_key = 'requestUebKey'";
 
 118                 List<EPApp> appList = new ArrayList<>();
 
 119                 EPApp app = new EPApp();
 
 120                 app.setAppPassword("password");
 
 121                 app.setUsername("requestAppName");
 
 123                 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
 
 124                 String secretKey = null;
 
 125                 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
 
 126                 Mockito.when(CipherUtil.decryptPKC("password",
 
 127                                 secretKey == null ? null : secretKey)).thenReturn("pwd");
 
 128                 assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
 
 132         public void verifyRESTCredentialIfAppNullTest() throws Exception
 
 134                 PowerMockito.mockStatic(CipherUtil.class);
 
 135                 PowerMockito.mockStatic(SystemProperties.class);
 
 136                 String criteria= " where ueb_key = 'requestUebKey'";
 
 137                 List<EPApp> appList = new ArrayList<>();
 
 138                 EPApp app = new EPApp();
 
 139                 app.setAppPassword("password");
 
 140                 app.setUsername("requestAppName");
 
 142                 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
 
 143                 String secretKey = null;
 
 144                 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
 
 145                 Mockito.when(CipherUtil.decryptPKC("password",
 
 146                                 secretKey == null ? null : secretKey)).thenReturn("pwd");
 
 147                 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
 
 151         public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
 
 153                 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
 
 157         public void verifyAppKeyCredentialTest() throws Exception
 
 159                 PowerMockito.mockStatic(CipherUtil.class);
 
 160                 PowerMockito.mockStatic(SystemProperties.class);
 
 161                 StringBuffer criteria = new  StringBuffer("where ueb_key = 'requestUebKey'");
 
 162 //              String criteria= " where ueb_key = 'requestUebKey'";
 
 163                 List<EPApp> appList = new ArrayList<>();
 
 164                 EPApp app = new EPApp();
 
 165                 app.setAppPassword("password");
 
 166                 app.setUsername("requestAppName");
 
 168                 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
 
 169                 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
 
 173         public void verifyAppKeyCredentialSuccessTest() throws Exception
 
 175                 PowerMockito.mockStatic(CipherUtil.class);
 
 176                 PowerMockito.mockStatic(SystemProperties.class);
 
 177                 String criteria= " where ueb_key = 'test'";
 
 178                 List<EPApp> appList = new ArrayList<>();
 
 179                 EPApp app = new EPApp();
 
 180                 app.setAppPassword("password");
 
 181                 app.setUsername("requestAppName");
 
 183                 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
 
 184                 assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));