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