2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.policy.xacml.test.util;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import java.io.IOException;
28 import java.nio.file.Path;
29 import java.util.List;
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.XACMLPolicyScanner;
35 import com.att.research.xacml.util.XACMLPolicyScanner.Callback;
37 public class XACMLPolicyScannerTest {
39 private static final Log logger = LogFactory.getLog(XACMLPolicyScannerTest.class);
40 private static Path configPolicyPathValue;
41 private static Path actionPolicyPathValue;
46 ClassLoader classLoader = getClass().getClassLoader();
49 new File(classLoader.getResource("Config_SampleTest1206.1.xml").getFile());
50 configPolicyPathValue = templateFile.toPath();
52 new File(classLoader.getResource("Action_TestActionPolicy.1.xml").getFile());
53 actionPolicyPathValue = templateFile.toPath();
54 } catch (Exception e1) {
55 logger.error("Exception Occured" + e1);
60 public void xacmlPolicyScannerTest() throws IOException {
61 Callback callback = null;
63 XACMLPolicyScanner actionScanner =
64 new XACMLPolicyScanner(actionPolicyPathValue, callback);
65 assertTrue(actionScanner.getPolicyObject() != null);
66 Object actionObject = actionScanner.scan();
67 assertTrue(actionObject != null);
69 XACMLPolicyScanner scanner = new XACMLPolicyScanner(configPolicyPathValue, callback);
70 assertTrue(scanner.getPolicyObject() != null);
71 Object object = scanner.scan();
72 assertTrue(object != null);
73 String id = XACMLPolicyScanner.getID(scanner.getPolicyObject());
74 assertTrue(id.equals("urn:com:xacml:policy:id:0b67998b-57e2-4e25-9ea9-f9154bf18df1"));
75 String version = XACMLPolicyScanner.getVersion(scanner.getPolicyObject());
76 assertTrue(version.equals("1"));
77 String versionFromPath = XACMLPolicyScanner.getVersion(configPolicyPathValue);
78 assertTrue(versionFromPath.equals("1"));
79 List<String> returnValue =
80 XACMLPolicyScanner.getCreatedByModifiedBy(configPolicyPathValue);
81 assertTrue(returnValue.get(0).equals("test"));
82 String createdBy = XACMLPolicyScanner.getCreatedBy(configPolicyPathValue);
83 assertTrue(createdBy.equals("test"));
84 String modifiedBy = XACMLPolicyScanner.getModifiedBy(configPolicyPathValue);
85 assertTrue(modifiedBy.equals("test"));
86 } catch (Exception e) {
88 logger.error("Exception Occured" + e);