summaryrefslogtreecommitdiffstats
path: root/security-util-lib/src
diff options
context:
space:
mode:
Diffstat (limited to 'security-util-lib/src')
-rw-r--r--security-util-lib/src/main/java/org/onap/sdc/security/SecurityUtil.java5
-rw-r--r--security-util-lib/src/main/java/org/onap/sdc/security/utils/RestUtils.java4
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/AuthenticationCookieUtilsTest.java45
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/CipherUtilTest.java49
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/PasswordsTest.java34
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/RepresentationUtilsTest.java19
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/RestUtilsTest.java31
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/SecurityUtilTest.java21
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/filters/RestrictionAccessFilterTest.java210
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/filters/SessionValidationFilterTest.java111
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java32
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/EcompLoggerErrorCodeTest.java16
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/LoggerSupportabilityActionsTest.java25
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/SeverityTest.java14
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/StatusCodeTest.java12
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcAuditTest.java42
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcUtilBaseTest.java29
-rw-r--r--security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java125
18 files changed, 426 insertions, 398 deletions
diff --git a/security-util-lib/src/main/java/org/onap/sdc/security/SecurityUtil.java b/security-util-lib/src/main/java/org/onap/sdc/security/SecurityUtil.java
index eb67813..099ca0a 100644
--- a/security-util-lib/src/main/java/org/onap/sdc/security/SecurityUtil.java
+++ b/security-util-lib/src/main/java/org/onap/sdc/security/SecurityUtil.java
@@ -46,7 +46,6 @@ public class SecurityUtil {
private static final Logger LOG = Logger.getLogger(SecurityUtil.class);
- public static final SecurityUtil INSTANCE = new SecurityUtil();
public static final String ALGORITHM = "AES";
public static final String CHARSET = UTF_8.name();
@@ -69,7 +68,7 @@ public class SecurityUtil {
}
// obfuscates key prefix -> **********
- public String obfuscateKey(String sensitiveData) {
+ public static String obfuscateKey(String sensitiveData) {
if (sensitiveData == null) {
return null;
@@ -176,7 +175,7 @@ public class SecurityUtil {
return Either.right("Decrypt FAILED");
}
- public Either<String, String> decrypt(String byteCipherText) {
+ public static Either<String, String> decrypt(String byteCipherText) {
try {
return decrypt(byteCipherText.getBytes(CHARSET), true);
} catch (UnsupportedEncodingException e) {
diff --git a/security-util-lib/src/main/java/org/onap/sdc/security/utils/RestUtils.java b/security-util-lib/src/main/java/org/onap/sdc/security/utils/RestUtils.java
index 2803720..5df9d8a 100644
--- a/security-util-lib/src/main/java/org/onap/sdc/security/utils/RestUtils.java
+++ b/security-util-lib/src/main/java/org/onap/sdc/security/utils/RestUtils.java
@@ -32,6 +32,8 @@ import java.util.Properties;
public class RestUtils {
+ private RestUtils() {}
+
public static void addBasicAuthHeader(Properties headers, String username, String password) {
headers.setProperty(HttpHeaders.AUTHORIZATION, getAuthHeaderValue(username,password));
}
@@ -49,7 +51,7 @@ public class RestUtils {
@VisibleForTesting
public static String decryptPassword(String password) {
validate(password);
- Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(password);
+ Either<String, String> passkey = SecurityUtil.decrypt(password);
if(passkey.isLeft()) {
return passkey.left().value();
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/AuthenticationCookieUtilsTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/AuthenticationCookieUtilsTest.java
index fdd354e..900afe2 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/AuthenticationCookieUtilsTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/AuthenticationCookieUtilsTest.java
@@ -20,29 +20,32 @@
package org.onap.sdc.security;
-import org.junit.Test;
-import org.onap.sdc.security.filters.SampleFilter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
-import javax.servlet.http.Cookie;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertTrue;
+import javax.servlet.http.Cookie;
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.security.filters.SampleFilter;
public class AuthenticationCookieUtilsTest {
- private SampleFilter sessionValidationFilter = new SampleFilter();
- private ISessionValidationFilterConfiguration filterCfg = sessionValidationFilter.getFilterConfiguration();
+ private final SampleFilter sessionValidationFilter = new SampleFilter();
+ private final ISessionValidationFilterConfiguration filterCfg = sessionValidationFilter.getFilterConfiguration();
@Test
- public void validateThatCookieCurrentSessionTimeIncreased() throws IOException, CipherUtilException, InterruptedException {
+ public void validateThatCookieCurrentSessionTimeIncreased()
+ throws IOException, CipherUtilException, InterruptedException {
// original cookie, pojo and servlet cookie
AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku");
- Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg ));
+ Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(),
+ AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal, filterCfg));
// cookie with increased time, pojo and servlet cookie
TimeUnit.SECONDS.sleep(1);
Cookie cookieWithIncreasedTime = AuthenticationCookieUtils.updateSessionTime(cookieWithOriginalTime, filterCfg);
- AuthenticationCookie authenticationCookieIncreasedTime = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithIncreasedTime, filterCfg);
+ AuthenticationCookie authenticationCookieIncreasedTime = AuthenticationCookieUtils
+ .getAuthenticationCookie(cookieWithIncreasedTime, filterCfg);
// validation
long currentSessionTimeOriginal = authenticationCookieOriginal.getCurrentSessionTime();
long currentSessionTimeIncreased = authenticationCookieIncreasedTime.getCurrentSessionTime();
@@ -53,23 +56,11 @@ public class AuthenticationCookieUtilsTest {
public void validateSerializationEncriptionDeserializationDecryption() throws IOException, CipherUtilException {
// original cookie, pojo and servlet cookie
AuthenticationCookie authenticationCookieOriginal = new AuthenticationCookie("kuku");
- Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal,filterCfg ));
+ Cookie cookieWithOriginalTime = new Cookie(filterCfg.getCookieName(),
+ AuthenticationCookieUtils.getEncryptedCookie(authenticationCookieOriginal, filterCfg));
// cookie with increased time, pojo and servlet cookie
- AuthenticationCookie decriptedAndDeserializedAuthenticationCookie = AuthenticationCookieUtils.getAuthenticationCookie(cookieWithOriginalTime,filterCfg);
- assertTrue(authenticationCookieOriginal.equals(decriptedAndDeserializedAuthenticationCookie));
+ AuthenticationCookie decriptedAndDeserializedAuthenticationCookie = AuthenticationCookieUtils
+ .getAuthenticationCookie(cookieWithOriginalTime, filterCfg);
+ assertEquals(authenticationCookieOriginal, decriptedAndDeserializedAuthenticationCookie);
}
-
-
-
-// @Test
-// public void getEncryptedCookie() {
-// }
-//
-// @Test
-// public void getAuthenticationCookie() {
-// }
-//
-// @Test
-// public void isSessionExpired() {
-// }
} \ No newline at end of file
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/CipherUtilTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/CipherUtilTest.java
index 9a6646c..e8d57a1 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/CipherUtilTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/CipherUtilTest.java
@@ -20,14 +20,13 @@
package org.onap.sdc.security;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.RandomStringUtils;
-import org.junit.Test;
-
-import java.util.Random;
-
-import static org.apache.commons.codec.binary.Base64.encodeBase64String;
-import static org.junit.Assert.*;
+import org.junit.jupiter.api.Test;
public class CipherUtilTest {
@@ -41,36 +40,34 @@ public class CipherUtilTest {
String encrypted = CipherUtil.encryptPKC(DATA, base64Key);
assertNotEquals(DATA, encrypted);
String decrypted = CipherUtil.decryptPKC(encrypted, base64Key);
- assertEquals(decrypted, DATA);
+ assertEquals(DATA, decrypted);
}
@Test
public void encryptInvalidKey() {
- try {
- CipherUtil.encryptPKC(DATA, "invalidKey");
- fail();
- } catch (CipherUtilException ex) {
- assertTrue(ex.getMessage().contains("Invalid AES key length"));
- }
+ assertThrows(
+ CipherUtilException.class,
+ () -> CipherUtil.encryptPKC(DATA, "invalidKey"),
+ "Invalid AES key length"
+ );
}
@Test
public void decryptInvalidKey() {
- try {
- CipherUtil.decryptPKC(DATA, "invalidKey");
- fail();
- } catch (CipherUtilException ex) {
- assertTrue(ex.getMessage().contains("length"));
- }
+ assertThrows(
+ CipherUtilException.class,
+ () -> CipherUtil.decryptPKC(DATA, "invalidKey"),
+ "length"
+
+ );
}
@Test
- public void decryptInvalidData() {
- try {
- CipherUtil.decryptPKC(DATA, KEY);
- fail();
- } catch (CipherUtilException ex) {
- assertTrue(ex.getMessage().contains("Input too short"));
- }
+ public void decryptInvalidData() {
+ assertThrows(
+ CipherUtilException.class,
+ () -> CipherUtil.decryptPKC(DATA, KEY),
+ "Input too short"
+ );
}
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/PasswordsTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/PasswordsTest.java
index f8c8452..ff5d0f1 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/PasswordsTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/PasswordsTest.java
@@ -20,39 +20,43 @@
package org.onap.sdc.security;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
+
public class PasswordsTest {
@Test
- public void hashPassword() throws Exception {
+ public void hashPassword() {
String hash = Passwords.hashPassword("hello1234");
assertTrue(Passwords.isExpectedPassword("hello1234", hash));
//test different salt-> result in different hash
String hash2 = Passwords.hashPassword("hello1234");
- assertFalse(hash.equals(hash2));
+ assertNotEquals(hash, hash2);
- String hash3 = Passwords.hashPassword("");
+ String hash3 = Passwords.hashPassword("");
assertTrue(Passwords.isExpectedPassword("", hash3));
- String hash4 = Passwords.hashPassword(null);
- assertTrue(hash4 == null);
+ String hash4 = Passwords.hashPassword(null);
+ assertNull(hash4);
}
@Test
- public void isExpectedPassword() throws Exception {
+ public void isExpectedPassword() {
//region isExpectedPassword(String password, String salt, String hash)
assertTrue(Passwords.isExpectedPassword(null, null, null));
//valid hash
- assertTrue(Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b", "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertTrue(Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b",
+ "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
//invalid salt
- assertFalse(Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c", "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
- assertFalse(Passwords.isExpectedPassword("hello1234", null, "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertFalse(Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c",
+ "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertFalse(Passwords
+ .isExpectedPassword("hello1234", null, "6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
//exacly 1 param uninitialized
assertFalse(Passwords.isExpectedPassword("hello1234", "", null));
assertFalse(Passwords.isExpectedPassword(null, "", "hello1234"));
@@ -63,9 +67,11 @@ public class PasswordsTest {
//region isExpectedPassword(String password, String expectedHash)
assertTrue(Passwords.isExpectedPassword(null, null));
//valid hash
- assertTrue(Passwords.isExpectedPassword("hello1234", "e0277df331f4ff8f74752ac4a8fbe03b:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertTrue(Passwords.isExpectedPassword("hello1234",
+ "e0277df331f4ff8f74752ac4a8fbe03b:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
//invalid salt
- assertFalse(Passwords.isExpectedPassword("hello1234", "c0000df331f4ff8f74752ac4a00be03c:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
+ assertFalse(Passwords.isExpectedPassword("hello1234",
+ "c0000df331f4ff8f74752ac4a00be03c:6dfbad308cdf53c9ff2ee2dca811ee92f1b359586b33027580e2ff92578edbd0"));
//exacly 1 param uninitialized
assertFalse(Passwords.isExpectedPassword("hello1234", null));
assertFalse(Passwords.isExpectedPassword(null, "hello1234"));
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/RepresentationUtilsTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/RepresentationUtilsTest.java
index 26c392e..a5a37d7 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/RepresentationUtilsTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/RepresentationUtilsTest.java
@@ -20,35 +20,36 @@
package org.onap.sdc.security;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
-
-import static org.junit.Assert.assertTrue;
+import org.junit.jupiter.api.Test;
public class RepresentationUtilsTest {
- private static AuthenticationCookie originalCookie = new AuthenticationCookie("kuku");
+ private static final AuthenticationCookie originalCookie = new AuthenticationCookie("kuku");
@Test
public void representationE2EwithRoleNull() throws IOException {
originalCookie.setRoles(null);
String jsonStr = RepresentationUtils.toRepresentation(originalCookie);
- AuthenticationCookie cookieFromJson = RepresentationUtils.fromRepresentation(jsonStr, AuthenticationCookie.class);
- assertTrue(originalCookie.equals(cookieFromJson));
+ AuthenticationCookie cookieFromJson = RepresentationUtils
+ .fromRepresentation(jsonStr, AuthenticationCookie.class);
+ assertEquals(originalCookie, cookieFromJson);
}
@Test
public void representationE2EwithRoleNotNull() throws IOException {
- Set<String> roles = new HashSet<String>();
+ Set<String> roles = new HashSet<>();
roles.add("Designer");
roles.add("Admin");
roles.add("Tester");
originalCookie.setRoles(roles);
String jsonStr = RepresentationUtils.toRepresentation(originalCookie);
- AuthenticationCookie cookieFromJson = RepresentationUtils.fromRepresentation(jsonStr, AuthenticationCookie.class);
- assertTrue(originalCookie.equals(cookieFromJson));
+ AuthenticationCookie cookieFromJson = RepresentationUtils
+ .fromRepresentation(jsonStr, AuthenticationCookie.class);
+ assertEquals(originalCookie, cookieFromJson);
}
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/RestUtilsTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/RestUtilsTest.java
index bc0ea6f..a55b45d 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/RestUtilsTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/RestUtilsTest.java
@@ -20,12 +20,15 @@
package org.onap.sdc.security;
-import org.apache.http.HttpHeaders;
-import org.junit.Test;
-import org.onap.sdc.security.utils.RestUtils;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Properties;
+import org.apache.http.HttpHeaders;
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.security.utils.RestUtils;
public class RestUtilsTest {
@@ -33,8 +36,8 @@ public class RestUtilsTest {
@Test
public void addBasicAuthHeaderTest() {
Properties headers = new Properties();
- String encryptedPassword = SecurityUtil.INSTANCE.encrypt("password").left().value();
- RestUtils.addBasicAuthHeader(headers, "userName",encryptedPassword);
+ String encryptedPassword = SecurityUtil.encrypt("password").left().value();
+ RestUtils.addBasicAuthHeader(headers, "userName", encryptedPassword);
String authHeader = headers.getProperty(HttpHeaders.AUTHORIZATION);
assertNotNull(authHeader);
assertTrue(authHeader.startsWith("Basic"));
@@ -43,18 +46,24 @@ public class RestUtilsTest {
@Test
public void decryptPasswordSuccessTest() {
String decryptedPassword = "password";
- String encryptedPassword = SecurityUtil.INSTANCE.encrypt(decryptedPassword).left().value();
+ String encryptedPassword = SecurityUtil.encrypt(decryptedPassword).left().value();
String resultPassword = RestUtils.decryptPassword(encryptedPassword);
assertEquals(decryptedPassword, resultPassword);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void decryptEmptyPasswordTest() {
- RestUtils.decryptPassword("");
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> RestUtils.decryptPassword("")
+ );
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void decryptInvalidPasswordTest() {
- RestUtils.decryptPassword("enc:9aS3AHtN_pR8QUGu-LPzHC7L8HO43WqOFx2s6nvrYrS");
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> RestUtils.decryptPassword("enc:9aS3AHtN_pR8QUGu-LPzHC7L8HO43WqOFx2s6nvrYrS")
+ );
}
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/SecurityUtilTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/SecurityUtilTest.java
index f0a21f0..67361a9 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/SecurityUtilTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/SecurityUtilTest.java
@@ -20,31 +20,30 @@
package org.onap.sdc.security;
-import org.junit.Test;
-
-import java.util.Base64;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import java.util.Base64;
+import org.junit.jupiter.api.Test;
+
public class SecurityUtilTest {
@Test
public void encryptDecryptAES128() {
String data = "decrypt SUCCESS!!";
- String encrypted = SecurityUtil.INSTANCE.encrypt(data).left().value();
- assertNotEquals( data, encrypted );
+ String encrypted = SecurityUtil.encrypt(data).left().value();
+ assertNotEquals(data, encrypted);
byte[] decryptMsg = Base64.getDecoder().decode(encrypted);
- assertEquals( SecurityUtil.INSTANCE.decrypt( decryptMsg , false ).left().value() ,data );
- assertEquals( SecurityUtil.INSTANCE.decrypt( encrypted.getBytes() , true ).left().value() ,data );
+ assertEquals(SecurityUtil.decrypt(decryptMsg, false).left().value(), data);
+ assertEquals(SecurityUtil.decrypt(encrypted.getBytes(), true).left().value(), data);
}
@Test
public void obfuscateKey() {
String key = "abcdefghij123456";
String expectedkey = "********ij123456";
- String obfuscated = SecurityUtil.INSTANCE.obfuscateKey( key );
- System.out.println( obfuscated );
- assertEquals( obfuscated , expectedkey );
+ String obfuscated = SecurityUtil.obfuscateKey(key);
+ System.out.println(obfuscated);
+ assertEquals(obfuscated, expectedkey);
}
} \ No newline at end of file
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/filters/RestrictionAccessFilterTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/filters/RestrictionAccessFilterTest.java
index 20f0d05..6fe7926 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/filters/RestrictionAccessFilterTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/filters/RestrictionAccessFilterTest.java
@@ -20,187 +20,193 @@
package org.onap.sdc.security.filters;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.sdc.security.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
-import javax.servlet.http.Cookie;
-import java.io.IOException;
-import java.security.InvalidParameterException;
import java.util.HashSet;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import javax.servlet.http.Cookie;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.sdc.security.AuthenticationCookie;
+import org.onap.sdc.security.ISessionValidationFilterConfiguration;
+import org.onap.sdc.security.IUsersThreadLocalHolder;
+import org.onap.sdc.security.PortalClient;
+import org.onap.sdc.security.RedirectException;
-@RunWith(MockitoJUnitRunner.class)
-public class RestrictionAccessFilterTest {
- private static final String jsonResponseFromPortal = "{\"orgId\":null,\"managerId\":null,\"firstName\":\"NAME\",\"middleInitial\":null,\"lastName\":\"FAMILY\",\"phone\":null,\"email\":\"abc123@test.com\",\"hrid\":null,\"orgUserId\":\"abc123\",\"orgCode\":null,\"orgManagerUserId\":null,\"jobTitle\":null," +
- "\"loginId\":\"abc123\",\"active\":true,\"roles\":[%s]}";
- private static final String rolesJson = "{\"id\":\"1234\",\"name\":\"designer\",\"roleFunctions\":[\"read\",\"write\"]}";
+public class RestrictionAccessFilterTest {
private static final String userId = "abc123";
- @Mock
- private CloseableHttpClient httpClient;
- @Mock
- private ISessionValidationFilterConfiguration configuration;
- @Mock
- private ISessionValidationCookieConfiguration cookieConfig;
- @Mock
- private IUsersThreadLocalHolder threadLocalUtils;
- @Mock
- private AuthenticationCookie authenticationCookie;
- @Mock
- private PortalClient portalClient;
+ private final ISessionValidationFilterConfiguration configuration = Mockito
+ .mock(ISessionValidationFilterConfiguration.class);
+
+ private final IUsersThreadLocalHolder threadLocalUtils = Mockito.mock(IUsersThreadLocalHolder.class);
+
+ private final AuthenticationCookie authenticationCookie = Mockito.mock(AuthenticationCookie.class);
+
+ private final PortalClient portalClient = Mockito.mock(PortalClient.class);
private RestrictionAccessFilter filter;
- @Before
+ @BeforeEach
public void setUp() {
mockCreateFilter(configuration, threadLocalUtils, portalClient);
assertNotNull(filter);
}
- private void mockCreateFilter(ISessionValidationFilterConfiguration sessionConfig, IUsersThreadLocalHolder threadLocalUtils, PortalClient portalClient) {
+ private void mockCreateFilter(ISessionValidationFilterConfiguration sessionConfig,
+ IUsersThreadLocalHolder threadLocalUtils, PortalClient portalClient) {
filter = new RestrictionAccessFilter(sessionConfig, threadLocalUtils, portalClient);
}
-// @Test(expected = InvalidParameterException.class)
-// public void filterConfigurationObjectCreationFailedWhenPropertyIsNotSet() {
-// when(configuration.getAuthCookie()).thenReturn(cookieConfig);
-// when(cookieConfig.getRedirectURL()).thenReturn("does_not_exist");
-// filter = new RestrictionAccessFilter(configuration, portalClient, threadLocalUtils);
-// }
-
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUsersDifferent() throws RedirectException {
- Cookie[] cookies = new Cookie [1] ;
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUsersDifferent() {
+ Cookie[] cookies = new Cookie[1];
cookies[0] = new Cookie(RestrictionAccessFilter.CSP_USER_ID, "user1");
- filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ assertThrows(
+ RedirectException.class,
+ () -> filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUserRolesDifferent() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUserRolesDifferent() {
when(authenticationCookie.getUserID()).thenReturn(userId);
RestrictionAccessFilter spyFilter2 = spy(filter);
HashSet<String> roles = new HashSet<>();
roles.add("b");
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
when(authenticationCookie.getRoles()).thenReturn(roles);
- spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ assertThrows(
+ RedirectException.class,
+ () -> spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUserRolesDisappearInCookie() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUserRolesDisappearInCookie() {
when(authenticationCookie.getUserID()).thenReturn(userId);
RestrictionAccessFilter spyFilter2 = spy(filter);
HashSet<String> roles = new HashSet<>();
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
when(authenticationCookie.getRoles()).thenReturn(roles);
- spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ assertThrows(
+ RedirectException.class,
+ () -> spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUserRolesRetrievedFromPortalAndMatch() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUserRolesRetrievedFromPortalAndMatch() {
when(authenticationCookie.getUserID()).thenReturn(userId);
- PortalClient spyFilter = spy(portalClient);
RestrictionAccessFilter spyFilter2 = spy(filter);
HashSet<String> roles = new HashSet<>();
roles.add("DESIGNER");
when(authenticationCookie.getRoles()).thenReturn(roles);
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
- spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
+ assertThrows(
+ RedirectException.class,
+ () -> spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUserRolesRetrievedFromPortalAndEmpty() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUserRolesRetrievedFromPortalAndEmpty() {
HashSet<String> roles = new HashSet<>();
roles.add("b");
when(authenticationCookie.getUserID()).thenReturn(userId);
when(authenticationCookie.getRoles()).thenReturn(roles);
- PortalClient spyFilter = spy(portalClient);
RestrictionAccessFilter spyFilter2 = spy(filter);
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
- spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
+ assertThrows(
+ RedirectException.class,
+ () -> spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenUserRolesCantBeRetrievedFromPortal() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenUserRolesCantBeRetrievedFromPortal() {
HashSet<String> roles = new HashSet<>();
roles.add("b");
when(authenticationCookie.getUserID()).thenReturn(userId);
when(authenticationCookie.getRoles()).thenReturn(roles);
RestrictionAccessFilter spyFilter2 = spy(filter);
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
- spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
+ assertThrows(
+ RedirectException.class,
+ () -> spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
-// @Test (expected = RedirectException.class)
-// public void authorizeUserOnSessionExpirationWhenHttpRequestFailed() throws RedirectException, IOException, RestrictionAccessFilterException {
-// HashSet<String> roles = new HashSet<>();
-// roles.add("b");
-// when(authenticationCookie.getUserID()).thenReturn(userId);
-// when(authenticationCookie.getRoles()).thenReturn(roles);
-//// PortalClient spyFilter = spy(portalClient);
-// RestrictionAccessFilter spyFilter2 = spy(filter);
-//// when(spyFilter.fetchUserRolesFromPortal()*/
-// doThrow(IOException.class).when(portalClient).fetchUserRolesFromPortal(eq(userId));
-// Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId)};
-// spyFilter2.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
-// }
-
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenCspUserCookieIsNull() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenCspUserCookieIsNull() {
when(authenticationCookie.getUserID()).thenReturn(userId);
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, null)};
- filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, null)};
+ assertThrows(
+ RedirectException.class,
+ () -> filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
- @Test (expected = RedirectException.class)
- public void authorizeUserOnSessionExpirationWhenCookieNotFound() throws RedirectException, IOException {
+ @Test
+ public void authorizeUserOnSessionExpirationWhenCookieNotFound() {
assertNotNull(filter);
- Cookie[] cookies = new Cookie [] {new Cookie("someCookie", userId)};
- filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies);
+ Cookie[] cookies = new Cookie[]{new Cookie("someCookie", userId)};
+ assertThrows(
+ RedirectException.class,
+ () -> filter.authorizeUserOnSessionExpiration(authenticationCookie, cookies)
+ );
}
@Test
public void getCspUserIdWhenMoreThanOneUserIdExists() throws RedirectException {
- Cookie[] cookies = new Cookie [] {
- new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId),
- new Cookie(RestrictionAccessFilter.CSP_USER_ID, "other")};
+ Cookie[] cookies = new Cookie[]{
+ new Cookie(RestrictionAccessFilter.CSP_USER_ID, userId),
+ new Cookie(RestrictionAccessFilter.CSP_USER_ID, "other")};
assertEquals(userId, filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID));
}
- @Test()
+ @Test
public void getCspUserIdWhenUserIdIsNull() throws RedirectException {
- Cookie[] cookies = new Cookie [] {new Cookie(RestrictionAccessFilter.CSP_USER_ID, null)} ;
+ Cookie[] cookies = new Cookie[]{new Cookie(RestrictionAccessFilter.CSP_USER_ID, null)};
assertNull(filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID));
}
- @Test(expected=RedirectException.class)
- public void getCspUserIdWhenUserIdCookieNotFound() throws RedirectException {
- Cookie[] cookies = new Cookie [] {new Cookie("someName", "someValue")} ;
- filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID);
+ @Test
+ public void getCspUserIdWhenUserIdCookieNotFound() {
+ Cookie[] cookies = new Cookie[]{new Cookie("someName", "someValue")};
+ assertThrows(
+ RedirectException.class,
+ () -> filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID)
+ );
}
- @Test(expected=RedirectException.class)
- public void getCspUserIdWhenNoCookiesFound() throws RedirectException {
- Cookie[] cookies = new Cookie [] {};
- filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID);
+ @Test
+ public void getCspUserIdWhenNoCookiesFound() {
+ Cookie[] cookies = new Cookie[]{};
+ assertThrows(
+ RedirectException.class,
+ () -> filter.getCookieValue(cookies, RestrictionAccessFilter.CSP_USER_ID)
+ );
}
- @Test(expected=RedirectException.class)
- public void getCspUserIdWhenCookiesNull() throws RedirectException {
- filter.getCookieValue(null, RestrictionAccessFilter.CSP_USER_ID);
+ @Test
+ public void getCspUserIdWhenCookiesNull() {
+ assertThrows(
+ RedirectException.class,
+ () -> filter.getCookieValue(null, RestrictionAccessFilter.CSP_USER_ID)
+ );
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/filters/SessionValidationFilterTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/filters/SessionValidationFilterTest.java
index 9c5fd89..c92d086 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/filters/SessionValidationFilterTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/filters/SessionValidationFilterTest.java
@@ -20,52 +20,43 @@
package org.onap.sdc.security.filters;
-import org.junit.Before;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.sdc.security.AuthenticationCookie;
-import org.onap.sdc.security.AuthenticationCookieUtils;
-import org.onap.sdc.security.CipherUtilException;
-import org.onap.sdc.security.RepresentationUtils;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
+import org.junit.FixMethodOrder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.runners.MethodSorters;
+import org.mockito.Mockito;
+import org.onap.sdc.security.AuthenticationCookie;
+import org.onap.sdc.security.AuthenticationCookieUtils;
+import org.onap.sdc.security.CipherUtilException;
+import org.onap.sdc.security.RepresentationUtils;
-@RunWith(MockitoJUnitRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SessionValidationFilterTest {
- @Mock
- private HttpServletRequest request;
- @Spy
- private HttpServletResponse response;
- @Mock
- private FilterChain filterChain;
- @Mock
- private FilterConfig filterConfig;
+
+ private final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
+
+ private final HttpServletResponse response = Mockito.spy(HttpServletResponse.class);
+
+ private final FilterChain filterChain = Mockito.mock(FilterChain.class);
+
+ private final FilterConfig filterConfig = Mockito.mock(FilterConfig.class);
// implementation of SessionValidationFilter
- @InjectMocks
- @Spy
- private SampleFilter sessionValidationFilter = new SampleFilter();
+ private final SampleFilter sessionValidationFilter = Mockito.spy(SampleFilter.class);
- @Before
- public void setUpClass() throws ServletException {
+ @BeforeEach
+ public void setUpClass() {
sessionValidationFilter.init(filterConfig);
}
@@ -111,23 +102,28 @@ public class SessionValidationFilterTest {
@Test
public void noCookiesWithCorrectNameInRequest() throws IOException, ServletException {
when(request.getPathInfo()).thenReturn("/resource");
- String newNameNotContainsRealName = sessionValidationFilter.getFilterConfiguration().getCookieName().substring(1);
- Cookie cookie = new Cookie("fake" + newNameNotContainsRealName + "fake2", RepresentationUtils.toRepresentation(new AuthenticationCookie("kuku")));
+ String newNameNotContainsRealName = sessionValidationFilter.getFilterConfiguration().getCookieName()
+ .substring(1);
+ Cookie cookie = new Cookie("fake" + newNameNotContainsRealName + "fake2",
+ RepresentationUtils.toRepresentation(new AuthenticationCookie("kuku")));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
Mockito.verify(sessionValidationFilter, times(1)).handleRedirectException(response);
}
@Test
- public void cookieMaxSessionTimedOutAndUserIsNotAuthorized() throws IOException, ServletException, CipherUtilException {
+ public void cookieMaxSessionTimedOutAndUserIsNotAuthorized()
+ throws IOException, ServletException, CipherUtilException {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie(SampleFilter.FAILED_ON_USER_AUTH);
// set max session time to timout value
long maxSessionTimeOut = sessionValidationFilter.getFilterConfiguration().getMaxSessionTimeOut();
long startTime = authenticationCookie.getMaxSessionTime();
- long timeout = startTime - maxSessionTimeOut - 1000l;
+ long timeout = startTime - maxSessionTimeOut - 1000L;
authenticationCookie.setMaxSessionTime(timeout);
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -135,15 +131,18 @@ public class SessionValidationFilterTest {
}
@Test
- public void cookieMaxSessionTimedOutAndUserIsAuthorized() throws IOException, ServletException, CipherUtilException {
+ public void cookieMaxSessionTimedOutAndUserIsAuthorized()
+ throws IOException, ServletException, CipherUtilException {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie("userId");
// set max session time to timout value
long maxSessionTimeOut = sessionValidationFilter.getFilterConfiguration().getMaxSessionTimeOut();
long startTime = authenticationCookie.getMaxSessionTime();
- long timeout = startTime - maxSessionTimeOut - 1000l;
+ long timeout = startTime - maxSessionTimeOut - 1000L;
authenticationCookie.setMaxSessionTime(timeout);
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -159,7 +158,9 @@ public class SessionValidationFilterTest {
long sessionStartTime = authenticationCookie.getCurrentSessionTime();
long timeout = sessionStartTime - idleSessionTimeOut - 2000;
authenticationCookie.setCurrentSessionTime(timeout);
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -175,7 +176,9 @@ public class SessionValidationFilterTest {
long sessionStartTime = authenticationCookie.getCurrentSessionTime();
long timeout = sessionStartTime - idleSessionTimeOut - 2000;
authenticationCookie.setCurrentSessionTime(timeout);
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -183,10 +186,13 @@ public class SessionValidationFilterTest {
}
@Test
- public void cookieSessionIsNotExpiredRoleAssignmentDone() throws IOException, ServletException, CipherUtilException {
+ public void cookieSessionIsNotExpiredRoleAssignmentDone()
+ throws IOException, ServletException, CipherUtilException {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie(SampleFilter.FAILED_ON_ROLE);
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -199,20 +205,25 @@ public class SessionValidationFilterTest {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie("kuku");
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
Mockito.verify(filterChain, times(1)).doFilter(request, response);
}
-// test validate contains
+ // test validate contains
@Test
- public void requestThatPassFilterWithCookieNameAsPartOfOtherString() throws IOException, ServletException, CipherUtilException {
+ public void requestThatPassFilterWithCookieNameAsPartOfOtherString()
+ throws IOException, ServletException, CipherUtilException {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie("kuku");
- Cookie cookie = new Cookie("some" +sessionValidationFilter.getFilterConfiguration().getCookieName() + "Thing", AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie("some" + sessionValidationFilter.getFilterConfiguration().getCookieName() + "Thing",
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
sessionValidationFilter.doFilter(request, response, filterChain);
@@ -224,7 +235,9 @@ public class SessionValidationFilterTest {
when(request.getPathInfo()).thenReturn("/resource");
AuthenticationCookie authenticationCookie = new AuthenticationCookie("kuku");
- Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(), AuthenticationCookieUtils.getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
+ Cookie cookie = new Cookie(sessionValidationFilter.getFilterConfiguration().getCookieName(),
+ AuthenticationCookieUtils
+ .getEncryptedCookie(authenticationCookie, sessionValidationFilter.getFilterConfiguration()));
when(request.getCookies()).thenReturn(new Cookie[]{cookie});
String oldKey = sessionValidationFilter.getFilterConfiguration().getSecurityKey();
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java
index bb95d15..ea1f6b7 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/elements/LogFieldsMdcHandlerTest.java
@@ -14,16 +14,6 @@
*/
package org.onap.sdc.security.logging.elements;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.sdc.security.logging.api.ILogConfiguration;
-import org.onap.sdc.security.logging.enums.EcompHeadersConstants;
-import org.onap.sdc.security.logging.enums.Severity;
-import org.slf4j.MDC;
-
-import javax.servlet.http.HttpServletRequest;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -37,12 +27,22 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import javax.servlet.http.HttpServletRequest;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.sdc.security.logging.api.ILogConfiguration;
+import org.onap.sdc.security.logging.enums.EcompHeadersConstants;
+import org.onap.sdc.security.logging.enums.Severity;
+import org.slf4j.MDC;
+
public class LogFieldsMdcHandlerTest {
+
LogFieldsMdcHandler instanceMdcWrapper;
LogFieldsMdcHandler spy;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp() {
LogFieldsMdcHandler.hostAddress = "TestHost";
LogFieldsMdcHandler.fqdn = "Test";
instanceMdcWrapper = LogFieldsMdcHandler.getInstance();
@@ -144,7 +144,7 @@ public class LogFieldsMdcHandlerTest {
spy.setAlertSeverity(Severity.CRITICAL);
verify(spy, times(1)).setAlertSeverity(any(Severity.class));
assertEquals(String.valueOf(Severity.CRITICAL.getSeverityType()),
- MDC.get(ONAPLogConstants.MDCs.RESPONSE_SEVERITY));
+ MDC.get(ONAPLogConstants.MDCs.RESPONSE_SEVERITY));
}
@Test
@@ -441,7 +441,7 @@ public class LogFieldsMdcHandlerTest {
public void collectRequestInfoForErrorAndDebugLogging() {
HttpServletRequest httpRequest = mock(HttpServletRequest.class);
when(httpRequest.getHeader(EcompHeadersConstants.X_ECOMP_SERVICE_ID_HEADER)).thenReturn(
- "MockServiceInstanceID");
+ "MockServiceInstanceID");
when(httpRequest.getHeader(EcompHeadersConstants.USER_ID_HEADER)).thenReturn("Mock_User");
when(httpRequest.getRemoteHost()).thenReturn("Test_Host");
when(httpRequest.getLocalAddr()).thenReturn("172.0.0.0");
@@ -450,12 +450,12 @@ public class LogFieldsMdcHandlerTest {
spy.collectRequestInfoForErrorAndDebugLogging(httpRequest);
verify(spy, times(1)).
- collectRequestInfoForErrorAndDebugLogging(any(HttpServletRequest.class));
+ collectRequestInfoForErrorAndDebugLogging(any(HttpServletRequest.class));
assertEquals("Test_Service", spy.getServiceName());
assertEquals("Test_ID", spy.getKeyRequestId());
assertEquals("Test_Host", spy.getRemoteHost());
assertEquals("172.0.0.0", spy.getServerIpAddress());
- assertEquals("MockServiceInstanceID", MDC.get(ILogConfiguration.MDC_SERVICE_INSTANCE_ID) );
+ assertEquals("MockServiceInstanceID", MDC.get(ILogConfiguration.MDC_SERVICE_INSTANCE_ID));
assertEquals("Mock_User", spy.getPartnerName());
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/EcompLoggerErrorCodeTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/EcompLoggerErrorCodeTest.java
index 1bdbddf..2522c11 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/EcompLoggerErrorCodeTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/EcompLoggerErrorCodeTest.java
@@ -24,7 +24,7 @@
package org.onap.sdc.security.logging.enums;
import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class EcompLoggerErrorCodeTest {
@@ -32,19 +32,19 @@ public class EcompLoggerErrorCodeTest {
public void getByValueTest() {
EcompLoggerErrorCode ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_0");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 0);
+ Assert.assertEquals(0, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_100");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 100);
+ Assert.assertEquals(100, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_200");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 200);
+ Assert.assertEquals(200, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_300");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 300);
+ Assert.assertEquals(300, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_400");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 400);
+ Assert.assertEquals(400, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("E_500");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 500);
+ Assert.assertEquals(500, ecompLoggerErrorCode.getErrorCode());
ecompLoggerErrorCode = EcompLoggerErrorCode.getByValue("none");
- Assert.assertEquals(ecompLoggerErrorCode.getErrorCode(), 900);
+ Assert.assertEquals(900, ecompLoggerErrorCode.getErrorCode());
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/LoggerSupportabilityActionsTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/LoggerSupportabilityActionsTest.java
index 5f63c7a..b36ad72 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/LoggerSupportabilityActionsTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/LoggerSupportabilityActionsTest.java
@@ -21,25 +21,24 @@
*/
package org.onap.sdc.security.logging.enums;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
+
public class LoggerSupportabilityActionsTest {
@Test
public void testGetName() {
- assertEquals(LoggerSupportabilityActions.ARCHIVE.getName(), "ARCHIVE");
- assertEquals(LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI.getName(),
- "ASSOCIATE RI TO RI");
- assertEquals(LoggerSupportabilityActions.CHANGELIFECYCLESTATE.getName(),
- "CHANGE LIFECYCLE STATE");
- assertEquals(LoggerSupportabilityActions.CREATE_ARTIFACTS.getName(), "ADD ARTIFACTS");
- assertEquals(LoggerSupportabilityActions.CREATE_CAPABILITY_REQUIREMENTS.getName(),
- "CREATE CAPABILITY REQUIREMENTS");
- assertEquals(LoggerSupportabilityActions.CREATE_GROUP_POLICY.getName(), "ADD GROUP POLICY");
- assertEquals(LoggerSupportabilityActions.CREATE_GROUPS.getName(), "ADD GROUPS");
-
+ assertEquals("ARCHIVE", LoggerSupportabilityActions.ARCHIVE.getName());
+ assertEquals("ASSOCIATE RI TO RI",
+ LoggerSupportabilityActions.ASSOCIATE_RI_TO_RI.getName());
+ assertEquals("CHANGE LIFECYCLE STATE",
+ LoggerSupportabilityActions.CHANGELIFECYCLESTATE.getName());
+ assertEquals("ADD ARTIFACTS", LoggerSupportabilityActions.CREATE_ARTIFACTS.getName());
+ assertEquals("CREATE CAPABILITY REQUIREMENTS",
+ LoggerSupportabilityActions.CREATE_CAPABILITY_REQUIREMENTS.getName());
+ assertEquals("ADD GROUP POLICY", LoggerSupportabilityActions.CREATE_GROUP_POLICY.getName());
+ assertEquals("ADD GROUPS", LoggerSupportabilityActions.CREATE_GROUPS.getName());
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/SeverityTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/SeverityTest.java
index 7ef4190..dff7665 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/SeverityTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/SeverityTest.java
@@ -22,18 +22,18 @@
package org.onap.sdc.security.logging.enums;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
+
public class SeverityTest {
@Test
public void testGetSeverityType() {
- assertEquals(Severity.OK.getSeverityType(), 0);
- assertEquals(Severity.WARNING.getSeverityType(), 1);
- assertEquals(Severity.CRITICAL.getSeverityType(), 2);
- assertEquals(Severity.DOWN.getSeverityType(), 3);
- assertEquals(Severity.UNREACHABLE.getSeverityType(), 4);
+ assertEquals(0, Severity.OK.getSeverityType());
+ assertEquals(1, Severity.WARNING.getSeverityType());
+ assertEquals(2, Severity.CRITICAL.getSeverityType());
+ assertEquals(3, Severity.DOWN.getSeverityType());
+ assertEquals(4, Severity.UNREACHABLE.getSeverityType());
}
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/StatusCodeTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/StatusCodeTest.java
index 72cf01c..1fefec5 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/StatusCodeTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/enums/StatusCodeTest.java
@@ -22,18 +22,18 @@
package org.onap.sdc.security.logging.enums;
-import org.junit.Test;
-
import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
+
public class StatusCodeTest {
@Test
public void testGetStatusCodeEnum() {
- assertEquals(StatusCode.ERROR.getStatusCodeEnum(), "ERROR");
- assertEquals(StatusCode.STARTED.getStatusCodeEnum(), "STARTED");
- assertEquals(StatusCode.COMPLETE.getStatusCodeEnum(), "COMPLETE");
- assertEquals(StatusCode.INPROGRESS.getStatusCodeEnum(), "INPROGRESS");
+ assertEquals("ERROR", StatusCode.ERROR.getStatusCodeEnum());
+ assertEquals("STARTED", StatusCode.STARTED.getStatusCodeEnum());
+ assertEquals("COMPLETE", StatusCode.COMPLETE.getStatusCodeEnum());
+ assertEquals("INPROGRESS", StatusCode.INPROGRESS.getStatusCodeEnum());
}
}
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcAuditTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcAuditTest.java
index a8eab4c..67412b4 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcAuditTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcAuditTest.java
@@ -14,22 +14,6 @@
*/
package org.onap.sdc.security.logging.wrappers;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.sdc.security.logging.enums.LogLevel;
-import org.onap.sdc.security.logging.enums.Severity;
-import org.slf4j.MDC;
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.net.URISyntaxException;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -41,18 +25,34 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.sdc.security.logging.enums.LogLevel;
+import org.onap.sdc.security.logging.enums.Severity;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
public class LoggerSdcAuditTest {
+
LoggerSdcAudit spy;
private Marker marker;
- @Before
+ @BeforeEach
public void setUp() {
LoggerSdcAudit audit = new LoggerSdcAudit(this.getClass());
spy = spy(audit);
marker = MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName());
}
- @After
+ @AfterEach
public void tearDown() {
MDC.clear();
}
@@ -106,7 +106,7 @@ public class LoggerSdcAuditTest {
spy.logExit("172.0.0.0", mockContext, mockStatus, LogLevel.INFO, Severity.WARNING, "MockMessage", marker);
assertEquals("false", MDC.get("auditOn"));
verify(spy, times(1)).logExit(anyString(), any(ContainerRequestContext.class), any(Response.StatusType.class)
- , any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class));
+ , any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class));
}
@Test
@@ -124,7 +124,7 @@ public class LoggerSdcAuditTest {
spy.logEntry("172.0.0.0", mockContext, LogLevel.INFO, Severity.WARNING, "MockMessage", marker);
assertEquals("false", MDC.get("auditOn"));
verify(spy, times(1)).logEntry(anyString(), any(ContainerRequestContext.class)
- , any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class));
+ , any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class));
}
@Test
@@ -132,6 +132,6 @@ public class LoggerSdcAuditTest {
spy.logEntry(LogLevel.INFO, Severity.WARNING, "MockMessage", marker, "RequestID");
assertEquals("false", MDC.get("auditOn"));
verify(spy, times(1))
- .logEntry(any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class), anyString());
+ .logEntry(any(LogLevel.class), any(Severity.class), anyString(), any(Marker.class), anyString());
}
} \ No newline at end of file
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcUtilBaseTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcUtilBaseTest.java
index 10b88c5..7c16999 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcUtilBaseTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerSdcUtilBaseTest.java
@@ -14,24 +14,12 @@
*/
package org.onap.sdc.security.logging.wrappers;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.sdc.security.logging.enums.EcompLoggerErrorCode;
-
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.core.UriInfo;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -40,10 +28,21 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.security.logging.enums.EcompLoggerErrorCode;
+
public class LoggerSdcUtilBaseTest {
+
private LoggerSdcUtilBase spy;
- @Before
+ @BeforeEach
public void setUp() {
LoggerSdcUtilBase loggerSdcUtilBase = new LoggerSdcUtilBase();
spy = spy(loggerSdcUtilBase);
@@ -60,7 +59,7 @@ public class LoggerSdcUtilBaseTest {
@Test
public void convertHttpCodeToErrorCode() {
- assertEquals( EcompLoggerErrorCode.SUCCESS ,spy.convertHttpCodeToErrorCode(398));
+ assertEquals(EcompLoggerErrorCode.SUCCESS, spy.convertHttpCodeToErrorCode(398));
assertEquals(EcompLoggerErrorCode.SCHEMA_ERROR, spy.convertHttpCodeToErrorCode(409));
assertEquals(EcompLoggerErrorCode.UNKNOWN_ERROR, spy.convertHttpCodeToErrorCode(421));
assertEquals(EcompLoggerErrorCode.DATA_ERROR, spy.convertHttpCodeToErrorCode(415));
diff --git a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java
index 1288578..0912920 100644
--- a/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java
+++ b/security-util-lib/src/test/java/org/onap/sdc/security/logging/wrappers/LoggerTest.java
@@ -14,18 +14,6 @@
*/
package org.onap.sdc.security.logging.wrappers;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
-import org.onap.sdc.security.logging.elements.ErrorLogOptionalData;
-import org.onap.sdc.security.logging.enums.EcompErrorSevirity;
-import org.onap.sdc.security.logging.enums.EcompLoggerErrorCode;
-import org.slf4j.Marker;
-import org.slf4j.MarkerFactory;
-
-import java.util.Arrays;
-import java.util.List;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -37,14 +25,26 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.sdc.security.logging.elements.ErrorLogOptionalData;
+import org.onap.sdc.security.logging.enums.EcompErrorSevirity;
+import org.onap.sdc.security.logging.enums.EcompLoggerErrorCode;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
public class LoggerTest {
+
Logger log;
Logger spy;
Marker marker;
List<String> testList;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp() {
testList = Arrays.asList("Item1", "Item2");
marker = MarkerFactory.getMarker(ONAPLogConstants.Markers.ENTRY.getName());
log = Logger.getLogger(LoggerTest.class.getName());
@@ -96,38 +96,42 @@ public class LoggerTest {
@Test
public void testInfoWithObject() {
- spy.info("Test Info log", testList);
- verify(spy, times(1)).info("Test Info log", testList);
+ spy.info("Test Info log - {}", testList);
+ verify(spy, times(1)).info("Test Info log - {}", testList);
}
@Test
public void testInfoWith2Object() {
- spy.info("Test Info log", testList, testList);
- verify(spy, times(1)).info("Test Info log", testList, testList);
+ spy.info("Test Info log - {} - {}", testList, testList);
+ verify(spy, times(1)).info("Test Info log - {} - {}", testList, testList);
}
@Test
public void debug() {
- spy.debug("Test DEBUG log", testList);
+ spy.debug("Test DEBUG log - {}", testList);
verify(spy, times(1)).debug(anyString(), any(Object.class));
}
@Test
public void metric() {
- spy.metric("Test metric log", testList);
+ spy.metric("Test metric log - {}", testList);
verify(spy, times(1)).metric(anyString(), any(Object.class));
}
@Test
public void invoke() {
spy.invoke("Test Host", "Test Entity", "Test Service", "Test metric log", testList, testList, testList);
- verify(spy, times(1)).invoke(anyString(), anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ verify(spy, times(1))
+ .invoke(anyString(), anyString(), anyString(), anyString(), anyCollection(), anyCollection(),
+ anyCollection());
}
@Test
public void invokeReturn() {
spy.invokeReturn(ONAPLogConstants.ResponseStatus.ERROR, "Test metric log", testList, testList, testList);
- verify(spy, times(1)).invokeReturn(any(ONAPLogConstants.ResponseStatus.class), anyString(), anyCollection(), anyCollection(), anyCollection());
+ verify(spy, times(1))
+ .invokeReturn(any(ONAPLogConstants.ResponseStatus.class), anyString(), anyCollection(), anyCollection(),
+ anyCollection());
}
@Test
@@ -161,19 +165,19 @@ public class LoggerTest {
@Test
public void testDebugMarkerWithParam() {
- spy.debug(marker, "Test marker debug log", testList);
+ spy.debug(marker, "Test marker debug log - {}", testList);
verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection());
}
@Test
public void testDebugMarkerWithMultipleObjects() {
- spy.debug(marker, "Test marker debug log", testList, testList, testList);
+ spy.debug(marker, "Test marker debug log - {} - {} - {}", testList, testList, testList);
verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testDebugWithMarker2Params() {
- spy.debug(marker, "Test marker debug log", testList, testList);
+ spy.debug(marker, "Test marker debug log - {} - {}", testList, testList);
verify(spy, times(1)).debug(any(Marker.class), anyString(), anyCollection(), anyCollection());
}
@@ -191,19 +195,19 @@ public class LoggerTest {
@Test
public void testDebugWithParam() {
- spy.debug("Test debug log", testList);
+ spy.debug("Test debug log - {}", testList);
verify(spy, times(1)).debug(anyString(), anyCollection());
}
@Test
public void testDebugWith2Params() {
- spy.debug("Test debug log", testList, testList);
+ spy.debug("Test debug log - {} - {}", testList, testList);
verify(spy, times(1)).debug(anyString(), anyCollection(), anyCollection());
}
@Test
public void trace() {
- spy.trace("Test trace log", testList, testList, testList);
+ spy.trace("Test trace log - {} - {} - {}", testList, testList, testList);
verify(spy, times(1)).trace(anyString(), anyCollection(), anyCollection(), anyCollection());
}
@@ -226,19 +230,19 @@ public class LoggerTest {
@Test
public void testTraceMarkerWithParam() {
- spy.trace(marker, "Test trace log", testList);
+ spy.trace(marker, "Test trace log - {}", testList);
verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection());
}
@Test
public void testTraceMarkerWith2Params() {
- spy.trace(marker, "Test trace log", testList, testList);
+ spy.trace(marker, "Test trace log - {} - {}", testList, testList);
verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection(), anyCollection());
}
@Test
public void testTraceMarkerWithMultipleParams() {
- spy.trace(marker, "Test trace log", testList, testList, testList);
+ spy.trace(marker, "Test trace log - {} - {} - {}", testList, testList, testList);
verify(spy, times(1)).trace(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@@ -256,19 +260,19 @@ public class LoggerTest {
@Test
public void testTraceWithParam() {
- spy.trace("Test trace log", testList);
+ spy.trace("Test trace log - {}", testList);
verify(spy, times(1)).trace(anyString(), anyCollection());
}
@Test
public void testTraceWith2Params() {
- spy.trace("Test trace log", testList, testList);
+ spy.trace("Test trace log - {} - {}", testList, testList);
verify(spy, times(1)).trace(anyString(), anyCollection(), anyCollection());
}
@Test
public void testInfoWithMultipleObjects() {
- spy.info("Test Info log", testList, testList, testList);
+ spy.info("Test Info log - {} - {} - {}", testList, testList, testList);
verify(spy, times(1)).info(anyString(), anyCollection(), anyCollection(), anyCollection());
}
@@ -291,19 +295,19 @@ public class LoggerTest {
@Test
public void testInfoMarkerWithParam() {
- spy.info(marker, "Test info log", testList);
+ spy.info(marker, "Test info log - {}", testList);
verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection());
}
@Test
public void testInfoMarkerWith2Params() {
- spy.info(marker, "Test info log", testList, testList);
+ spy.info(marker, "Test info log - {} - {}", testList, testList);
verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection(), anyCollection());
}
@Test
public void testInfoMarkerWithMultipleParams() {
- spy.info(marker, "Test info log", testList, testList, testList);
+ spy.info(marker, "Test info log - {} - {} - {}", testList, testList, testList);
verify(spy, times(1)).info(any(Marker.class), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@@ -326,70 +330,73 @@ public class LoggerTest {
@Test
public void testErrorWithSeverity() {
spy.error(EcompErrorSevirity.ERROR, EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", "MockTargetEntity",
- "Test error description", testList, testList, testList);
+ "Mock Service", "MockTargetEntity",
+ "Test error description", testList, testList, testList);
verify(spy, times(1)).error(any(EcompErrorSevirity.class), any(EcompLoggerErrorCode.class),
- anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testError() {
spy.error(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", "Test error description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {}", "Test error description", testList, testList, testList);
verify(spy, times(1)).error(any(EcompLoggerErrorCode.class),
- anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testErrorOptionalData() {
spy.error(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", ErrorLogOptionalData.newBuilder().build(),
- "Test error description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {} - {}", ErrorLogOptionalData.newBuilder().build(),
+ "Test error description", testList, testList, testList);
verify(spy, times(1)).error(any(EcompLoggerErrorCode.class),
- anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(),
+ anyCollection());
}
@Test
public void testWarn() {
spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", "Test warn description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {}", "Test warn description", testList, testList, testList);
verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class),
- anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testWarnWithTargetEntity() {
spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", "MockTargetEntity",
- "Test warn description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {} - {}", "MockTargetEntity",
+ "Test warn description", testList, testList, testList);
verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class),
- anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testWarnOptionalData() {
spy.warn(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", ErrorLogOptionalData.newBuilder().build(),
- "Test warn description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {} - {}", ErrorLogOptionalData.newBuilder().build(),
+ "Test warn description", testList, testList, testList);
verify(spy, times(1)).warn(any(EcompLoggerErrorCode.class),
- anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(),
+ anyCollection());
}
@Test
public void testFatalWithTargetEntity() {
spy.fatal(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", "MockTargetEntity",
- "Test fatal description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {} - {}", "MockTargetEntity",
+ "Test fatal description", testList, testList, testList);
verify(spy, times(1)).fatal(any(EcompLoggerErrorCode.class),
- anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), anyString(), anyString(), anyCollection(), anyCollection(), anyCollection());
}
@Test
public void testFatalWithOptionalData() {
spy.fatal(EcompLoggerErrorCode.UNKNOWN_ERROR,
- "Mock Service", ErrorLogOptionalData.newBuilder().build(),
- "Test fatal description", testList, testList, testList);
+ "Mock Service - {} - {} - {} - {} - {}", ErrorLogOptionalData.newBuilder().build(),
+ "Test fatal description", testList, testList, testList);
verify(spy, times(1)).fatal(any(EcompLoggerErrorCode.class),
- anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(), anyCollection());
+ anyString(), any(ErrorLogOptionalData.class), anyString(), anyCollection(), anyCollection(),
+ anyCollection());
}
} \ No newline at end of file