Improve ONAP-PDP-REST JUnit test case independency
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / ConfigPolicyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
4  * ================================================================================
5  * Copyright (C) 2018 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22 package org.onap.policy.pdp.rest.api.services;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.util.Arrays;
30 import java.util.List;
31 import java.util.Properties;
32
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.policy.api.PolicyParameters;
37
38 public class ConfigPolicyServiceTest {
39
40         private static final String SYSTEM_KEY = "xacml.properties";
41         private static String oldProperty;
42
43         @BeforeClass
44         public static void setUpBeforeClass() throws Exception {
45                 Properties prop = new Properties();
46                 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
47                 String succeeded = prop.getProperty("xacml.rest.pap.url");
48                 List<String> paps = Arrays.asList(succeeded.split(","));
49                 PAPServices.setPaps(paps);
50                 PAPServices.setJunit(true);
51                 oldProperty = System.getProperty(SYSTEM_KEY);
52         }
53
54         @AfterClass
55         public static void tearDownAfterClass() {
56                 PAPServices.setPaps(null);
57                 PAPServices.setJunit(false);
58                 // Restore the original system property
59                 if (oldProperty != null) {
60                         System.setProperty(SYSTEM_KEY, oldProperty);
61                 } else {
62                         System.clearProperty(SYSTEM_KEY);
63                 }
64         }
65
66         @Test
67         public void testRaw() throws FileNotFoundException, IOException {
68
69                 String testVal = "testVal";
70                 PolicyParameters testParams = new PolicyParameters();
71
72                 // Set the system property temporarily
73                 System.setProperty(SYSTEM_KEY, "xacml.pdp.properties");
74
75                 ConfigPolicyService service = new ConfigPolicyService(testVal, testVal, testParams, testVal);
76                 assertEquals(service.getValidation(), false);
77                 assertEquals(service.getMessage(), "PE300 - Data Issue: No Config Body given.");
78         }
79 }