summaryrefslogtreecommitdiffstats
path: root/ONAP-XACML/src/test
diff options
context:
space:
mode:
authorbobbymander <bobby.mander@att.com>2018-04-02 14:35:37 -0400
committerbobbymander <bobby.mander@att.com>2018-04-02 15:47:02 -0400
commitb0b4b6397de13ac296ab82ed40df75fdf5846d83 (patch)
tree1c7027d69f8de1663a7c20db4fc7731f4e7ec76a /ONAP-XACML/src/test
parent26360c30af5ad955765ae0c3cb5bf2bfcf143669 (diff)
JUnit additions for PDP,PDP-REST,SDK,XACML
Issue-ID: POLICY-600 Change-Id: I8052451c3f66116f361f2963fcc2727c022dd4d9 Signed-off-by: bobbymander <bobby.mander@att.com>
Diffstat (limited to 'ONAP-XACML/src/test')
-rw-r--r--ONAP-XACML/src/test/java/org/onap/policy/xacml/test/util/XACMLPolicyWriterTest.java80
1 files changed, 51 insertions, 29 deletions
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());
+ }
}