[POLICY-122] Policy GUI Fixes
[policy/engine.git] / ECOMP-XACML / src / test / java / org / openecomp / policy / xacml / test / util / XACMLPolicyScannerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-XACML
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.openecomp.policy.xacml.test.util;
21
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.file.Path;
28 import java.util.List;
29
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.openecomp.policy.xacml.util.XACMLPolicyScanner;
35
36 import com.att.research.xacml.util.XACMLPolicyScanner.Callback;
37
38 public class XACMLPolicyScannerTest {
39
40         private static final Log logger                         = LogFactory.getLog(XACMLPolicyScannerTest.class);
41         private static Path configPolicyPathValue;
42         private static Path actionPolicyPathValue;
43         
44         @Before
45         public void setUp() {
46                 File templateFile;
47                 ClassLoader classLoader = getClass().getClassLoader();
48         try {
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);
55                 }
56         }
57         
58         @Test
59         public void xacmlPolicyScannerTest() throws IOException{
60                 Callback callback = null;
61                 try{
62                         XACMLPolicyScanner actionScanner = new XACMLPolicyScanner(actionPolicyPathValue, callback);
63                         assertTrue(actionScanner.getPolicyObject() != null);
64                         Object actionObject = actionScanner.scan();
65                         assertTrue(actionObject != null);
66                         
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"));
83                 }catch(Exception e){
84                         fail();
85                         logger.error("Exception Occured"+e);
86                 }
87         }
88 }