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;
29 import com.att.research.xacml.util.XACMLProperties;
31 import java.io.IOException;
32 import org.junit.FixMethodOrder;
33 import org.junit.Test;
34 import org.junit.runners.MethodSorters;
36 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
37 public class CheckPdpPropertiesTest {
40 public final void test1NoPropertySet() throws IOException {
41 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "noexistenfile.properties");
42 assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
44 System.clearProperty(XACMLProperties.XACML_PROPERTIES_NAME);
45 System.clearProperty("xacml.rest.pdp.idfile");
46 assertFalse(CheckPdpProperties.validateId("http://localhost:8082/pdp/"));
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/"));
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/"));
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/"));
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/"));
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/"));
70 assertNull(CheckPdpProperties.getPdpMap());
71 assertNull(CheckPdpProperties.getEncoding("http://localhost:8082/pdp/"));
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=="));