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