1 package org.openecomp.portalapp.portal.service;
3 import static org.junit.Assert.*;
5 import java.util.ArrayList;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
11 import org.openecomp.portalsdk.core.util.SystemProperties;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.InjectMocks;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.MockitoAnnotations;
19 import org.openecomp.portalapp.portal.domain.EPApp;
20 import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
21 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
22 import org.openecomp.portalapp.service.RemoteWebServiceCallServiceImpl;
23 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
24 import org.openecomp.portalsdk.core.service.DataAccessService;
25 import org.powermock.api.mockito.PowerMockito;
26 import org.powermock.core.classloader.annotations.PrepareForTest;
27 import org.powermock.modules.junit4.PowerMockRunner;
29 @RunWith(PowerMockRunner.class)
30 @PrepareForTest({ CipherUtil.class , SystemProperties.class})
31 public class RemoteWebServiceCallServiceImplTest {
35 RemoteWebServiceCallServiceImpl remoteWebServiceCallServiceImpl = new RemoteWebServiceCallServiceImpl();
38 AppsCacheService appCacheService;
41 DataAccessService dataAccessService;
46 MockitoAnnotations.initMocks(this);
49 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
51 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
52 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
54 NullPointerException nullPointerException = new NullPointerException();
57 public void verifyRESTCredentialTest() throws Exception
59 PowerMockito.mockStatic(CipherUtil.class);
60 PowerMockito.mockStatic(SystemProperties.class);
61 String criteria= " where ueb_key = 'requestUebKey'";
62 List<EPApp> appList = new ArrayList<>();
63 EPApp app = new EPApp();
64 app.setAppPassword("password");
66 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
67 String secretKey = null;
68 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
69 Mockito.when(CipherUtil.decrypt("password",
70 secretKey == null ? null : secretKey)).thenReturn("pwd");
71 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword"));
75 public void verifyRESTCredentialExceptionTest() throws Exception
77 PowerMockito.mockStatic(CipherUtil.class);
78 PowerMockito.mockStatic(SystemProperties.class);
79 String criteria= " where ueb_key = 'requestUebKey'";
80 List<EPApp> appList = new ArrayList<>();
81 EPApp app = new EPApp();
82 app.setAppPassword("password");
83 app.setUsername("requestAppName");
85 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
86 String secretKey = null;
87 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
88 Mockito.when(CipherUtil.decrypt("password",
89 secretKey == null ? null : secretKey)).thenReturn("pwd");
90 assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
94 public void verifyRESTCredentialIfAppNullTest() 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");
102 app.setUsername("requestAppName");
104 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
105 String secretKey = null;
106 Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey);
107 Mockito.when(CipherUtil.decrypt("password",
108 secretKey == null ? null : secretKey)).thenReturn("pwd");
109 assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd"));
113 public void verifyAppKeyCredentialIfKeyIsNullTest() throws Exception
115 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential(null));
119 public void verifyAppKeyCredentialTest() throws Exception
121 PowerMockito.mockStatic(CipherUtil.class);
122 PowerMockito.mockStatic(SystemProperties.class);
123 StringBuffer criteria = new StringBuffer("where ueb_key = 'requestUebKey'");
124 // String criteria= " where ueb_key = 'requestUebKey'";
125 List<EPApp> appList = new ArrayList<>();
126 EPApp app = new EPApp();
127 app.setAppPassword("password");
128 app.setUsername("requestAppName");
130 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null);
131 assertFalse(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));
135 public void verifyAppKeyCredentialSuccessTest() throws Exception
137 PowerMockito.mockStatic(CipherUtil.class);
138 PowerMockito.mockStatic(SystemProperties.class);
139 String criteria= " where ueb_key = 'test'";
140 List<EPApp> appList = new ArrayList<>();
141 EPApp app = new EPApp();
142 app.setAppPassword("password");
143 app.setUsername("requestAppName");
145 Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList);
146 assertTrue(remoteWebServiceCallServiceImpl.verifyAppKeyCredential("test"));