2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.xacml.test.std.pap;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.not;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertThat;
29 import java.io.IOException;
30 import java.net.ConnectException;
32 import java.net.URISyntaxException;
33 import java.util.Properties;
34 import org.junit.Test;
35 import org.onap.policy.xacml.std.pap.StdPDPPolicy;
36 import com.att.research.xacml.api.pap.PAPException;
37 import org.onap.policy.xacml.std.pap.StdPDPPolicyParams;
40 public class StdPDPPolicyTest {
42 public void testPolicy() throws URISyntaxException, IOException, PAPException {
44 String value = "testVal";
45 URI uri = new URI("http://localhost/");
49 StdPDPPolicy policy = new StdPDPPolicy(value, true);
50 assertNotNull(policy);
51 StdPDPPolicy policy2 = new StdPDPPolicy(value, true, value);
52 assertNotNull(policy2);
53 StdPDPPolicy policy4 = new StdPDPPolicy();
54 assertNotNull(policy4);
56 StdPDPPolicy policy5 = new StdPDPPolicy(StdPDPPolicyParams.builder()
66 assertNotNull(policy5);
67 StdPDPPolicy policy6 = new StdPDPPolicy(value, true, value, uri, false);
68 assertNotNull(policy6);
69 StdPDPPolicy policy8 = new StdPDPPolicy(value, true, value, uri, false);
70 assertNotNull(policy8);
74 assertEquals(value, policy.getId());
75 policy.setName(value);
76 assertEquals(value, policy.getName());
77 policy.setPolicyId(value);
78 assertEquals(value, policy.getPolicyId());
79 policy.setDescription(value);
80 assertEquals(value, policy.getDescription());
81 policy.setVersion("1");
82 assertEquals("1", policy.getVersion());
83 assertEquals(1, policy.getVersionInts()[0]);
84 assertEquals(true, policy.isRoot());
85 policy.setValid(true);
86 assertEquals(true, policy.isValid());
87 assertEquals(uri, policy5.getLocation());
88 policy.setRoot(false);
89 assertEquals(false, policy.isRoot());
90 policy.setLocation(uri);
91 assertEquals(uri, policy.getLocation());
93 // Test equals combinations
94 assertThat(policy.hashCode(), is(not(0)));
95 assertEquals(true, policy.equals(policy));
96 assertEquals(false, policy.equals(null));
97 assertEquals(false, policy.equals(value));
98 assertEquals(true, policy6.equals(policy8));
100 assertEquals(false, policy6.equals(policy8));
102 assertEquals(false, policy6.equals(policy8));
104 assertEquals(true, policy6.equals(policy8));
105 policy8.setPolicyId(value);
106 assertEquals(false, policy6.equals(policy8));
107 policy6.setPolicyId("1");
108 policy8.setPolicyId("2");
109 assertEquals(false, policy6.equals(policy8));
110 policy8.setPolicyId("1");
111 policy6.setVersion("1");
112 policy8.setVersion("2");
113 assertEquals(false, policy6.equals(policy8));
116 assertThat(policy.toString().length(), is(not(0)));
117 assertEquals("1.1", StdPDPPolicy.versionArrayToString(array));
118 assertEquals("", StdPDPPolicy.versionArrayToString(null));
119 assertEquals(0, StdPDPPolicy.versionStringToArray(null).length);
122 @Test(expected = ConnectException.class)
123 public void negTestStream() throws URISyntaxException, IOException, PAPException {
125 String value = "testVal";
126 URI uri = new URI("http://localhost:54287");
127 StdPDPPolicy policy = new StdPDPPolicy(StdPDPPolicyParams.builder()
138 // Negative test stream
142 @Test(expected = ConnectException.class)
143 public void negTestConstructor1() throws URISyntaxException, IOException {
145 String value = "testVal";
146 URI uri = new URI("http://localhost:54287");
149 StdPDPPolicy policy = new StdPDPPolicy(value, true, value, uri);
150 assertNotNull(policy);
153 @Test(expected = ConnectException.class)
154 public void negTestConstructor2() throws URISyntaxException, IOException {
156 String value = "testVal";
157 URI uri = new URI("http://localhost:54287");
158 Properties props = new Properties();
161 StdPDPPolicy policy = new StdPDPPolicy(value, true, uri, props);
162 assertNotNull(policy);