diff options
Diffstat (limited to 'applications/naming')
-rw-r--r-- | applications/naming/pom.xml | 9 | ||||
-rw-r--r-- | applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java | 87 |
2 files changed, 42 insertions, 54 deletions
diff --git a/applications/naming/pom.xml b/applications/naming/pom.xml index ac18c330..61fdd2dc 100644 --- a/applications/naming/pom.xml +++ b/applications/naming/pom.xml @@ -3,7 +3,7 @@ ONAP Policy Engine - XACML PDP ================================================================================ Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - Modifications Copyright (C) 2023 Nordix Foundation. + Modifications Copyright (C) 2023-2024 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.xacml-pdp.applications</groupId> <artifactId>applications</artifactId> - <version>4.0.0-SNAPSHOT</version> + <version>4.0.1-SNAPSHOT</version> </parent> <artifactId>xacml-naming</artifactId> @@ -35,11 +35,6 @@ <dependencies> <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.onap.policy.xacml-pdp.applications</groupId> <artifactId>common</artifactId> <version>${project.version}</version> diff --git a/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java b/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java index aa8fde41..deeee2f5 100644 --- a/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java +++ b/applications/naming/src/test/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplicationTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,25 +27,22 @@ import static org.assertj.core.api.Assertions.assertThat; import com.att.research.xacml.api.Response; import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Collection; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.ServiceLoader; import org.apache.commons.lang3.tuple.Pair; import org.assertj.core.api.Condition; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.io.TempDir; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -60,61 +57,53 @@ import org.onap.policy.pdp.xacml.xacmltest.TestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class NamingPdpApplicationTest { +@TestMethodOrder(MethodOrderer.MethodName.class) +class NamingPdpApplicationTest { private static final Logger LOGGER = LoggerFactory.getLogger(NamingPdpApplicationTest.class); - private static Properties properties = new Properties(); - private static File propertiesFile; + private static final Properties properties = new Properties(); private static XacmlApplicationServiceProvider service; - private static StandardCoder gson = new StandardCoder(); + private static final StandardCoder gson = new StandardCoder(); private static DecisionRequest baseRequest; - @ClassRule - public static final TemporaryFolder policyFolder = new TemporaryFolder(); + @TempDir + static Path policyFolder; /** * Copies the xacml.properties and policies files into * temporary folder and loads the service provider saving * instance of provider off for other tests to use. */ - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + static void setUp() throws Exception { // // Load Single Decision Request // baseRequest = gson.decode( - TextFileUtils - .getTextFileAsString( - "src/test/resources/decision.naming.input.json"), - DecisionRequest.class); - // - // Setup our temporary folder - // - XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.newFile(filename); - propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties", - properties, myCreator); + TextFileUtils + .getTextFileAsString( + "src/test/resources/decision.naming.input.json"), + DecisionRequest.class); + // // Copy the test policy types into data area // String policy = "onap.policies.Naming"; String policyType = ResourceUtils.getResourceAsString("policytypes/" + policy + ".yaml"); LOGGER.info("Copying {}", policyType); - Files.write(Paths.get(policyFolder.getRoot().getAbsolutePath(), policy + "-1.0.0.yaml"), - policyType.getBytes()); + Files.write(Paths.get(policyFolder.toFile().getAbsolutePath(), policy + "-1.0.0.yaml"), + policyType.getBytes()); // // Load service // ServiceLoader<XacmlApplicationServiceProvider> applicationLoader = - ServiceLoader.load(XacmlApplicationServiceProvider.class); + ServiceLoader.load(XacmlApplicationServiceProvider.class); // // Iterate through Xacml application services and find // the optimization service. Save it for use throughout // all the Junit tests. // StringBuilder strDump = new StringBuilder("Loaded applications:" + XacmlPolicyUtils.LINE_SEPARATOR); - Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator(); - while (iterator.hasNext()) { - XacmlApplicationServiceProvider application = iterator.next(); + for (XacmlApplicationServiceProvider application : applicationLoader) { // // Is it our service? // @@ -136,11 +125,15 @@ public class NamingPdpApplicationTest { // Tell it to initialize based on the properties file // we just built for it. // + + XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.resolve(filename).toFile(); + File propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties", + properties, myCreator); service.initialize(propertiesFile.toPath().getParent(), null); } @Test - public void test01Basics() { + void test01Basics() { // // Make sure there's an application name // @@ -155,13 +148,13 @@ public class NamingPdpApplicationTest { // can support the correct policy types. // assertThat(service.canSupportPolicyType(new ToscaConceptIdentifier( - "onap.policies.Naming", "1.0.0"))).isTrue(); + "onap.policies.Naming", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType(new ToscaConceptIdentifier( - "onap.foobar", "1.0.0"))).isFalse(); + "onap.foobar", "1.0.0"))).isFalse(); } @Test - public void test02NoPolicies() throws CoderException { + void test02NoPolicies() throws CoderException { // // Ask for a decision when there are no policies loaded // @@ -180,7 +173,7 @@ public class NamingPdpApplicationTest { } @Test - public void test03Naming() throws CoderException, FileNotFoundException, IOException, + void test03Naming() throws XacmlApplicationException { // // Now load all the optimization policies @@ -198,7 +191,7 @@ public class NamingPdpApplicationTest { // // Ask for VNF // - baseRequest.getResource().put("policy-type", Arrays.asList("onap.policies.Naming")); + baseRequest.getResource().put("policy-type", List.of("onap.policies.Naming")); // // Ask for a decision for VNF default policies // @@ -238,13 +231,13 @@ public class NamingPdpApplicationTest { Map<String, Object> policyProperties = (Map<String, Object>) policyContents.get("properties"); validateMatchable((Collection<String>) request.getResource().get("nfRole"), - (Collection<String>) policyProperties.get("nfRole")); + (Collection<String>) policyProperties.get("nfRole")); validateMatchable((Collection<String>) request.getResource().get("naming-type"), - (Collection<String>) policyProperties.get("naming-type")); + (Collection<String>) policyProperties.get("naming-type")); validateMatchable((Collection<String>) request.getResource().get("property-name"), - (Collection<String>) policyProperties.get("property-name")); + (Collection<String>) policyProperties.get("property-name")); } } @@ -258,8 +251,8 @@ public class NamingPdpApplicationTest { return; } Condition<String> condition = new Condition<>( - requestList::contains, - "Request list is contained"); + requestList::contains, + "Request list is contained"); assertThat(policyProperties).haveAtLeast(1, condition); } |