2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.xacml.test.std.pap;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.CoreMatchers.not;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertThat;
30 import static org.junit.Assert.assertTrue;
31 import java.util.HashSet;
32 import java.util.Properties;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
37 import org.onap.policy.common.logging.flexlogger.Logger;
38 import org.onap.policy.xacml.std.pap.StdPDP;
39 import org.onap.policy.xacml.std.pap.StdPDPStatus;
40 import com.att.research.xacml.api.pap.PDPPIPConfig;
41 import com.att.research.xacml.api.pap.PDPPolicy;
43 public class StdPDPTest {
45 private static Logger logger = FlexLogger.getLogger(StdPDPTest.class);
47 private StdPDP stdPDP;
53 stdPDP = new StdPDP();
54 } catch (Exception e) {
60 public void testGetId() {
62 stdPDP.setId("testId");
63 assertTrue(stdPDP.getId() != null);
64 } catch (Exception e) {
70 public void testGetName() {
72 stdPDP.setName("abc");
73 assertTrue(stdPDP.getName() != null);
74 } catch (Exception e) {
80 public void testGetDescription() {
82 stdPDP.setDescription("somee here");
83 assertTrue(stdPDP.getDescription() != null);
84 } catch (Exception e) {
90 public void testGetStatus() {
92 stdPDP.setStatus(new StdPDPStatus());
93 assertTrue(stdPDP.getStatus() != null);
94 } catch (Exception e) {
100 public void testGetPipConfigs() {
102 assertTrue(stdPDP.getPipConfigs() != null);
103 } catch (Exception e) {
109 public void testGetJmxPort() {
111 stdPDP.setJmxPort(123);
112 assertTrue(stdPDP.getJmxPort() != null);
113 } catch (Exception e) {
119 public void testPDP() {
121 String id = "testID";
122 String value = "testVal";
123 Properties props = new Properties();
124 props.setProperty(id + ".name", value);
125 props.setProperty(id + ".description", value);
126 props.setProperty(id + ".jmxport", "0");
127 Set<PDPPIPConfig> pipConfigs = new HashSet<PDPPIPConfig>();
128 Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
131 StdPDP pdp = new StdPDP(id, 0);
133 StdPDP pdp2 = new StdPDP(id, value, 0);
135 StdPDP pdp3 = new StdPDP(id, value, value, 0);
137 StdPDP pdp4 = new StdPDP(id, props);
139 StdPDP pdp5 = new StdPDP(id, props);
143 pdp.setPipConfigs(pipConfigs);
144 assertEquals(pipConfigs, pdp.getPipConfigs());
145 pdp.setPolicies(policies);
146 assertEquals(policies, pdp.getPolicies());
148 // Test equals combinations
149 assertEquals(true, pdp4.equals(pdp5));
150 assertEquals(true, pdp4.equals(pdp4));
151 assertEquals(false, pdp4.equals(null));
152 assertEquals(false, pdp4.equals(value));
154 assertEquals(false, pdp4.equals(value));
156 assertEquals(false, pdp4.equals(pdp5));
158 assertEquals(false, pdp4.equals(pdp5));
159 assertThat(pdp.hashCode(), is(not(0)));
162 assertEquals(-1, pdp4.compareTo(null));
163 assertEquals(0, pdp4.compareTo(pdp4));
165 assertEquals(-1, pdp4.compareTo(pdp5));
168 assertEquals(1, pdp4.compareTo(pdp5));
171 assertThat(pdp.toString().length(), is(not(0)));