From: adheli.tavares Date: Mon, 8 Dec 2025 16:07:49 +0000 (+0000) Subject: Uplift code base to java21 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=HEAD;p=policy%2Fxacml-pdp.git Uplift code base to java21 Issue-ID: POLICY-5466 Change-Id: I297717a04295d4a4cf1a30357b556f040593d971 Signed-off-by: adheli.tavares --- diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java index d2e23fe4..3ed6d505 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ class XacmlPolicyUtilsTest { * writing them out to the temporary folder. */ @BeforeAll - public static void setUp() { + static void setUp() { assertThatCode(() -> { // // Load our test property object diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java index a0a66118..0b767a1f 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,12 +81,11 @@ import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class StdMatchableTranslatorTest { +class StdMatchableTranslatorTest { private static final Logger logger = LoggerFactory.getLogger(StdMatchableTranslatorTest.class); private static final String CLIENT_NAME = "policy-api"; private static final StandardYamlCoder yamlCoder = new StandardYamlCoder(); - private static int port; private static RestClientParameters clientParams; private static ToscaServiceTemplate testTemplate; private static HttpClient apiClient; @@ -107,12 +106,11 @@ public class StdMatchableTranslatorTest { // // Setup our api server simulator // - port = NetworkUtil.allocPort(); clientParams = mock(RestClientParameters.class); when(clientParams.getClientName()).thenReturn("apiClient"); when(clientParams.getHostname()).thenReturn("localhost"); - when(clientParams.getPort()).thenReturn(port); + when(clientParams.getPort()).thenReturn(NetworkUtil.allocPort()); Properties props = getProperties(); @@ -164,7 +162,7 @@ public class StdMatchableTranslatorTest { } @AfterAll - public static void tearDownAfterClass() { + static void tearDownAfterClass() { HttpServletServerFactoryInstance.getServerFactory().destroy(); } @@ -213,13 +211,13 @@ public class StdMatchableTranslatorTest { // List listAttributes = new ArrayList<>(); ObligationExpressionType xacmlObligation = translatedPolicy.getObligationExpressions() - .getObligationExpression().get(0); + .getObligationExpression().getFirst(); assertThat(xacmlObligation.getAttributeAssignmentExpression()).hasSize(4); // // Copy into the list // xacmlObligation.getAttributeAssignmentExpression().forEach(assignment -> { - Object value = ((AttributeValueType) assignment.getExpression().getValue()).getContent().get(0); + Object value = ((AttributeValueType) assignment.getExpression().getValue()).getContent().getFirst(); listAttributes.add(TestUtilsCommon.createAttributeAssignment(assignment.getAttributeId(), assignment.getCategory(), value)); }); diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java index 4bacaf3c..f24c0f89 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPipTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2024 Nordix Foundation. + * Modifications Copyright (C) 2024-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ class StdOnapPipTest { * @throws PIPException if an error occurs */ @BeforeEach - public void setUp() throws PIPException { + void setUp() throws PIPException { resp = new StdMutablePIPResponse(); lenient().when(request.getIssuer()).thenReturn(ISSUER); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java index 24c3d234..d25b10c7 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/CommonRest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019, 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2019, 2023-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +32,8 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.security.SecureRandom; import java.util.Objects; import java.util.concurrent.atomic.AtomicBoolean; -import javax.net.ssl.SSLContext; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -43,7 +41,6 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.onap.policy.common.utils.network.NetworkUtil; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.common.utils.security.SelfSignedKeyStore; import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager; import org.onap.policy.pdpx.main.startstop.Main; import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator; @@ -109,9 +106,7 @@ public class CommonRest { * @throws Exception if an error occurs */ @BeforeAll - public static void setUpBeforeClass() throws Exception { - System.setProperty("javax.net.ssl.keyStore", new SelfSignedKeyStore().getKeystoreName()); - System.setProperty("javax.net.ssl.keyStorePassword", SelfSignedKeyStore.KEYSTORE_PASSWORD); + public static void setUpBeforeClass() throws Exception { // NOSONAR - class is extended System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog"); System.setProperty("org.eclipse.jetty.LEVEL", "OFF"); @@ -133,7 +128,7 @@ public class CommonRest { * Stops the "Main". */ @AfterAll - public static void tearDownAfterClass() { + static void tearDownAfterClass() { stopMain(); } @@ -141,7 +136,7 @@ public class CommonRest { * Resets the statistics. */ @BeforeEach - public void setUp() { + void setUp() { activatorWasAlive = XacmlPdpActivator.getCurrent().isAlive(); XacmlPdpStatisticsManager.getCurrent().resetAllStatistics(); } @@ -150,7 +145,7 @@ public class CommonRest { * Restores the "alive" status of the activator. */ @AfterEach - public void tearDown() { + public void tearDown() { // NOSONAR - class is extended markActivator(activatorWasAlive); } @@ -176,32 +171,23 @@ public class CommonRest { } /** - * Sends an HTTPS request to an endpoint of the PDP's REST API. + * Sends an HTTP request to an endpoint of the PDP's REST API. * * @param endpoint target endpoint * @return a request builder - * @throws Exception if an error occurs */ - protected Invocation.Builder sendHttpsRequest(final String endpoint) throws Exception { - // always trust the certificate - final SSLContext sc = SSLContext.getInstance("TLSv1.2"); - sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom()); - - // always trust the host name - final ClientBuilder clientBuilder = - ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true); - - final Client client = clientBuilder.build(); + protected Invocation.Builder sendHttpsRequest(final String endpoint) { + final Client client = ClientBuilder.newBuilder().build(); final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("healthcheck", "zb!XztG34"); client.register(feature); - final WebTarget webTarget = client.target("https://localhost:" + port + "/policy/pdpx/v1/" + endpoint); + final WebTarget webTarget = client.target("http://localhost:" + port + "/policy/pdpx/v1/" + endpoint); return webTarget.request(MediaType.APPLICATION_JSON); } /** - * Mark the activator as dead, but leave its REST server running. + * Mark the activator as dead but leave its REST server running. */ protected void markActivatorDead() { markActivator(false); diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java index b9b8b9e4..2b1cf745 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019, 2024 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ class TestMain extends CommonRest { * @throws Exception if an error occurs */ @BeforeAll - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() throws Exception { // NOSONAR - class is extended ParameterService.clear(); CommonRest.setUpBeforeClass(); @@ -54,9 +54,8 @@ class TestMain extends CommonRest { CommonRest.stopMain(); } - @Override @BeforeEach - public void setUp() { + void setUp() { main = null; } diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java index 2db620de..3bf9bf5f 100644 --- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java +++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019, 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2019, 2023-2025 OpenInfra Foundation Europe. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,7 @@ import org.springframework.test.util.ReflectionTestUtils; /** * Class to perform unit test of XacmlPdpActivator. */ -public class TestXacmlPdpActivator extends CommonRest { +class TestXacmlPdpActivator extends CommonRest { private static final String PROBE_FIELD_NAME = "probeHeartbeatTopicSec"; private static XacmlPdpParameterGroup parGroup; @@ -52,7 +52,7 @@ public class TestXacmlPdpActivator extends CommonRest { * Loads properties. */ @BeforeAll - public static void setUpBeforeClass() throws Exception { + public static void setUpBeforeClass() throws Exception { // NOSONAR - class is extended ParameterService.clear(); CommonRest.setUpBeforeClass(); @@ -67,9 +67,8 @@ public class TestXacmlPdpActivator extends CommonRest { /** * Creates the activator. */ - @Override @BeforeEach - public void setUp() { + void setUp() { ReflectionTestUtils.setField(parGroup, PROBE_FIELD_NAME, 4); activator = new XacmlPdpActivator(parGroup); } @@ -119,7 +118,7 @@ public class TestXacmlPdpActivator extends CommonRest { * Teardown tests. */ @AfterEach - public void teardown() { + void teardown() { if (activator != null && activator.isAlive()) { activator.stop(); } diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json index a0608862..5dff6cf6 100644 --- a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json +++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Std.json @@ -7,7 +7,7 @@ "port":${port}, "userName":"healthcheck", "password":"zb!XztG34", - "https":true + "https":false }, "policyApiParameters": { "hostname": "0.0.0.0", diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/ssl/policy-truststore b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/ssl/policy-truststore deleted file mode 100644 index 8834ac25..00000000 Binary files a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/ssl/policy-truststore and /dev/null differ