2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.xacml.test.util;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24 import java.io.ByteArrayOutputStream;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.xacml.util.XACMLPolicyWriter;
35 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
36 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
38 public class XACMLPolicyWriterTest {
39 private static final Log logger = LogFactory.getLog(XACMLPolicyWriterTest.class);
40 private static Path configPolicyPathValue;
41 private static Path actionPolicyPathValue;
46 ClassLoader classLoader = getClass().getClassLoader();
48 templateFile = new File(classLoader.getResource("Config_SampleTest1206.1.xml").getFile());
49 configPolicyPathValue = templateFile.toPath();
50 templateFile = new File(classLoader.getResource("Action_TestActionPolicy.1.xml").getFile());
51 actionPolicyPathValue = templateFile.toPath();
52 } catch (Exception e1) {
53 logger.error("Exception Occured" + e1);
57 @SuppressWarnings("static-access")
59 public void xacmlPolicyWriterTest() throws IOException {
60 XACMLPolicyWriter writer = new XACMLPolicyWriter();
61 String configResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(configPolicyPathValue);
62 assertTrue(configResponseValue.equals("txt"));
63 String actionResponseValue = writer.changeFileNameInXmlWhenRenamePolicy(actionPolicyPathValue);
64 assertTrue(actionResponseValue.equals("json"));
68 public void testWrites() {
70 PolicyType policyType = new PolicyType();
71 OutputStream os = new ByteArrayOutputStream();
72 Path filename = Paths.get("/tmp/foo");
73 PolicySetType policySet = new PolicySetType();
75 // Test write combinations
76 assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policySet));
77 assertNotNull(XACMLPolicyWriter.writePolicyFile(filename, policyType));
78 assertNotNull(XACMLPolicyWriter.getXmlAsInputStream(policyType));
79 XACMLPolicyWriter.writePolicyFile(os, policySet);
80 assertNotNull(os.toString());
81 XACMLPolicyWriter.writePolicyFile(os, policyType);
82 assertNotNull(os.toString());