2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.xacml.test.std.pap;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.CoreMatchers.not;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertThat;
28 import static org.junit.Assert.assertTrue;
29 import java.util.HashSet;
30 import java.util.Properties;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.common.logging.flexlogger.FlexLogger;
35 import org.onap.policy.common.logging.flexlogger.Logger;
36 import org.onap.policy.xacml.std.pap.StdPDP;
37 import org.onap.policy.xacml.std.pap.StdPDPStatus;
38 import com.att.research.xacml.api.pap.PDPPIPConfig;
39 import com.att.research.xacml.api.pap.PDPPolicy;
41 public class StdPDPTest {
43 private static Logger logger = FlexLogger.getLogger(StdPDPTest.class);
45 private StdPDP stdPDP;
51 stdPDP = new StdPDP();
52 } catch (Exception e) {
58 public void testGetId() {
60 stdPDP.setId("testId");
61 assertTrue(stdPDP.getId() != null);
62 } catch (Exception e) {
68 public void testGetName() {
70 stdPDP.setName("abc");
71 assertTrue(stdPDP.getName() != null);
72 } catch (Exception e) {
78 public void testGetDescription() {
80 stdPDP.setDescription("somee here");
81 assertTrue(stdPDP.getDescription() != null);
82 } catch (Exception e) {
88 public void testGetStatus() {
90 stdPDP.setStatus(new StdPDPStatus());
91 assertTrue(stdPDP.getStatus() != null);
92 } catch (Exception e) {
98 public void testGetPipConfigs() {
100 assertTrue(stdPDP.getPipConfigs() != null);
101 } catch (Exception e) {
107 public void testGetJmxPort() {
109 stdPDP.setJmxPort(123);
110 assertTrue(stdPDP.getJmxPort() != null);
111 } catch (Exception e) {
117 public void testPDP() {
119 String id = "testID";
120 String value = "testVal";
121 Properties props = new Properties();
122 props.setProperty(id + ".name", value);
123 props.setProperty(id + ".description", value);
124 props.setProperty(id + ".jmxport", "0");
125 Set<PDPPIPConfig> pipConfigs = new HashSet<PDPPIPConfig>();
126 Set<PDPPolicy> policies = new HashSet<PDPPolicy>();
129 StdPDP pdp = new StdPDP(id, 0);
131 StdPDP pdp2 = new StdPDP(id, value, 0);
133 StdPDP pdp3 = new StdPDP(id, value, value, 0);
135 StdPDP pdp4 = new StdPDP(id, props);
137 StdPDP pdp5 = new StdPDP(id, props);
141 pdp.setPipConfigs(pipConfigs);
142 assertEquals(pipConfigs, pdp.getPipConfigs());
143 pdp.setPolicies(policies);
144 assertEquals(policies, pdp.getPolicies());
146 // Test equals combinations
147 assertEquals(true, pdp4.equals(pdp5));
148 assertEquals(true, pdp4.equals(pdp4));
149 assertEquals(false, pdp4.equals(null));
150 assertEquals(false, pdp4.equals(value));
152 assertEquals(false, pdp4.equals(value));
154 assertEquals(false, pdp4.equals(pdp5));
156 assertEquals(false, pdp4.equals(pdp5));
157 assertThat(pdp.hashCode(), is(not(0)));
160 assertEquals(-1, pdp4.compareTo(null));
161 assertEquals(0, pdp4.compareTo(pdp4));
163 assertEquals(-1, pdp4.compareTo(pdp5));
166 assertEquals(1, pdp4.compareTo(pdp5));
169 assertThat(pdp.toString().length(), is(not(0)));