2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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.openecomp.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.openecomp.portalapp.portal.domain.EPApp;
57 import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
58 import org.openecomp.portalapp.service.RemoteWebServiceCallServiceImpl;
59 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
60 import org.openecomp.portalsdk.core.service.DataAccessService;
61 import org.openecomp.portalsdk.core.util.SystemProperties;
62 import org.powermock.api.mockito.PowerMockito;
63 import org.powermock.core.classloader.annotations.PrepareForTest;
64 import org.powermock.modules.junit4.PowerMockRunner;
66 @RunWith(PowerMockRunner.class)
67 @PrepareForTest({ CipherUtil.class , SystemProperties.class})
68 public class RemoteWebServiceCallServiceImplTest {
72 RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
75 AppsCacheService appCacheService;
78 DataAccessService dataAccessService;
83 MockitoAnnotations.initMocks(this);
86 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
88 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
89 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
91 NullPointerException nullPointerException = new NullPointerException();
94 public void verifyRESTCredentialTest() throws Exception
96 PowerMockito.mockStatic(CipherUtil.class);
97 PowerMockito.mockStatic(SystemProperties.class);
98 String criteria= " where ueb_key = 'requestUebKey'";
99 List<EPApp> appList = new ArrayList<>();
100 EPApp app = new EPApp();
101 app.setAppPassword("password");
103 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
104 String secretKey = null;
105 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
106 Mockito.when(CipherUtil.decrypt("password",
107 secretKey == null ? null : secretKey)).thenReturn("pwd");
108 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword"));
112 public void verifyRESTCredentialExceptionTest() throws Exception
114 PowerMockito.mockStatic(CipherUtil.class);
115 PowerMockito.mockStatic(SystemProperties.class);
116 String criteria= " where ueb_key = 'requestUebKey'";
117 List<EPApp> appList = new ArrayList<>();
118 EPApp app = new EPApp();
119 app.setAppPassword("password");
120 app.setUsername("requestAppName");
122 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
123 String secretKey = null;
124 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
125 Mockito.when(CipherUtil.decrypt("password",
126 secretKey == null ? null : secretKey)).thenReturn("pwd");
127 assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
131 public void verifyRESTCredentialIfAppNullTest() throws Exception
133 PowerMockito.mockStatic(CipherUtil.class);
134 PowerMockito.mockStatic(SystemProperties.class);
135 String criteria= " where ueb_key = 'requestUebKey'";
136 List<EPApp> appList = new ArrayList<>();
137 EPApp app = new EPApp();
138 app.setAppPassword("password");
139 app.setUsername("requestAppName");
141 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
142 String secretKey = null;
143 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
144 Mockito.when(CipherUtil.decrypt("password",
145 secretKey == null ? null : secretKey)).thenReturn("pwd");
146 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
150 public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
152 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
156 public void verifyAppKeyCredentialTest() throws Exception
158 PowerMockito.mockStatic(CipherUtil.class);
159 PowerMockito.mockStatic(SystemProperties.class);
160 StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'");
161 // String criteria= " where ueb_key = 'requestUebKey'";
162 List<EPApp> appList = new ArrayList<>();
163 EPApp app = new EPApp();
164 app.setAppPassword("password");
165 app.setUsername("requestAppName");
167 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
168 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
172 public void verifyAppKeyCredentialSuccessTest() throws Exception
174 PowerMockito.mockStatic(CipherUtil.class);
175 PowerMockito.mockStatic(SystemProperties.class);
176 String criteria= " where ueb_key = 'test'";
177 List<EPApp> appList = new ArrayList<>();
178 EPApp app = new EPApp();
179 app.setAppPassword("password");
180 app.setUsername("requestAppName");
182 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
183 assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));