Remove powermock from SecurityManagerTest 96/107496/2
authorRodrigo Lima <rodrigo.lima@yoppworks.com>
Mon, 11 May 2020 19:54:37 +0000 (15:54 -0400)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Tue, 12 May 2020 06:21:23 +0000 (06:21 +0000)
- Add new package level constructor to SecurityManager
- Remove powermock from SecurityManagerTest

Issue-ID: SDC-3054
Signed-off-by: Rodrigo Lima <rodrigo.lima@yoppworks.com>
Change-Id: I04c53601f31d2aad84de8f8801f6889f8b9d4260

openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java

index 53c2e1d..6fae6f0 100644 (file)
@@ -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;
         }
index b1d6fdc..7c5cb66 100644 (file)
@@ -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