diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-02-19 16:59:01 -0500 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-02-19 19:59:33 -0500 |
commit | 3f4d4125093ca000c735adc1d6430c39e31de38c (patch) | |
tree | 5386fae347d6445bdba7599d0f42aefc85d867df /applications/naming | |
parent | 56038a31a23e468f51c0b2ab349f748eafe4b6d2 (diff) |
Use datatype in matchable translator
With the new changes to models/api, the full policy template will
be retrieved along with inherited policy types and datatypes.
Changed api caller to return tosca template instead of individual
policy type so all policy types and data types are available.
Changed stdmatchabletranslator to be able to flexibly go deep with
list/map of datatypes of attributes. NOTE: This should be re-factored
at a later date as its a bit messy.
The naming application was used to test this code, but it was determined
by the CCSDK team that they will not do filtering this release. Instead,
switched to combined results policy type to return the full policy type.
Issue-ID: POLICY-1740
Change-Id: Ieb4e46e7fb2c639a1155be3bc07f5587c4f7b09a
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/naming')
2 files changed, 21 insertions, 25 deletions
diff --git a/applications/naming/src/main/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplication.java b/applications/naming/src/main/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplication.java index d04fca6a..5d45bfc5 100644 --- a/applications/naming/src/main/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplication.java +++ b/applications/naming/src/main/java/org/onap/policy/xacml/pdp/application/naming/NamingPdpApplication.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,11 @@ package org.onap.policy.xacml.pdp.application.naming; -import java.nio.file.Path; import java.util.Arrays; import java.util.List; -import org.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator; -import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException; -import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator; +import org.onap.policy.pdp.xacml.application.common.std.StdCombinedPolicyResultsTranslator; import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider; public class NamingPdpApplication extends StdXacmlApplicationServiceProvider { @@ -37,7 +34,7 @@ public class NamingPdpApplication extends StdXacmlApplicationServiceProvider { private static final ToscaPolicyTypeIdentifier supportedPolicy = new ToscaPolicyTypeIdentifier( "onap.policies.Naming", "1.0.0"); - private StdMatchableTranslator translator = new StdMatchableTranslator(); + private StdCombinedPolicyResultsTranslator translator = new StdCombinedPolicyResultsTranslator(); @Override public String applicationName() { @@ -50,21 +47,6 @@ public class NamingPdpApplication extends StdXacmlApplicationServiceProvider { } @Override - public void initialize(Path pathForData, RestServerParameters policyApiParameters) - throws XacmlApplicationException { - // - // Store our API parameters and path for translator so it - // can go get Policy Types - // - this.translator.setPathForData(pathForData); - this.translator.setApiRestParameters(policyApiParameters); - // - // Let our super class do its thing - // - super.initialize(pathForData, policyApiParameters); - } - - @Override public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() { return Arrays.asList(supportedPolicy); } 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 02884b63..0077d0b9 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.Map; @@ -42,8 +43,10 @@ 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.onap.policy.common.endpoints.parameters.RestServerParameters; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; @@ -59,6 +62,7 @@ import org.onap.policy.pdp.xacml.xacmltest.TestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class NamingPdpApplicationTest { private static final Logger LOGGER = LoggerFactory.getLogger(NamingPdpApplicationTest.class); private static Properties properties = new Properties(); @@ -92,7 +96,6 @@ public class NamingPdpApplicationTest { // // Setup our temporary folder // - // TODO use lambda policyFolder::newFile XacmlPolicyUtils.FileCreator myCreator = (String filename) -> policyFolder.newFile(filename); propertiesFile = XacmlPolicyUtils.copyXacmlPropertiesContents("src/test/resources/xacml.properties", properties, myCreator); @@ -102,7 +105,6 @@ public class NamingPdpApplicationTest { String policy = "onap.policies.Naming"; String policyType = ResourceUtils.getResourceAsString("policytypes/" + policy + ".yaml"); LOGGER.info("Copying {}", policyType); - // TODO investigate UTF-8 Files.write(Paths.get(policyFolder.getRoot().getAbsolutePath(), policy + "-1.0.0.yaml"), policyType.getBytes()); // @@ -188,7 +190,19 @@ public class NamingPdpApplicationTest { // Ask for a decision for available default policies // DecisionResponse response = makeDecision(); - + // + // There is no default policy + // + assertThat(response).isNotNull(); + assertThat(response.getPolicies().size()).isEqualTo(0); + // + // Ask for VNF + // + baseRequest.getResource().put("policy-type", Arrays.asList("onap.policies.Naming")); + // + // Ask for a decision for VNF default policies + // + response = makeDecision(); assertThat(response).isNotNull(); assertThat(response.getPolicies().size()).isEqualTo(1); // |