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.assertTrue;
23 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import java.nio.file.Path;
28 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;
36 import com.att.research.xacml.util.XACMLPolicyScanner.Callback;
38 public class XACMLPolicyScannerTest {
40 private static final Log logger = LogFactory.getLog(XACMLPolicyScannerTest.class);
41 private static Path configPolicyPathValue;
42 private static Path actionPolicyPathValue;
47 ClassLoader classLoader = getClass().getClassLoader();
49 templateFile = new File(classLoader.getResource("Config_SampleTest1206.1.xml").getFile());
50 configPolicyPathValue = templateFile.toPath();
51 templateFile = new File(classLoader.getResource("Action_TestActionPolicy.1.xml").getFile());
52 actionPolicyPathValue = templateFile.toPath();
53 } catch (Exception e1) {
54 logger.error("Exception Occured"+e1);
59 public void xacmlPolicyScannerTest() throws IOException{
60 Callback callback = null;
62 XACMLPolicyScanner actionScanner = new XACMLPolicyScanner(actionPolicyPathValue, callback);
63 assertTrue(actionScanner.getPolicyObject() != null);
64 Object actionObject = actionScanner.scan();
65 assertTrue(actionObject != null);
67 XACMLPolicyScanner scanner = new XACMLPolicyScanner(configPolicyPathValue, callback);
68 assertTrue(scanner.getPolicyObject() != null);
69 Object object = scanner.scan();
70 assertTrue(object != null);
71 String id = XACMLPolicyScanner.getID(scanner.getPolicyObject());
72 assertTrue(id.equals("urn:com:xacml:policy:id:0b67998b-57e2-4e25-9ea9-f9154bf18df1"));
73 String version = XACMLPolicyScanner.getVersion(scanner.getPolicyObject());
74 assertTrue(version.equals("1"));
75 String versionFromPath = XACMLPolicyScanner.getVersion(configPolicyPathValue);
76 assertTrue(versionFromPath.equals("1"));
77 List<String> returnValue = XACMLPolicyScanner.getCreatedByModifiedBy(configPolicyPathValue);
78 assertTrue(returnValue.get(0).equals("test"));
79 String createdBy = XACMLPolicyScanner.getCreatedBy(configPolicyPathValue);
80 assertTrue(createdBy.equals("test"));
81 String modifiedBy = XACMLPolicyScanner.getModifiedBy(configPolicyPathValue);
82 assertTrue(modifiedBy.equals("test"));
85 logger.error("Exception Occured"+e);