diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2020-03-16 11:09:36 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2020-03-16 11:24:19 -0400 |
commit | 6b4f9b69bc4acec28da8ef50b8f234d0182f0d78 (patch) | |
tree | 877cc134b10d08393f0868a7dae7d5f604e49a5b /applications/common/src/test | |
parent | ec20e47d350e16e1bf52f0396b777063b23770c7 (diff) |
Missing support for PolicySetType
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>
Diffstat (limited to 'applications/common/src/test')
2 files changed, 22 insertions, 9 deletions
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 46ad83b5..05d796ea 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 @@ -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 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 e191a08a..584390cd 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 @@ -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); |