JUnit addition for PAP-REST
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / components / PolicyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2019 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
21 package org.onap.policy.pap.xacml.rest.components;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 import com.att.research.xacml.util.XACMLProperties;
28
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.policy.rest.adapter.PolicyRestAdapter;
35
36 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
37
38 public class PolicyTest {
39     @Test
40     public void testPolicy() {
41         // Setup test data
42         System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "xacml.pap.properties");
43         PolicyRestAdapter adapter = Mockito.mock(PolicyRestAdapter.class);
44         Policy policy = new ConfigPolicy(adapter);
45         Path path = Paths.get("src/test/resources");
46
47         // Test set and get
48         policy.setFinalPolicyPath(path);
49         assertEquals(path, policy.getFinalPolicyPath());
50
51         // Test misc methods
52         assertNotNull(policy.createMatch("testKey", "testVal"));
53         assertNotNull(policy.createDynamicMatch("testKey", "testVal"));
54         assertNotNull(policy.getNextFilename(path, "Config", "SampleTest1206", 1));
55         assertNull(policy.getNextLoopFilename(path, "Config", "ClosedLoop_PM", "foo", 1));
56         assertNull(policy.getNextLoopFilename(path, "Config", "ClosedLoop_Fault", "foo", 1));
57         assertNull(policy.getNextLoopFilename(path, "Config", "Micro Service", "foo", 1));
58         assertNull(policy.getNextLoopFilename(path, "Config", "Optimization", "foo", 1));
59
60         // Test create
61         Object policyData = null;
62         assertEquals(0, policy.createPolicy(null, policyData).size());
63         policyData = new PolicyType();
64         assertEquals(1, policy.createPolicy(null, policyData).size());
65
66         // Test remaining set and get
67         assertNotNull(Policy.getConfigHome());
68         assertEquals(true, policy.validateConfigForm());
69         policy.setPreparedToSave(true);
70         assertEquals(true, policy.isPreparedToSave());
71         policy.setPolicyExists(true);
72         assertEquals(true, policy.isPolicyExists());
73     }
74 }