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.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;
32 import com.att.research.xacml.api.pap.PDPPIPConfig;
33 import com.att.research.xacml.api.pap.PDPPolicy;
35 import java.util.HashSet;
36 import java.util.Properties;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.onap.policy.common.logging.flexlogger.FlexLogger;
42 import org.onap.policy.common.logging.flexlogger.Logger;
43 import org.onap.policy.xacml.std.pap.StdPDP;
44 import org.onap.policy.xacml.std.pap.StdPDPStatus;
46 public class StdPDPTest {
48 private static Logger logger = FlexLogger.getLogger(StdPDPTest.class);
50 private StdPDP stdPDP;
56 stdPDP = new StdPDP();
57 } catch (Exception e) {
63 public void testGetId() {
65 stdPDP.setId("testId");
66 assertTrue(stdPDP.getId() != null);
67 } catch (Exception e) {
73 public void testGetName() {
75 stdPDP.setName("abc");
76 assertTrue(stdPDP.getName() != null);
77 } catch (Exception e) {
83 public void testGetDescription() {
85 stdPDP.setDescription("somee here");
86 assertTrue(stdPDP.getDescription() != null);
87 } catch (Exception e) {
93 public void testGetStatus() {
95 stdPDP.setStatus(new StdPDPStatus());
96 assertTrue(stdPDP.getStatus() != null);
97 } catch (Exception e) {
103 public void testGetPipConfigs() {
105 assertTrue(stdPDP.getPipConfigs() != null);
106 } catch (Exception e) {
112 public void testGetJmxPort() {
114 stdPDP.setJmxPort(123);
115 assertTrue(stdPDP.getJmxPort() != null);
116 } catch (Exception e) {
122 public void testPdp() {
124 String id = "testID";
125 String value = "testVal";
126 Properties props = new Properties();
127 props.setProperty(id + ".name", value);
128 props.setProperty(id + ".description", value);
129 props.setProperty(id + ".jmxport", "0");
130 props.setProperty(id + ".foo", "0");
131 props.setProperty("foo" + ".jmxport", "0");
134 StdPDP pdp = new StdPDP(id, 0);
136 StdPDP pdp2 = new StdPDP(id, value, 0);
138 StdPDP pdp3 = new StdPDP(id, value, value, 0);
140 StdPDP pdp4 = new StdPDP(id, props);
142 StdPDP pdp5 = new StdPDP(id, props);
144 StdPDP pdp6 = new StdPDP(id, value, value, null);
148 Set<PDPPIPConfig> pipConfigs = new HashSet<PDPPIPConfig>();
149 Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
150 pdp.setPipConfigs(pipConfigs);
151 assertEquals(pipConfigs, pdp.getPipConfigs());
152 pdp.setPolicies(policies);
153 assertEquals(policies, pdp.getPolicies());
155 // Test equals combinations
156 assertEquals(true, pdp4.equals(pdp5));
157 assertEquals(true, pdp4.equals(pdp4));
158 assertEquals(false, pdp4.equals(null));
159 assertEquals(false, pdp4.equals(value));
161 assertEquals(false, pdp4.equals(value));
163 assertEquals(false, pdp4.equals(pdp5));
165 assertEquals(false, pdp4.equals(pdp5));
166 assertThat(pdp.hashCode(), is(not(0)));
169 assertEquals(-1, pdp4.compareTo(null));
170 assertEquals(0, pdp4.compareTo(pdp4));
172 assertEquals(-1, pdp4.compareTo(pdp5));
175 assertEquals(1, pdp4.compareTo(pdp5));
178 assertThat(pdp.toString().length(), is(not(0)));