summaryrefslogtreecommitdiffstats
path: root/applications/native/src/test/java
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-03-16 11:09:36 -0400
committerPamela Dragosh <pdragosh@research.att.com>2020-03-16 11:24:19 -0400
commit6b4f9b69bc4acec28da8ef50b8f234d0182f0d78 (patch)
tree877cc134b10d08393f0868a7dae7d5f604e49a5b /applications/native/src/test/java
parentec20e47d350e16e1bf52f0396b777063b23770c7 (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/native/src/test/java')
-rw-r--r--applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java65
1 files changed, 64 insertions, 1 deletions
diff --git a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
index b25c2a31..a11c1b14 100644
--- a/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
+++ b/applications/native/src/test/java/org/onap/policy/xacml/pdp/application/nativ/NativePdpApplicationTest.java
@@ -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();
@@ -111,6 +121,59 @@ public class NativePdpApplicationTest {
}
@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 {
LOGGER.info("*********** Running native policy test *************");
@@ -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();