From 2bd47b537ff4fa78ae8f38758900022df6344cdb Mon Sep 17 00:00:00 2001 From: “Kruthi Date: Thu, 4 Jun 2020 19:34:07 +0530 Subject: Resubmitting KeyProperty code change since tests failed Change-Id: I14c0f9b59229e32de45b1652e64c01dd6c1d39e3 Issue-ID: PORTAL-914 Signed-off-by: krutbhat@att.com --- .../service/BasicAuthAccountServiceImplTest.java | 14 +++++++++----- .../portal/service/MicroserviceServiceImplTest.java | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'ecomp-portal-BE-common/src/test/java') diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java index 6382bef4..a905ca81 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java @@ -42,6 +42,8 @@ import org.onap.portalapp.portal.domain.EPEndpoint; import org.onap.portalapp.portal.domain.EPEndpointAccount; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.DataAccessServiceImpl; import org.onap.portalsdk.core.util.SystemProperties; @@ -51,7 +53,7 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({ CipherUtil.class , SystemProperties.class}) +@PrepareForTest({ CipherUtil.class , SystemProperties.class, KeyProperties.class, KeyConstants.class}) public class BasicAuthAccountServiceImplTest { @Mock DataAccessService dataAccessService = new DataAccessServiceImpl(); @@ -92,11 +94,12 @@ public class BasicAuthAccountServiceImplTest { @Test public void saveBasicAuthAccountTest_password() throws Exception{ PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); BasicAuthCredentials credentials = new BasicAuthCredentials(); credentials.setPassword("password"); String result = null; - Mockito.when(CipherUtil.encryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result); + Mockito.when(CipherUtil.encryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result); basicAuthAccountServiceImpl.saveBasicAuthAccount(credentials); } @@ -163,7 +166,8 @@ public class BasicAuthAccountServiceImplTest { @Test public void getAccountDataTest_password() throws Exception { PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List list = new ArrayList<>(); BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials(); basicAuthCredentials.setPassword("password"); @@ -171,7 +175,7 @@ public class BasicAuthAccountServiceImplTest { Mockito.when((List) dataAccessService.getList(BasicAuthCredentials.class, null)) .thenReturn(list); String result = null; - Mockito.when(CipherUtil.decryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result); + Mockito.when(CipherUtil.decryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java index ae813152..bc8d4548 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java @@ -58,6 +58,8 @@ import org.onap.portalapp.portal.domain.MicroserviceData; import org.onap.portalapp.portal.domain.MicroserviceParameter; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.DataAccessServiceImpl; import org.onap.portalsdk.core.util.SystemProperties; @@ -66,7 +68,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({Criterion.class, Restrictions.class, CipherUtil.class, EPCommonSystemProperties.class, SystemProperties.class, Restrictions.class}) +@PrepareForTest({Criterion.class, Restrictions.class, CipherUtil.class, EPCommonSystemProperties.class, SystemProperties.class, KeyProperties.class, KeyConstants.class}) public class MicroserviceServiceImplTest { private static final String TEST="test"; @@ -150,6 +152,8 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); PowerMockito.mockStatic(Restrictions.class); PowerMockito.mockStatic(Criterion.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List microserviceParameters = new ArrayList<>(); MicroserviceData microserviceData = new MicroserviceData(); MicroserviceParameter microserviceParameter = new MicroserviceParameter(); @@ -168,8 +172,7 @@ public class MicroserviceServiceImplTest { Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList2.add(serviceIdCriterion); Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); - Mockito.when(CipherUtil.decryptPKC("xyz", - SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn("abc"); + Mockito.when(CipherUtil.decryptPKC("xyz",KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn("abc"); List actual = microserviceServiceImpl.getMicroserviceData(); assertNotNull(actual); } @@ -181,6 +184,8 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); PowerMockito.mockStatic(Restrictions.class); PowerMockito.mockStatic(Criterion.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List microserviceParameters = new ArrayList<>(); MicroserviceData microserviceData = new MicroserviceData(); MicroserviceParameter microserviceParameter = new MicroserviceParameter(); @@ -199,8 +204,7 @@ public class MicroserviceServiceImplTest { Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList2.add(serviceIdCriterion); Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); - Mockito.when(CipherUtil.decryptPKC("xyz", - SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenThrow(BadPaddingException.class); + Mockito.when(CipherUtil.decryptPKC("xyz",KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenThrow(BadPaddingException.class); List actual = microserviceServiceImpl.getMicroserviceData(); assertNotNull(actual); } @@ -220,10 +224,10 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList.add(serviceIdCriterion); - PowerMockito.mockStatic(SystemProperties.class); - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(TEST); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); + Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(TEST); Mockito.when(CipherUtil.encryptPKC(TEST, TEST)).thenReturn(TEST); - Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList, null)).thenReturn(microserviceParameters); microserviceServiceImpl.updateMicroservice(1l, buildData()); -- cgit 1.2.3-korg