2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.policy.pap.xacml.rest.components;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
27 import com.att.research.xacml.util.XACMLProperties;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.policy.rest.adapter.PolicyRestAdapter;
36 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
38 public class PolicyTest {
40 public void testPolicy() {
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");
48 policy.setFinalPolicyPath(path);
49 assertEquals(path, policy.getFinalPolicyPath());
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));
61 Object policyData = null;
62 assertEquals(0, policy.createPolicy(null, policyData).size());
63 policyData = new PolicyType();
64 assertEquals(1, policy.createPolicy(null, policyData).size());
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());