358b69f1f35e0fc9e1e864af7fd0ef6b2adcb942
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / admin / CheckPDPTest.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 import static org.junit.Assert.fail;
29
30 import java.io.File;
31
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 CheckPDPTest {
38
39     @Test
40     public final void test1NoPropertySet() {
41         try {
42             System.clearProperty("xacml.rest.pdp.idfile");
43             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
44
45             System.setProperty("xacml.rest.pdp.idfile",
46                     new File(".").getCanonicalPath() + File.separator + "src" + File.separator + "test" + File.separator
47                             + "resources" + File.separator + "idonotexist.properties");
48             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
49
50             System.setProperty("xacml.rest.pdp.idfile",
51                     new File(".").getCanonicalPath() + File.separator + "src" + File.separator + "test" + File.separator
52                             + "resources" + File.separator + "doesnothaveproperties.atall");
53             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
54
55             System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
56                     + File.separator + "test" + File.separator + "resources" + File.separator + "testbad.properties");
57             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
58
59             System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
60                     + File.separator + "test" + File.separator + "resources" + File.separator + "empty.properties");
61             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
62
63             System.setProperty("xacml.rest.pdp.idfile",
64                     new File(".").getCanonicalPath() + File.separator + "src" + File.separator + "test" + File.separator
65                             + "resources" + File.separator + "testnotenoughvalues.properties");
66             assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
67
68             assertNull(CheckPDP.getPdpMap());
69             assertNull(CheckPDP.getEncoding("http://localhost:8082/pdp/"));
70
71         } catch (Exception e) {
72             fail("Error occured in CheckPDP test");
73         }
74     }
75
76     @Test
77     public final void test2CheckPDP() {
78         try {
79             System.setProperty("xacml.rest.pdp.idfile", new File(".").getCanonicalPath() + File.separator + "src"
80                     + File.separator + "test" + File.separator + "resources" + File.separator + "test.properties");
81             assertTrue(CheckPDP.validateID("http://localhost:8082/pdp/"));
82             assertTrue(CheckPDP.getPdpMap().containsKey("http://localhost:8082/pdp/"));
83             assertTrue(CheckPDP.getEncoding("http://localhost:8082/pdp/").equals("dGVzdHBkcDphbHBoYTQ1Ng=="));
84         } catch (Exception e) {
85             fail("Error occured in CheckPDP test");
86         }
87     }
88 }