Cleanup POLICY-SDK-APP CheckPDP
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / admin / CheckPdpPropertiesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 2019 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
23 package org.onap.policy.admin;
24
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28
29 import com.att.research.xacml.util.XACMLProperties;
30 import java.io.File;
31 import java.io.IOException;
32 import org.junit.FixMethodOrder;
33 import org.junit.Test;
34 import org.junit.runners.MethodSorters;
35
36 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
37 public class CheckPdpPropertiesTest {
38
39     @Test
40     public final void test1NoPropertySet() throws IOException {
41         System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "noexistenfile.properties");
42         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
43
44         System.clearProperty(XACMLProperties.XACML_PROPERTIES_NAME);
45         System.clearProperty("xacml.rest.pdp.idfile");
46         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
47
48         System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
49                 + File.separator + "test" + File.separator + "resources" + File.separator + "idonotexist.properties");
50         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
51
52         System.setProperty("xacml.rest.pdp.idfile",
53                 new File(".").getCanonicalPath() + File.separator + "src" + File.separator + "test" + File.separator
54                         + "resources" + File.separator + "doesnothaveproperties.atall");
55         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
56
57         System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
58                 + File.separator + "test" + File.separator + "resources" + File.separator + "testbad.properties");
59         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
60
61         System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
62                 + File.separator + "test" + File.separator + "resources" + File.separator + "empty.properties");
63         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
64
65         System.setProperty("xacml.rest.pdp.idfile",
66                 new File(".").getCanonicalPath() + File.separator + "src" + File.separator + "test" + File.separator
67                         + "resources" + File.separator + "testnotenoughvalues.properties");
68         assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
69
70         assertNull(CheckPdpProperties.getPdpMap());
71         assertNull(CheckPdpProperties.getEncoding("http://localhost:8082/pdp/"));
72     }
73
74     @Test
75     public final void test2CheckPdp() throws IOException {
76         System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
77                 + File.separator + "test" + File.separator + "resources" + File.separator + "test.properties");
78         assertTrue(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
79         assertTrue(CheckPdpProperties.getPdpMap().containsKey("http://localhost:8082/pdp/"));
80         assertTrue(CheckPdpProperties.getEncoding("http://localhost:8082/pdp/").equals("dGVzdHBkcDphbHBoYTQ1Ng=="));
81     }
82 }