2 * ============LICENSE_START=======================================================
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
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=========================================================
23 package org.onap.policy.admin;
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;
32 import org.junit.FixMethodOrder;
33 import org.junit.Test;
34 import org.junit.runners.MethodSorters;
36 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
37 public class CheckPDPTest {
40 public final void test1NoPropertySet() {
42 System.clearProperty("xacml.rest.pdp.idfile");
43 assertFalse(CheckPDP.validateID("http://localhost:8082/pdp/"));
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/"));
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/"));
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/"));
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/"));
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/"));
68 assertNull(CheckPDP.getPdpMap());
69 assertNull(CheckPDP.getEncoding("http://localhost:8082/pdp/"));
71 } catch (Exception e) {
72 fail("Error occured in CheckPDP test");
77 public final void test2CheckPDP() {
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");