diff options
author | sebdet <sebastien.determe@intl.att.com> | 2019-11-05 13:44:53 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2019-11-05 17:22:09 +0100 |
commit | 1b6a428451709a3daa98d0f1cdee49d791985c0d (patch) | |
tree | 22166ce7141e5cd47cc7e995bd60803f5cf00cc1 /src/test/java/org | |
parent | 2901ca9fec4a88db325b90bda2103ffc5e921681 (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')
4 files changed, 54 insertions, 65 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 ab4421fca..49f173644 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 1e6742c98..1453d0baa 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 63a1fa3e7..13f8e3ad6 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()); diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java index 773332ddd..fbf1f2079 100644 --- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java +++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java @@ -44,7 +44,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.onap.clamp.clds.Application; -import org.onap.clamp.clds.exception.policy.PolicyModelException; import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException; import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException; import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact; @@ -88,13 +87,13 @@ public class CsarInstallerItCase { private CsarInstaller csarInstaller; private BlueprintArtifact buildFakeBuildprintArtifact(String instanceName, String invariantResourceUuid, - String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { + String blueprintFilePath, String artifactName, String invariantServiceUuid) throws IOException { IResourceInstance resource = Mockito.mock(IResourceInstance.class); Mockito.when(resource.getResourceInstanceName()).thenReturn(instanceName); Mockito.when(resource.getResourceInvariantUUID()).thenReturn(invariantResourceUuid); BlueprintArtifact blueprintArtifact = Mockito.mock(BlueprintArtifact.class); Mockito.when(blueprintArtifact.getDcaeBlueprint()) - .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); + .thenReturn(ResourceFileUtil.getResourceAsString(blueprintFilePath)); Mockito.when(blueprintArtifact.getBlueprintArtifactName()).thenReturn(artifactName); Mockito.when(blueprintArtifact.getBlueprintInvariantServiceUuid()).thenReturn(invariantServiceUuid); Mockito.when(blueprintArtifact.getResourceAttached()).thenReturn(resource); @@ -113,19 +112,19 @@ public class CsarInstallerItCase { Mockito.when(csarHandler.getMapOfBlueprints()).thenReturn(blueprintMap); // Create fake blueprint artifact 1 on resource1 BlueprintArtifact blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, - INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); + INVARIANT_RESOURCE1_UUID, "example/sdc/blueprint-dcae/tca.yaml", "tca.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); // Create fake blueprint artifact 2 on resource2 blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE2, INVARIANT_RESOURCE2_UUID, - "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); + "example/sdc/blueprint-dcae/tca_2.yaml", "tca_2.yaml", INVARIANT_SERVICE_UUID); listResources.add(blueprintArtifact.getResourceAttached()); blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); // Create fake blueprint artifact 3 on resource 1 so that it's possible to // test multiple CL deployment per Service/vnf blueprintArtifact = buildFakeBuildprintArtifact(RESOURCE_INSTANCE_NAME_RESOURCE1, INVARIANT_RESOURCE1_UUID, - "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); + "example/sdc/blueprint-dcae/tca_3.yaml", "tca_3.yaml", INVARIANT_SERVICE_UUID); blueprintMap.put(blueprintArtifact.getBlueprintArtifactName(), blueprintArtifact); // Build fake csarhandler @@ -146,7 +145,7 @@ public class CsarInstallerItCase { // Mockito.when(csarHandler.getSdcCsarHelper()).thenReturn(csarHelper); Mockito.when(csarHandler.getPolicyModelYaml()) - .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"))); + .thenReturn(Optional.ofNullable(ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"))); return csarHandler; } @@ -162,16 +161,16 @@ public class CsarInstallerItCase { CsarHandler csarHandler = new CsarHandler(notificationData, "", ""); csarHandler - .setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile()); + .setFilePath(Thread.currentThread().getContextClassLoader().getResource(CSAR_ARTIFACT_NAME).getFile()); Optional<String> testyaml = csarHandler.getPolicyModelYaml(); - Assert.assertEquals(testyaml, - Optional.ofNullable(ResourceFileUtil.getResourceAsString("example/sdc/expected-result/policy-data.yaml"))); + Assert.assertEquals(testyaml, Optional + .ofNullable(ResourceFileUtil.getResourceAsString("example/sdc/expected-result/policy-data.yaml"))); } @Test @Transactional public void testIsCsarAlreadyDeployedTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, InterruptedException, PolicyModelException { + CsarHandlerException, IOException, InterruptedException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csarHandler = buildFakeCsarHandler(generatedName); assertThat(csarInstaller.isCsarAlreadyDeployed(csarHandler)).isFalse(); @@ -183,23 +182,22 @@ public class CsarInstallerItCase { @Transactional @Rollback(value = false) public void testInstallTheCsarTca() throws SdcArtifactInstallerException, SdcToscaParserException, - CsarHandlerException, IOException, JSONException, InterruptedException, PolicyModelException { + CsarHandlerException, IOException, JSONException, InterruptedException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csar = buildFakeCsarHandler(generatedName); csarInstaller.installTheCsar(csar); assertThat(loopsRepo - .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))) - .isTrue(); - assertThat(loopsRepo - .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))) - .isTrue(); - assertThat(loopsRepo - .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))) - .isTrue(); + .existsById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml"))) + .isTrue(); + assertThat(loopsRepo.existsById( + Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml"))).isTrue(); + assertThat(loopsRepo.existsById( + Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml"))).isTrue(); // Verify now that policy and json representation, global properties are well // set Loop loop = loopsRepo - .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")).get(); + .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca.yaml")) + .get(); assertThat(loop.getSvgRepresentation()).startsWith("<svg "); assertThat(loop.getGlobalPropertiesJson().get("dcaeDeployParameters")).isNotNull(); assertThat(loop.getMicroServicePolicies()).hasSize(1); @@ -207,27 +205,27 @@ public class CsarInstallerItCase { assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull(); assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull(); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/model-properties.json"), - JsonUtils.GSON.toJson(loop.getModelPropertiesJson()), true); + JsonUtils.GSON.toJson(loop.getModelPropertiesJson()), true); assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty(); loop = loopsRepo - .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml")) - .get(); + .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE1, "tca_3.yaml")) + .get(); assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty(); loop = loopsRepo - .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml")) - .get(); + .findById(Loop.generateLoopName(generatedName, "1.0", RESOURCE_INSTANCE_NAME_RESOURCE2, "tca_2.yaml")) + .get(); assertThat(((MicroServicePolicy) (loop.getMicroServicePolicies().toArray()[0])).getModelType()).isNotEmpty(); } @Test(expected = SdcArtifactInstallerException.class) @Transactional - public void shouldThrowSdcArtifactInstallerException() throws SdcArtifactInstallerException, - SdcToscaParserException, IOException, InterruptedException, PolicyModelException { + public void shouldThrowSdcArtifactInstallerException() + throws SdcArtifactInstallerException, SdcToscaParserException, IOException, InterruptedException { String generatedName = RandomStringUtils.randomAlphanumeric(5); CsarHandler csarHandler = buildFakeCsarHandler(generatedName); - Mockito.when(csarHandler.getMapOfBlueprints()).thenThrow(IOException.class); + Mockito.when(csarHandler.getPolicyModelYaml()).thenThrow(IOException.class); csarInstaller.installTheCsar(csarHandler); } } |