Missing support for PolicySetType 39/103739/2
authorPamela Dragosh <pdragosh@research.att.com>
Mon, 16 Mar 2020 15:09:36 +0000 (11:09 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Mon, 16 Mar 2020 15:24:19 +0000 (11:24 -0400)
Adds support for PolicySetType specifically for Native policies. When/If
the other applications change to support they can easily do so.

Adding some more code coverage for Native application and translator.

Issue-ID: POLICY-2433
Change-Id: I463ca9f04928d759624a2176598b463057d386bd
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
16 files changed:
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/ToscaPolicyTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtilsTest.java
applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslatorTest.java
applications/native/src/main/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTranslator.java
applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
applications/native/src/test/resources/policies/bad.native.policies.yaml [new file with mode: 0644]
applications/native/src/test/resources/policies/native.policy.yaml
applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTranslator.java

index 32b950b..61ec0be 100644 (file)
@@ -24,9 +24,6 @@ package org.onap.policy.pdp.xacml.application.common;
 
 import com.att.research.xacml.api.Request;
 import com.att.research.xacml.api.Response;
-
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -37,10 +34,10 @@ public interface ToscaPolicyTranslator {
      * Implement this method to translate policies.
      *
      * @param toscaPolicy Incoming Tosca Policy object
-     * @return Xacml PolicyType object
+     * @return Xacml PolicyType or PolicySetType object
      * @throws ToscaPolicyConversionException Exception
      */
-    PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException;
+    Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException;
 
     /**
      * Implement this method to convert an ONAP DecisionRequest into
index 0ca7198..c845709 100644 (file)
@@ -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.
@@ -23,6 +23,7 @@
 package org.onap.policy.pdp.xacml.application.common;
 
 import com.att.research.xacml.api.Identifier;
+import com.att.research.xacml.util.XACMLPolicyWriter;
 import com.att.research.xacml.util.XACMLProperties;
 
 import java.io.File;
@@ -352,13 +353,24 @@ public class XacmlPolicyUtils {
      * @param path Path for policy
      * @return Path unique file path for the Policy
      */
-    public static Path constructUniquePolicyFilename(PolicyType policy, Path path) {
+    public static Path constructUniquePolicyFilename(Object policy, Path path) {
+        String id;
+        String version;
+        if (policy instanceof PolicyType) {
+            id = ((PolicyType) policy).getPolicyId();
+            version = ((PolicyType) policy).getVersion();
+        } else if (policy instanceof PolicySetType) {
+            id = ((PolicySetType) policy).getPolicySetId();
+            version = ((PolicySetType) policy).getVersion();
+        } else {
+            throw new IllegalArgumentException("Must pass a PolicyType or PolicySetType");
+        }
         //
         //
         // Can it be possible to produce an invalid filename?
         // Should we insert a UUID
         //
-        String filename = policy.getPolicyId() + "_" + policy.getVersion() + ".xml";
+        String filename = id + "_" + version + ".xml";
         //
         // Construct the Path
         //
@@ -495,4 +507,21 @@ public class XacmlPolicyUtils {
             return propertiesFile;
         }
     }
+
+    /**
+     * Wraps the call to XACMLPolicyWriter.
+     *
+     * @param path Path to file to be written to.
+     * @param policy PolicyType or PolicySetType
+     * @return Path - the same path passed in most likely from XACMLPolicyWriter. Or NULL if an error occurs.
+     */
+    public static Path writePolicyFile(Path path, Object policy) {
+        if (policy instanceof PolicyType) {
+            return XACMLPolicyWriter.writePolicyFile(path, (PolicyType) policy);
+        } else if (policy instanceof PolicySetType) {
+            return XACMLPolicyWriter.writePolicyFile(path, (PolicySetType) policy);
+        } else {
+            throw new IllegalArgumentException("Expecting PolicyType or PolicySetType");
+        }
+    }
 }
index 3ac57b7..a6c9977 100644 (file)
@@ -64,7 +64,7 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
     public static final String POLICY_VERSION = "policy-version";
 
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         throw new ToscaPolicyConversionException("Please override convertPolicy");
     }
 
index d966182..8db9948 100644 (file)
@@ -59,7 +59,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
     }
 
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         //
         // Sanity checks
         //
index 7ca995e..690b710 100644 (file)
@@ -156,6 +156,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator {
         );
     }
 
+    @Override
     protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
         LOGGER.warn("scanAdvice not supported by {}", this.getClass());
     }
@@ -235,7 +236,7 @@ public class StdMatchableTranslator  extends StdBaseTranslator {
     }
 
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         //
         // Get the TOSCA Policy Type for this policy
         //
index 0fdd3a9..9a8b63f 100644 (file)
@@ -28,7 +28,6 @@ import com.att.research.xacml.api.pdp.PDPEngine;
 import com.att.research.xacml.api.pdp.PDPEngineFactory;
 import com.att.research.xacml.api.pdp.PDPException;
 import com.att.research.xacml.util.FactoryException;
-import com.att.research.xacml.util.XACMLPolicyWriter;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -39,7 +38,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import lombok.Getter;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
@@ -121,7 +119,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
             //
             // Convert the policies first
             //
-            PolicyType xacmlPolicy = this.getTranslator(toscaPolicy.getType()).convertPolicy(toscaPolicy);
+            Object xacmlPolicy = this.getTranslator(toscaPolicy.getType()).convertPolicy(toscaPolicy);
             if (xacmlPolicy == null) {
                 throw new ToscaPolicyConversionException("Failed to convert policy");
             }
@@ -137,7 +135,9 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
             // Write the policy to disk
             // Maybe check for an error
             //
-            XACMLPolicyWriter.writePolicyFile(refPath, xacmlPolicy);
+            if (XacmlPolicyUtils.writePolicyFile(refPath, xacmlPolicy) == null) {
+                throw new ToscaPolicyConversionException("Unable to writePolicyFile");
+            }
             if (LOGGER.isInfoEnabled()) {
                 LOGGER.info("Xacml Policy is {}{}", XacmlPolicyUtils.LINE_SEPARATOR,
                     new String(Files.readAllBytes(refPath), StandardCharsets.UTF_8));
index 46ad83b..05d796e 100644 (file)
@@ -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.
@@ -24,6 +24,7 @@ package org.onap.policy.pdp.xacml.application.common;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
 import com.att.research.xacml.api.XACML3;
 import com.att.research.xacml.util.XACMLPolicyWriter;
@@ -121,9 +122,9 @@ public class XacmlPolicyUtilsTest {
             //
             // Save root policy
             //
-            File rootFile = policyFolder.newFile("root.xml");
-            LOGGER.info("Creating Root Policy {}", rootFile.getAbsolutePath());
-            rootPath = XACMLPolicyWriter.writePolicyFile(rootFile.toPath(), rootPolicy);
+            Path rootFile = XacmlPolicyUtils.constructUniquePolicyFilename(rootPolicy, policyFolder.getRoot().toPath());
+            LOGGER.info("Creating Root Policy {}", rootFile.toAbsolutePath());
+            rootPath = XacmlPolicyUtils.writePolicyFile(rootFile, rootPolicy);
             //
             // Create policies - Policies 1 and 2 will become references in the
             // root policy. While Policies 3 and 4 will become references in the
@@ -200,9 +201,21 @@ public class XacmlPolicyUtilsTest {
         //
         // Save it to disk
         //
-        File file = policyFolder.newFile(policy.getPolicyId() + ".xml");
-        LOGGER.info("Creating Policy {}", file.getAbsolutePath());
-        return XACMLPolicyWriter.writePolicyFile(file.toPath(), policy);
+        Path policyFile = XacmlPolicyUtils.constructUniquePolicyFilename(policy, policyFolder.getRoot().toPath());
+        LOGGER.info("Creating Policy {}", policyFile.toAbsolutePath());
+        return XacmlPolicyUtils.writePolicyFile(policyFile, policy);
+    }
+
+    @Test
+    public void testUncommonConditions() throws IOException {
+        File fileTemp = policyFolder.newFile();
+        assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() ->
+            XacmlPolicyUtils.writePolicyFile(fileTemp.toPath(), new String("not a policy"))
+        );
+        assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() ->
+            XacmlPolicyUtils.constructUniquePolicyFilename(new String("not a policy"),
+                    policyFolder.getRoot().toPath())
+        );
     }
 
     @Test
index e191a08..584390c 100644 (file)
@@ -192,9 +192,9 @@ public class StdMatchableTranslatorTest {
         for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) {
             for (ToscaPolicy policy : policies.values()) {
                 //
-                // Test that we can convert the policy
+                // Test that we can convert the policy - assuming PolicyType
                 //
-                PolicyType translatedPolicy = translator.convertPolicy(policy);
+                PolicyType translatedPolicy = (PolicyType) translator.convertPolicy(policy);
                 assertNotNull(translatedPolicy);
                 assertThat(translatedPolicy.getObligationExpressions().getObligationExpression()).hasSize(1);
                 logger.info("Translated policy {} {}", XacmlPolicyUtils.LINE_SEPARATOR, translatedPolicy);
index f1006c6..2c7ad58 100644 (file)
@@ -39,9 +39,6 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
-
 import org.apache.commons.io.IOUtils;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardYamlCoder;
@@ -63,7 +60,7 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
     }
 
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         LOGGER.debug("Using CoordinationGuardTranslator.convertPolicy");
         //
         // Policy name should be at the root
@@ -88,7 +85,7 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
         // Scan the string and convert to PoilcyType
         //
         try (InputStream is = new ByteArrayInputStream(xacmlStr.getBytes(StandardCharsets.UTF_8))) {
-            return (PolicyType) XACMLPolicyScanner.readPolicy(is);
+            return XACMLPolicyScanner.readPolicy(is);
         } catch (IOException e) {
             throw new ToscaPolicyConversionException("Failed to read policy", e);
         }
index fd46a98..1e4333e 100644 (file)
@@ -96,7 +96,8 @@ public class GuardTranslator implements ToscaPolicyTranslator {
     /**
      * Convert the policy.
      */
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    @Override
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         //
         // Policy name should be at the root
         //
@@ -140,6 +141,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
     /**
      * Convert Request.
      */
+    @Override
     public Request convertRequest(DecisionRequest request) throws ToscaPolicyConversionException {
         LOGGER.info("Converting Request {}", request);
         try {
@@ -152,6 +154,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
     /**
      * Convert response.
      */
+    @Override
     public DecisionResponse convertResponse(Response xacmlResponse) {
         LOGGER.info("Converting Response {}", xacmlResponse);
         DecisionResponse decisionResponse = new DecisionResponse();
index 36b43ae..c785a50 100644 (file)
@@ -166,7 +166,7 @@ public class GuardTranslatorTest {
                         translator.convertPolicy(policy));
                     continue;
                 }
-                PolicyType xacmlPolicy = translator.convertPolicy(policy);
+                PolicyType xacmlPolicy = (PolicyType) translator.convertPolicy(policy);
                 assertThat(xacmlPolicy).isNotNull();
                 //
                 // Let's dump it out
index 546c29e..5ce25fa 100644 (file)
@@ -27,11 +27,9 @@ import com.att.research.xacml.api.Response;
 import com.att.research.xacml.util.XACMLPolicyScanner;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.Base64;
 import java.util.Map;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -56,7 +54,7 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
     }
 
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         //
         // Extract the Base64 encoded policy xml string and decode it
         //
@@ -67,16 +65,19 @@ public class NativePdpApplicationTranslator implements ToscaPolicyTranslator {
         } catch (IllegalArgumentException exc) {
             throw new ToscaPolicyConversionException("error on Base64 decoding the native policy", exc);
         }
-        LOGGER.debug("Decoded xacml policy {}",decodedXacmlPolicy);
+        LOGGER.debug("Decoded xacml policy {}", decodedXacmlPolicy);
         //
         // Scan the string and convert to xacml PolicyType
         //
-        try (InputStream is = new ByteArrayInputStream(decodedXacmlPolicy.getBytes(StandardCharsets.UTF_8))) {
+        try (ByteArrayInputStream is = new ByteArrayInputStream(decodedXacmlPolicy.getBytes(StandardCharsets.UTF_8))) {
             //
-            // Here we assume it is PolicyType, not PolicySetType
-            // PolicySetType will be addressed later
+            // Read the Policy In
             //
-            return (PolicyType) XACMLPolicyScanner.readPolicy(is);
+            Object policy = XACMLPolicyScanner.readPolicy(is);
+            if (policy == null) {
+                throw new ToscaPolicyConversionException("Invalid XACML Policy");
+            }
+            return policy;
         } catch (IOException exc) {
             throw new ToscaPolicyConversionException("Failed to read policy", exc);
         }
index b25c2a3..a11c1b1 100644 (file)
@@ -23,6 +23,7 @@
 package org.onap.policy.xacml.pdp.application.nativ;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
 import com.att.research.xacml.api.Decision;
 import com.att.research.xacml.api.Request;
@@ -30,6 +31,7 @@ import com.att.research.xacml.api.Response;
 import com.att.research.xacml.std.dom.DOMRequest;
 import com.att.research.xacml.std.dom.DOMResponse;
 import java.io.File;
+import java.util.Map;
 import java.util.Properties;
 import java.util.ServiceLoader;
 import org.junit.BeforeClass;
@@ -37,7 +39,14 @@ import org.junit.ClassRule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
 import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
 import org.onap.policy.pdp.xacml.xacmltest.TestUtils;
@@ -48,6 +57,7 @@ public class NativePdpApplicationTest {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(NativePdpApplicationTest.class);
     private static final String PERMIT = "Permit";
+    private static final StandardYamlCoder yamlCoder = new StandardYamlCoder();
     private static Properties properties = new Properties();
     private static File propertiesFile;
     private static RestServerParameters clientParams = new RestServerParameters();
@@ -110,6 +120,59 @@ public class NativePdpApplicationTest {
                         "src/test/resources/requests/native.policy.request.xml"));
     }
 
+    @Test
+    public void testUncommon() {
+        NativePdpApplicationTranslator translator = new NativePdpApplicationTranslator();
+        assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+            translator.convertRequest(null)
+        ).withMessageContaining("Do not call native convertRequest");
+
+        assertThat(translator.convertResponse(null)).isNull();
+
+        NativePdpApplication application = new NativePdpApplication();
+        assertThat(application.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+            "onap.policies.native.Xacml", "1.0.0"))).isTrue();
+        assertThat(application.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+                "onap.policies.native.SomethingElse", "1.0.0"))).isFalse();
+        assertThat(application.actionDecisionsSupported()).contains("native");
+    }
+
+    @Test
+    public void testBadPolicies() throws Exception {
+        NativePdpApplicationTranslator translator = new NativePdpApplicationTranslator();
+        String policyYaml = ResourceUtils.getResourceAsString("src/test/resources/policies/bad.native.policies.yaml");
+        //
+        // Serialize it into a class
+        //
+        ToscaServiceTemplate serviceTemplate = yamlCoder.decode(policyYaml, ToscaServiceTemplate.class);
+        //
+        // Make sure all the fields are setup properly
+        //
+        JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+        jtst.fromAuthorative(serviceTemplate);
+        ToscaServiceTemplate completedJtst = jtst.toAuthorative();
+        //
+        // Get the policies
+        //
+        for (Map<String, ToscaPolicy> policies : completedJtst.getToscaTopologyTemplate().getPolicies()) {
+            for (ToscaPolicy policy : policies.values()) {
+                if ("bad.base64".equals(policy.getName())) {
+                    assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+                        translator.convertPolicy(policy)
+                    ).withMessageContaining("error on Base64 decoding the native policy");
+                } else if ("bad.noproperties".equals(policy.getName())) {
+                    assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+                        translator.convertPolicy(policy)
+                    ).withMessageContaining("no xacml native policy found in the tosca policy");
+                } else if ("bad.policy".equals(policy.getName())) {
+                    assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+                        translator.convertPolicy(policy)
+                    ).withMessageContaining("Invalid XACML Policy");
+                }
+            }
+        }
+    }
+
     @Test
     public void testNativePolicy() throws Exception {
 
@@ -152,7 +215,7 @@ public class NativePdpApplicationTest {
      * @throws Exception on errors checking the decision
      *
      **/
-    public void checkDecision(String expected, Response response) throws Exception {
+    private void checkDecision(String expected, Response response) throws Exception {
         LOGGER.info("Looking for {} Decision", expected);
         assertThat(response).isNotNull();
         Decision decision = response.getResults().iterator().next().getDecision();
diff --git a/applications/native/src/test/resources/policies/bad.native.policies.yaml b/applications/native/src/test/resources/policies/bad.native.policies.yaml
new file mode 100644 (file)
index 0000000..318b320
--- /dev/null
@@ -0,0 +1,28 @@
+tosca_definitions_version: tosca_simple_yaml_1_1_0
+topology_template:
+  policies:
+    -
+      bad.base64:
+        type: onap.policies.native.Xacml
+        version: 1.0.0
+        metadata:
+          policy-id: bad.base64
+          policy-version: 1.0.0
+        properties:
+          policy: "%%%%%%"
+    -
+      bad.noproperties:
+        type: onap.policies.native.Xacml
+        version: 1.0.0
+        metadata:
+          policy-id: bad.noproperties
+          policy-version: 1.0.0
+    -
+      bad.policy:
+        type: onap.policies.native.Xacml
+        version: 1.0.0
+        metadata:
+          policy-id: bad.policy
+          policy-version: 1.0.0
+        properties:
+          policy: ABC123
\ No newline at end of file
index 00bc5db..b9e8d60 100644 (file)
@@ -1,4 +1,4 @@
-tosca_definitions_version: tosca_simple_yaml_1_0_0
+tosca_definitions_version: tosca_simple_yaml_1_1_0
 topology_template:
   policies:
     -
@@ -7,6 +7,6 @@ topology_template:
         version: 1.0.0
         metadata:
           policy-id: native.access.control
-          policy-version: 1
+          policy-version: 1.0.0
         properties:
           policy: PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxQb2xpY3kgeG1sbnM9InVybjpvYXNpczpuYW1lczp0Yzp4YWNtbDozLjA6Y29yZTpzY2hlbWE6d2QtMTciIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIFBvbGljeUlkPSJ1cm46b2FzaXM6bmFtZXM6dGM6eGFjbWw6Mi4wOmNvbmZvcm1hbmNlLXRlc3Q6SUlBMTpwb2xpY3kiIFJ1bGVDb21iaW5pbmdBbGdJZD0idXJuOm9hc2lzOm5hbWVzOnRjOnhhY21sOjMuMDpydWxlLWNvbWJpbmluZy1hbGdvcml0aG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1cm46b2FzaXM6bmFtZXM6dGM6eGFjbWw6MS4wOmFjdGlvbjphY3Rpb24taWQiIENhdGVnb3J5PSJ1cm46b2FzaXM6bmFtZXM6dGM6eGFjbWw6My4wOmF0dHJpYnV0ZS1jYXRlZ29yeTphY3Rpb24iIERhdGFUeXBlPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSNzdHJpbmciIE11c3RCZVByZXNlbnQ9ImZhbHNlIi8+CiAgICAgICAgICAgICAgICAgICAgPC9NYXRjaD4KICAgICAgICAgICAgICAgIDwvQWxsT2Y+CiAgICAgICAgICAgIDwvQW55T2Y+CiAgICAgICAgPC9UYXJnZXQ+CiAgICA8L1J1bGU+CjwvUG9saWN5Pgo=
\ No newline at end of file
index d56b73a..52f1ec0 100644 (file)
@@ -65,11 +65,12 @@ public class OptimizationPdpApplicationTranslator extends StdMatchableTranslator
 
     @SuppressWarnings("unchecked")
     @Override
-    public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+    public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
         //
-        // Have our superclass do the work
+        // Have our superclass do the work - NOTE we are assuming
+        // that we are getting a PolicyType converted.
         //
-        PolicyType policy = super.convertPolicy(toscaPolicy);
+        PolicyType policy = (PolicyType) super.convertPolicy(toscaPolicy);
         //
         // Check if this is the subscriber policy
         //