aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/clamp/clds
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-11-05 13:44:53 +0100
committersebdet <sebastien.determe@intl.att.com>2019-11-05 17:22:09 +0100
commit1b6a428451709a3daa98d0f1cdee49d791985c0d (patch)
tree22166ce7141e5cd47cc7e995bd60803f5cf00cc1 /src/test/java/org/onap/clamp/clds
parent2901ca9fec4a88db325b90bda2103ffc5e921681 (diff)
Move to JDK 13
Do the required changes to move to JDK 13 Issue-ID: CLAMP-327 Change-Id: Ia7840851eeefc6c00e3e49eacb2e49cc27a0b2f0 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src/test/java/org/onap/clamp/clds')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java41
-rw-r--r--src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java12
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java10
3 files changed, 27 insertions, 36 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java
index ab4421fc..49f17364 100644
--- a/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/AuthorizationControllerItCase.java
@@ -35,16 +35,13 @@ import org.apache.camel.Exchange;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
import org.mockito.Mockito;
-import org.mockito.Spy;
import org.onap.clamp.authorization.AuthorizationController;
-import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.exception.NotAuthorizedException;
import org.onap.clamp.clds.service.SecureServicePermission;
import org.onap.clamp.util.PrincipalUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.mock.env.MockEnvironment;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
@@ -61,14 +58,10 @@ public class AuthorizationControllerItCase {
private PermissionTestDefaultHelper permissionTestHelper = new PermissionTestDefaultHelper();
- @Spy
- MockEnvironment env;
+ // @Spy
+ // MockEnvironment env;
- @Spy
- @InjectMocks
- private ClampProperties clampProp = new ClampProperties();
-
- @InjectMocks
+ @Autowired
private AuthorizationController auth;
/**
@@ -76,34 +69,30 @@ public class AuthorizationControllerItCase {
*/
@Before
public void setupBefore() {
- permissionTestHelper.setupMockEnv(env);
+ // permissionTestHelper.setupMockEnv(env);
List<GrantedAuthority> authList = permissionTestHelper.getAuthList();
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
- Mockito.when(securityContext.getAuthentication()).thenReturn(
- new UsernamePasswordAuthenticationToken(new User("admin", "", authList),
- "", authList)
- );
+ Mockito.when(securityContext.getAuthentication())
+ .thenReturn(new UsernamePasswordAuthenticationToken(new User("admin", "", authList), "", authList));
PrincipalUtils.setSecurityContext(securityContext);
}
@Test
public void testIsUserPermitted() {
- assertTrue(auth.isUserPermitted(new SecureServicePermission("permission-type-cl","dev","read")));
- assertTrue(auth.isUserPermitted(new SecureServicePermission("permission-type-cl-manage","dev","DEPLOY")));
- assertTrue(auth.isUserPermitted(new SecureServicePermission("permission-type-filter-vf","dev",
- "12345-55555-55555-5555")));
- assertFalse(auth.isUserPermitted(new SecureServicePermission("permission-type-cl","test","read")));
+ assertTrue(auth.isUserPermitted(new SecureServicePermission("permission-type-cl", "dev", "read")));
+ assertTrue(auth.isUserPermitted(new SecureServicePermission("permission-type-cl-manage", "dev", "DEPLOY")));
+ assertTrue(auth.isUserPermitted(
+ new SecureServicePermission("permission-type-filter-vf", "dev", "12345-55555-55555-5555")));
+ assertFalse(auth.isUserPermitted(new SecureServicePermission("permission-type-cl", "test", "read")));
}
@Test
public void testIfUserAuthorize() {
Exchange ex = Mockito.mock(Exchange.class);
try {
- permissionTestHelper.doActionOnAllPermissions(((type, instance, action) ->
- auth.authorize(ex, type, instance, action)
- )
- );
+ permissionTestHelper
+ .doActionOnAllPermissions(((type, instance, action) -> auth.authorize(ex, type, instance, action)));
} catch (NotAuthorizedException e) {
fail(e.getMessage());
}
@@ -112,6 +101,6 @@ public class AuthorizationControllerItCase {
@Test(expected = NotAuthorizedException.class)
public void testIfAuthorizeThrowException() {
Exchange ex = Mockito.mock(Exchange.class);
- auth.authorize(ex,"permission-type-cl","test","read");
+ auth.authorize(ex, "cl", "test", "read");
}
}
diff --git a/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java
index 1e6742c9..1453d0ba 100644
--- a/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java
@@ -28,7 +28,7 @@ package org.onap.clamp.clds.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
import java.security.InvalidKeyException;
@@ -45,13 +45,13 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({"javax.crypto.*"})
+@PowerMockIgnore({ "javax.crypto.*", "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*" })
public class CryptoUtilsTest {
private final String data = "This is a test string";
@Test
- @PrepareForTest({CryptoUtils.class})
+ @PrepareForTest({ CryptoUtils.class })
public final void testEncryption() throws Exception {
String encodedString = CryptoUtils.encrypt(data);
assertNotNull(encodedString);
@@ -59,7 +59,7 @@ public class CryptoUtilsTest {
}
@Test
- @PrepareForTest({CryptoUtils.class})
+ @PrepareForTest({ CryptoUtils.class })
public final void testEncryptedStringIsDifferent() throws Exception {
String encodedString1 = CryptoUtils.encrypt(data);
String encodedString2 = CryptoUtils.encrypt(data);
@@ -74,7 +74,7 @@ public class CryptoUtilsTest {
}
@Test
- @PrepareForTest({CryptoUtils.class})
+ @PrepareForTest({ CryptoUtils.class })
public final void testEncryptionBaseOnRandomKey() throws Exception {
SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
final String encryptionKey = String.valueOf(Hex.encodeHex(secretKey.getEncoded()));
@@ -86,7 +86,7 @@ public class CryptoUtilsTest {
}
@Test(expected = InvalidKeyException.class)
- @PrepareForTest({CryptoUtils.class})
+ @PrepareForTest({ CryptoUtils.class })
public final void testEncryptionBadKey() throws Exception {
final String badEncryptionKey = "93210sd";
setAesEncryptionKeyEnv(badEncryptionKey);
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java
index 63a1fa3e..13f8e3ad 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/DocumentBuilderTest.java
@@ -23,11 +23,13 @@
package org.onap.clamp.clds.util.drawing;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import java.io.IOException;
+
import javax.xml.parsers.ParserConfigurationException;
+
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.util.SVGConstants;
import org.junit.Assert;
@@ -57,15 +59,15 @@ public class DocumentBuilderTest {
Node newNode = document.createElement(newNodeTag);
newNode.appendChild(document.createTextNode(newNodeText));
- when(mockG2d.getRoot(any(Element.class))).then(a -> a.getArgumentAt(0, Element.class).appendChild(newNode));
+ when(mockG2d.getRoot(any(Element.class))).then(a -> a.getArgument(0, Element.class).appendChild(newNode));
DocumentBuilder db = new DocumentBuilder(document, document);
db.pushChangestoDocument(mockG2d, dataElementId);
Document actualDocument = db.getGroupingDocument();
Node addedActualNode = actualDocument.getDocumentElement().getLastChild();
- String actualDataElementId =
- addedActualNode.getAttributes().getNamedItem(DocumentBuilder.DATA_ELEMENT_ID_ATTRIBUTE).getTextContent();
+ String actualDataElementId = addedActualNode.getAttributes()
+ .getNamedItem(DocumentBuilder.DATA_ELEMENT_ID_ATTRIBUTE).getTextContent();
Assert.assertEquals(dataElementId, actualDataElementId);
Assert.assertEquals(SVGConstants.SVG_G_TAG, addedActualNode.getNodeName());