summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Lima <rodrigo.lima@yoppworks.com>2020-05-11 15:54:37 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-12 06:21:23 +0000
commitf2b6c943b558fcc5161b30ac30c1010066a135ae (patch)
treef84c3a18a7a123e68b65088ae78d714435617a29
parent052b66bed19c2ee0b7ef6c992ee709a1db90a73e (diff)
Remove powermock from SecurityManagerTest
- 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
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java13
2 files changed, 10 insertions, 15 deletions
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