From f2b6c943b558fcc5161b30ac30c1010066a135ae Mon Sep 17 00:00:00 2001 From: Rodrigo Lima Date: Mon, 11 May 2020 15:54:37 -0400 Subject: Remove powermock from SecurityManagerTest - Add new package level constructor to SecurityManager - Remove powermock from SecurityManagerTest Issue-ID: SDC-3054 Signed-off-by: Rodrigo Lima Change-Id: I04c53601f31d2aad84de8f8801f6889f8b9d4260 --- .../sdc/vendorsoftwareproduct/security/SecurityManager.java | 12 +++++++++--- .../vendorsoftwareproduct/security/SecurityManagerTest.java | 13 +------------ 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'openecomp-be/backend') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java index 53c2e1d0bc..6fae6f0e72 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java @@ -86,7 +86,13 @@ public class SecurityManager { } private SecurityManager() { - certificateDirectory = this.getcertDirectory(); + certificateDirectory = this.getcertDirectory(System.getenv("SDC_CERT_DIR")); + } + + + // Package level constructor use in tests to avoid power mock + SecurityManager(String sdcCertDir) { + certificateDirectory = this.getcertDirectory(sdcCertDir); } public static SecurityManager getInstance() { @@ -193,8 +199,8 @@ public class SecurityManager { } } - private File getcertDirectory() { - String certDirLocation = System.getenv("SDC_CERT_DIR"); + private File getcertDirectory(String sdcCertDir) { + String certDirLocation = sdcCertDir; if (certDirLocation == null) { certDirLocation = CERTIFICATE_DEFAULT_LOCATION; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java index b1d6fdc97d..7c5cb662c7 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java @@ -24,11 +24,6 @@ import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import java.io.File; import java.io.IOException; @@ -38,11 +33,7 @@ import java.nio.file.Paths; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -@RunWith(PowerMockRunner.class) -@PrepareForTest(SecurityManager.class) -@PowerMockIgnore("javax.security.auth.x500.X500Principal") public class SecurityManagerTest { private File certDir; private SecurityManager securityManager; @@ -54,9 +45,7 @@ public class SecurityManagerTest { tearDown(); } certDir.mkdirs(); - PowerMockito.mockStatic(System.class); - PowerMockito.when(System.getenv(eq("SDC_CERT_DIR"))).thenReturn(certDir.getPath()); - securityManager = SecurityManager.getInstance(); + securityManager = new SecurityManager(certDir.getPath()); } @After -- cgit 1.2.3-korg