From b0b4b6397de13ac296ab82ed40df75fdf5846d83 Mon Sep 17 00:00:00 2001 From: bobbymander Date: Mon, 2 Apr 2018 14:35:37 -0400 Subject: JUnit additions for PDP,PDP-REST,SDK,XACML Issue-ID: POLICY-600 Change-Id: I8052451c3f66116f361f2963fcc2727c022dd4d9 Signed-off-by: bobbymander --- .../xacml/test/util/XACMLPolicyWriterTest.java | 80 ++++++++++++++-------- 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'ONAP-XACML/src/test') diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/util/XACMLPolicyWriterTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/util/XACMLPolicyWriterTest.java index c948716dc..0a3a5e095 100644 --- a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/util/XACMLPolicyWriterTest.java +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/util/XACMLPolicyWriterTest.java @@ -19,44 +19,66 @@ */ package org.onap.policy.xacml.test.util; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.nio.file.Path; - +import java.nio.file.Paths; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.junit.Test; import org.onap.policy.xacml.util.XACMLPolicyWriter; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; public class XACMLPolicyWriterTest { - private static final Log logger = LogFactory.getLog(XACMLPolicyWriterTest.class); - private static Path configPolicyPathValue; - private static Path actionPolicyPathValue; - - @Before - public void setUp() { - File templateFile; - ClassLoader classLoader = getClass().getClassLoader(); - try { - templateFile = new File(classLoader.getResource("Config_SampleTest1206.1.xml").getFile()); - configPolicyPathValue = templateFile.toPath(); - templateFile = new File(classLoader.getResource("Action_TestActionPolicy.1.xml").getFile()); - actionPolicyPathValue = templateFile.toPath(); - } catch (Exception e1) { - logger.error("Exception Occured"+e1); - } - } - - @SuppressWarnings("static-access") - @Test - public void xacmlPolicyWriterTest() throws IOException{ - XACMLPolicyWriter writer = new XACMLPolicyWriter(); - String configResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(configPolicyPathValue); - assertTrue(configResponseValue.equals("txt")); - String actionResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(actionPolicyPathValue); - assertTrue(actionResponseValue.equals("json")); - } + private static final Log logger = LogFactory.getLog(XACMLPolicyWriterTest.class); + private static Path configPolicyPathValue; + private static Path actionPolicyPathValue; + + @Before + public void setUp() { + File templateFile; + ClassLoader classLoader = getClass().getClassLoader(); + try { + templateFile = new File(classLoader.getResource("Config_SampleTest1206.1.xml").getFile()); + configPolicyPathValue = templateFile.toPath(); + templateFile = new File(classLoader.getResource("Action_TestActionPolicy.1.xml").getFile()); + actionPolicyPathValue = templateFile.toPath(); + } catch (Exception e1) { + logger.error("Exception Occured" + e1); + } + } + + @SuppressWarnings("static-access") + @Test + public void xacmlPolicyWriterTest() throws IOException { + XACMLPolicyWriter writer = new XACMLPolicyWriter(); + String configResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(configPolicyPathValue); + assertTrue(configResponseValue.equals("txt")); + String actionResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(actionPolicyPathValue); + assertTrue(actionResponseValue.equals("json")); + } + + @Test + public void testWrites() { + // Set up test data + PolicyType policyType = new PolicyType(); + OutputStream os = new ByteArrayOutputStream(); + Path filename = Paths.get("/tmp/foo"); + PolicySetType policySet = new PolicySetType(); + + // Test write combinations + assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policySet)); + assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policyType)); + assertNotNull(XACMLPolicyWriter.getXmlAsInputStream(policyType)); + XACMLPolicyWriter.writePolicyFile(os, policySet); + assertNotNull(os.toString()); + XACMLPolicyWriter.writePolicyFile(os, policyType); + assertNotNull(os.toString()); + } } -- cgit 1.2.3-korg