2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.admin;
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;
29 import org.junit.FixMethodOrder;
30 import org.junit.Test;
31 import org.junit.runners.MethodSorters;
33 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
34 public class CheckPDPTest {
37 public final void test1NoPropertySet() {
39 System.clearProperty("xacml.rest.pdp.idfile");
40 assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
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/"));
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/"));
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/"));
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/"));
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/"));
72 assertNull(CheckPDP.getPdpMap());
73 assertNull(CheckPDP.getEncoding("http://localhost:8082/pdp/"));
75 } catch (Exception e) {
76 fail("Error occured in CheckPDP test");
81 public final void test2CheckPDP() {
83 System.setProperty("xacml.rest.pdp.idfile",
84 new File(".").getCanonicalPath() + File.separator + "src" + File.separator
85 + "test" + File.separator + "resources" + File.separator
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");