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.assertFalse;
41 import static org.junit.Assert.assertTrue;
43 import java.util.ArrayList;
44 import java.util.List;
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
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.service.RemoteWebServiceCallServiceImpl;
59 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
60 import org.onap.portalsdk.core.onboarding.util.KeyConstants;
61 import org.onap.portalsdk.core.onboarding.util.KeyProperties;
62 import org.onap.portalsdk.core.service.DataAccessService;
63 import org.onap.portalsdk.core.util.SystemProperties;
64 import org.powermock.api.mockito.PowerMockito;
65 import org.powermock.core.classloader.annotations.PrepareForTest;
66 import org.powermock.modules.junit4.PowerMockRunner;
68 @RunWith(PowerMockRunner.class)
69 @PrepareForTest({ CipherUtil.class , SystemProperties.class, KeyProperties.class, KeyConstants.class})
70 public class RemoteWebServiceCallServiceImplTest {
74 RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
77 AppsCacheService appCacheService;
80 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(KeyProperties.class);
99 PowerMockito.mockStatic(KeyConstants.class);
100 String criteria= " where ueb_key = 'requestUebKey'";
101 List<EPApp> appList = new ArrayList<>();
102 EPApp app = new EPApp();
103 app.setAppBasicAuthPassword("password");
105 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
106 String secretKey = null;
107 Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey);
108 Mockito.when(CipherUtil.decryptPKC("password",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(KeyProperties.class);
117 PowerMockito.mockStatic(KeyConstants.class);
118 String criteria= " where ueb_key = 'requestUebKey'";
119 List<EPApp> appList = new ArrayList<>();
120 EPApp app = new EPApp();
121 app.setAppBasicAuthPassword("password");
122 app.setAppBasicAuthUsername("requestAppName");
124 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
125 String secretKey = null;
126 Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey);
127 Mockito.when(CipherUtil.decryptPKC("password",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 PowerMockito.mockStatic(KeyProperties.class);
137 PowerMockito.mockStatic(KeyConstants.class);
138 String criteria= " where ueb_key = 'requestUebKey'";
139 List<EPApp> appList = new ArrayList<>();
140 EPApp app = new EPApp();
141 app.setAppBasicAuthPassword("password");
142 app.setAppBasicAuthUsername("requestAppName");
144 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
145 String secretKey = null;
146 Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey);
147 Mockito.when(CipherUtil.decryptPKC("password",secretKey == null ? null : secretKey)).thenReturn("pwd");
148 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
152 public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
154 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
158 public void verifyAppKeyCredentialTest() throws Exception
160 PowerMockito.mockStatic(CipherUtil.class);
161 PowerMockito.mockStatic(SystemProperties.class);
162 StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'");
163 // String criteria= " where ueb_key = 'requestUebKey'";
164 List<EPApp> appList = new ArrayList<>();
165 EPApp app = new EPApp();
166 app.setAppBasicAuthPassword("password");
167 app.setAppBasicAuthUsername("requestAppName");
169 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
170 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
174 public void verifyAppKeyCredentialSuccessTest() throws Exception
176 PowerMockito.mockStatic(CipherUtil.class);
177 PowerMockito.mockStatic(SystemProperties.class);
178 String criteria= " where ueb_key = 'test'";
179 List<EPApp> appList = new ArrayList<>();
180 EPApp app = new EPApp();
181 app.setAppBasicAuthPassword("password");
182 app.setAppBasicAuthUsername("requestAppName");
184 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
185 assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));