2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
20 package org.onap.policy.pdp.rest.api.test;
22 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
23 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
24 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
25 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
26 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
27 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
29 import java.io.IOException;
30 import java.lang.reflect.InvocationTargetException;
31 import java.lang.reflect.Method;
32 import java.util.Date;
33 import java.util.HashMap;
35 import java.util.UUID;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.onap.policy.api.AttributeType;
41 import org.onap.policy.api.ConfigRequestParameters;
42 import org.onap.policy.api.DecisionRequestParameters;
43 import org.onap.policy.api.DeletePolicyCondition;
44 import org.onap.policy.api.DeletePolicyParameters;
45 import org.onap.policy.api.DictionaryParameters;
46 import org.onap.policy.api.DictionaryType;
47 import org.onap.policy.api.EventRequestParameters;
48 import org.onap.policy.api.PolicyClass;
49 import org.onap.policy.api.PolicyConfigType;
50 import org.onap.policy.api.PolicyParameters;
51 import org.onap.policy.api.PolicyType;
52 import org.onap.policy.api.PushPolicyParameters;
53 import org.onap.policy.pdp.rest.XACMLPdpServlet;
54 import org.onap.policy.pdp.rest.api.models.ConfigFirewallPolicyAPIRequest;
55 import org.onap.policy.pdp.rest.api.models.ConfigNameRequest;
56 import org.onap.policy.pdp.rest.api.models.ConfigPolicyAPIRequest;
57 import org.onap.policy.pdp.rest.api.services.CreateUpdatePolicyServiceImpl;
58 import org.onap.policy.pdp.rest.config.PDPRestConfig;
59 import org.onap.policy.utils.PolicyUtils;
60 import org.springframework.beans.factory.annotation.Autowired;
61 import org.springframework.http.HttpHeaders;
62 import org.springframework.http.MediaType;
63 import org.springframework.test.context.ContextConfiguration;
64 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
65 import org.springframework.test.context.web.WebAppConfiguration;
66 import org.springframework.test.web.servlet.MockMvc;
67 import org.springframework.web.context.WebApplicationContext;
69 import com.att.research.xacml.util.XACMLProperties;
71 @RunWith(SpringJUnit4ClassRunner.class)
72 @ContextConfiguration(classes = {PDPRestConfig.class})
74 public class PolicyEngineServicesTest {
75 private static final String CLIENTAUTHHEADER = "ClientAuth";
76 private static final String UUIDHEADER = "X-ECOMP-RequestID";
77 // This value is as per test resource code. Don't change this.
78 private static final String CLIENTAUTHVALUE = "Basic cHl0aG9uOnRlc3Q=";
79 private static final String ERRORCLIENTVALUE = "Basic dGVzdDp0ZXN0MTIz";
81 private MockMvc mockMvc;
82 private HttpHeaders headers;
85 private WebApplicationContext webApplicationContext;
88 public void setup() throws IOException{
89 headers = new HttpHeaders();
90 headers.add(CLIENTAUTHHEADER, CLIENTAUTHVALUE);
91 XACMLProperties.reloadProperties();
92 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/pass.xacml.pdp.properties");
93 XACMLProperties.getProperties();
94 this.mockMvc = webAppContextSetup(webApplicationContext).build();
98 public void getConfigAPIFailureTest() throws Exception{
99 ConfigRequestParameters pep = new ConfigRequestParameters();
100 pep.setPolicyName(".*");
101 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
102 .andExpect(status().is(400));
103 // Authorization tests.
104 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
105 .andExpect(status().isUnauthorized());
106 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123"))
107 .andExpect(status().isUnauthorized());
108 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ERRORCLIENTVALUE))
109 .andExpect(status().isUnauthorized());
110 // Set wrong request.
111 pep.setPolicyName(null);
112 pep.setConfigName("test");
113 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, "123").contentType(MediaType.APPLICATION_JSON))
114 .andExpect(status().isBadRequest());
118 public void getConfigServiceTest() throws Exception{
119 ConfigRequestParameters pep = new ConfigRequestParameters();
120 pep.setPolicyName(".*");
121 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
122 .andExpect(status().isOk());
123 // Without policyName and using onapName and other fields.
124 pep.setPolicyName(null);
125 pep.setOnapName("test");
126 pep.setConfigName("test");
127 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).contentType(MediaType.APPLICATION_JSON))
128 .andExpect(status().isOk());
129 // with config attributes.
130 Map<String, String> configAttributes = new HashMap<>();
131 configAttributes.put("test", "test");
132 pep.setConfigAttributes(configAttributes);
133 pep.makeUnique(true);
134 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).contentType(MediaType.APPLICATION_JSON))
135 .andExpect(status().isOk());
139 public void getConfigByPolicyNameTest() throws Exception{
140 ConfigNameRequest pep = new ConfigNameRequest();
141 pep.setPolicyName(".*");
142 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
143 .andExpect(status().is(400));
144 // Authorization tests.
145 mockMvc.perform(post("/getConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
146 .andExpect(status().isUnauthorized());
147 mockMvc.perform(post("/getConfigByPolicyName").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
148 .andExpect(status().isOk());
152 public void listConfigTest() throws Exception{
153 ConfigRequestParameters pep = new ConfigRequestParameters();
154 pep.setPolicyName(".*");
155 mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON))
156 .andExpect(status().is(400));
157 // Authorization tests.
158 mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, ""))
159 .andExpect(status().isUnauthorized());
160 mockMvc.perform(post("/listConfig").content(PolicyUtils.objectToJsonString(pep)).headers(headers).header(UUIDHEADER, UUID.randomUUID()).contentType(MediaType.APPLICATION_JSON))
161 .andExpect(status().isOk());
165 public void getMetricsTest() throws Exception{
167 mockMvc.perform(get("/getMetrics")).andExpect(status().isBadRequest());
168 mockMvc.perform(get("/getMetrics").header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
170 mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
171 mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isOk());
172 mockMvc.perform(get("/getMetrics").headers(headers)).andExpect(status().isOk());
176 public void getNotificationAuthFailureTest() throws Exception{
177 mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "").content("test")).andExpect(status().isUnauthorized());
178 mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, "Basic test123").content("test")).andExpect(status().isUnauthorized());
179 mockMvc.perform(post("/getNotification").header(CLIENTAUTHHEADER, ERRORCLIENTVALUE).content(" ")).andExpect(status().isUnauthorized());
183 public void getNotificationTopicFailureTest() throws Exception{
184 mockMvc.perform(post("/getNotification")).andExpect(status().isBadRequest());
185 mockMvc.perform(post("/getNotification").headers(headers).content("")).andExpect(status().isBadRequest());
189 public void getNotificationTopicValidFailTest() throws Exception{
191 mockMvc.perform(post("/getNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
192 mockMvc.perform(post("/stopNotification").headers(headers).content(" ")).andExpect(status().isBadRequest());
193 mockMvc.perform(post("/sendHeartbeat").headers(headers).content(" ")).andExpect(status().isBadRequest());
197 public void getNotificationTopicValidPassTest() throws Exception{
199 mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, "123").content("test")).andExpect(status().isOk());
200 // Try to add same topic should fail.
201 mockMvc.perform(post("/getNotification").headers(headers).header(UUIDHEADER, UUID.randomUUID()).content("test")).andExpect(status().isBadRequest());
203 mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isOk());
204 // remove the added Topic.
205 mockMvc.perform(post("/stopNotification").headers(headers).content("test")).andExpect(status().isOk());
206 // try to remove again should fail.
207 mockMvc.perform(post("/sendHeartbeat").headers(headers).content("test")).andExpect(status().isBadRequest());
211 public void sendEventTest() throws Exception{
212 EventRequestParameters pep = new EventRequestParameters();
213 Map<String,String> eventAttributes = new HashMap<>();
214 eventAttributes.put("TEST", "test");
215 pep.setEventAttributes(eventAttributes);
217 mockMvc.perform(post("/sendEvent")).andExpect(status().isBadRequest());
218 mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
220 mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
221 .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
222 pep.setEventAttributes(null);
223 mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
224 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
225 pep.setEventAttributes(eventAttributes);
226 mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
227 .headers(headers)).andExpect(status().isOk());
228 pep.setEventAttributes(eventAttributes);
229 pep.setRequestID(UUID.randomUUID());
230 mockMvc.perform(post("/sendEvent").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
231 .headers(headers)).andExpect(status().isOk());
235 public void getDecisionTest() throws Exception{
236 DecisionRequestParameters pep = new DecisionRequestParameters();
237 Map<String,String> eventAttributes = new HashMap<>();
238 eventAttributes.put("TEST", "test");
239 pep.setONAPComponentName("te123");
240 pep.setDecisionAttributes(eventAttributes);
242 mockMvc.perform(post("/getDecision")).andExpect(status().isBadRequest());
243 mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
245 mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
246 .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
247 pep.setDecisionAttributes(null);
248 pep.setONAPComponentName(null);
249 mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
250 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
251 pep.setONAPComponentName("testing");
252 mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
253 .headers(headers)).andExpect(status().isBadRequest());
254 pep.setDecisionAttributes(eventAttributes);
255 pep.setRequestID(UUID.randomUUID());
256 mockMvc.perform(post("/getDecision").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
257 .headers(headers)).andExpect(status().isOk());
261 public void pushPolicyTest() throws Exception{
262 PushPolicyParameters pep = new PushPolicyParameters();
264 mockMvc.perform(put("/pushPolicy")).andExpect(status().isBadRequest());
265 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
267 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
268 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
269 pep.setPolicyName("scopeless");
270 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
271 .headers(headers)).andExpect(status().isBadRequest());
272 pep.setPolicyName("testing.test");
273 pep.setPolicyType("wrong");
274 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
275 .headers(headers)).andExpect(status().isBadRequest());
276 pep.setPolicyType("BRMS_PARAM");
277 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
278 .headers(headers)).andExpect(status().isBadRequest());
279 pep.setPolicyType("BRMS_RAW");
280 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
281 .headers(headers)).andExpect(status().isBadRequest());
282 pep.setPolicyType("MicroService");
283 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
284 .headers(headers)).andExpect(status().isBadRequest());
285 pep.setPolicyType("ClosedLoop_PM");
286 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
287 .headers(headers)).andExpect(status().isBadRequest());
288 pep.setPolicyType("ClosedLoop_Fault");
289 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
290 .headers(headers)).andExpect(status().isBadRequest());
291 pep.setPolicyType("Base");
292 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
293 .headers(headers)).andExpect(status().isBadRequest());
294 pep.setPolicyType("Decision");
295 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
296 .headers(headers)).andExpect(status().isBadRequest());
297 pep.setPolicyType("Action");
298 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
299 .headers(headers)).andExpect(status().isBadRequest());
300 pep.setPolicyType("Firewall");
301 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
302 .headers(headers)).andExpect(status().isBadRequest());
303 pep.setPdpGroup("default");
304 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
305 .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
306 pep.setRequestID(UUID.randomUUID());
307 mockMvc.perform(put("/pushPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
308 .headers(headers)).andExpect(status().isBadRequest());
312 public void deletePolicyTest() throws Exception{
313 DeletePolicyParameters pep = new DeletePolicyParameters();
315 mockMvc.perform(delete("/deletePolicy")).andExpect(status().isBadRequest());
316 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
318 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
319 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
320 pep.setPolicyName("testing");
321 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
322 .headers(headers).header(UUIDHEADER, "test123")).andExpect(status().isBadRequest());
323 pep.setPolicyName("testscope.name");
324 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
325 .headers(headers)).andExpect(status().isBadRequest());
326 pep.setPolicyName("testscope.name");
327 pep.setPolicyType("wrong");
328 pep.setRequestID(UUID.randomUUID());
329 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
330 .headers(headers)).andExpect(status().isBadRequest());
331 pep.setPolicyType("BRMS_PARAM");
332 pep.setPolicyComponent("wrong");
333 pep.setRequestID(null);
334 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
335 .headers(headers)).andExpect(status().isBadRequest());
336 pep.setPolicyType("BRMS_RAW");
337 pep.setPolicyComponent("PDP");
338 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
339 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
340 pep.setPolicyType("MicroService");
341 pep.setPolicyComponent("PAP");
342 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
343 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
344 pep.setPolicyType("ClosedLoop_PM");
345 pep.setPolicyComponent("PDP");
346 pep.setDeleteCondition(DeletePolicyCondition.ALL);
347 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
348 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
349 pep.setPolicyType("ClosedLoop_Fault");
350 pep.setDeleteCondition(DeletePolicyCondition.ONE);
351 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
352 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
353 pep.setPolicyType("Base");
354 pep.setPolicyComponent("PAP");
355 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
356 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
357 pep.setPolicyType("Decision");
358 pep.setPolicyComponent("PDP");
359 pep.setPolicyName("test.xml");
360 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
361 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
362 pep.setPolicyType("Action");
363 pep.setPolicyName("scope.Config_test.xml");
364 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
365 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
366 pep.setPdpGroup("default");
367 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
368 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
369 pep.setPolicyComponent("PAP");
370 pep.setPolicyType("Firewall");
371 pep.setDeleteCondition(null);
372 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
373 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
374 pep.setPolicyComponent("PAP");
375 pep.setDeleteCondition(DeletePolicyCondition.ONE);
376 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
377 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
378 pep.setPolicyComponent("fail");
379 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
380 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
381 pep.setPolicyComponent("PDP");
382 pep.setPolicyName("testscope.policyName");
383 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
384 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
385 pep.setPolicyComponent(null);
386 mockMvc.perform(delete("/deletePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
387 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
391 public void createUpdatePolicyTest() throws Exception{
392 PolicyParameters pep = new PolicyParameters();
394 mockMvc.perform(put("/createPolicy")).andExpect(status().isBadRequest());
395 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
396 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
398 setCreateUpdateImpl();
399 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
400 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
401 pep.setPolicyName("failName");
402 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
403 .headers(headers).header(UUIDHEADER, "test 123")).andExpect(status().isBadRequest());
404 pep.setPolicyName("test. name");
405 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
406 .headers(headers)).andExpect(status().isBadRequest());
407 pep.setPolicyName(" ");
408 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
409 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
410 pep.setPolicyName("test. ");
411 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
412 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
413 pep.setPolicyName("te st.name");
414 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
415 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
416 pep.setPolicyName("test.name");
417 pep.setPolicyDescription("testá");
418 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
419 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
420 pep.setPolicyName("test.name");
421 pep.setPolicyDescription("good");
422 pep.setTtlDate(new Date());
423 pep.setRequestID(UUID.randomUUID());
424 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
425 .headers(headers)).andExpect(status().isBadRequest());
429 public void brmsPolicyCreationTests() throws Exception{
430 PolicyParameters pep = new PolicyParameters();
431 pep.setPolicyName("test.name");
432 pep.setPolicyDescription("good");
433 pep.setTtlDate(new Date());
434 pep.setRequestID(UUID.randomUUID());
435 setCreateUpdateImpl();
436 // Checks for BRMS Param Policy.
437 pep.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
438 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
439 .headers(headers)).andExpect(status().isBadRequest());
440 pep.setRiskLevel("test");
441 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
442 .headers(headers)).andExpect(status().isBadRequest());
443 Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
444 Map<String,String> matching = new HashMap<>();
445 matching.put("key", "value");
446 attributes.put(AttributeType.MATCHING, matching);
447 pep.setAttributes(attributes);
448 pep.setRiskLevel("5");
449 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
450 .headers(headers)).andExpect(status().isInternalServerError());
451 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
452 .headers(headers)).andExpect(status().isInternalServerError());
453 // Checks for BRMS Raw Policy
454 pep.setPolicyConfigType(PolicyConfigType.BRMS_RAW);
455 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
456 .headers(headers)).andExpect(status().isBadRequest());
457 pep.setConfigBody("test");
458 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
459 .headers(headers)).andExpect(status().isBadRequest());
460 pep.setRiskLevel(null);
461 pep.setConfigBody("package droolsexample\n\n import com.sample.ItemCity;\nimport java.math.BigDecimal;\nrule \"Nagpur Medicine Item\"\n\n when\n item : ItemCity(purchaseCity == ItemCity.City.NAGPUR,\n typeofItem == ItemCity.Type.MEDICINES)\n then\n BigDecimal tax = new BigDecimal(0.0);\n item.setLocalTax(tax.multiply(item.getSellPrice()));\nend");
462 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
463 .headers(headers)).andExpect(status().isBadRequest());
464 pep.setRiskLevel("5");
465 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
466 .headers(headers)).andExpect(status().isInternalServerError());
467 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
468 .headers(headers)).andExpect(status().isInternalServerError());
472 public void baseConfigTests() throws Exception{
473 PolicyParameters pep = new PolicyParameters();
474 pep.setPolicyName("test.name");
475 pep.setPolicyDescription("good");
476 pep.setTtlDate(new Date());
477 pep.setRequestID(UUID.randomUUID());
478 setCreateUpdateImpl();
479 // Checks for Base config Policy.
480 pep.setPolicyConfigType(PolicyConfigType.Base);
481 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
482 .headers(headers)).andExpect(status().isBadRequest());
483 pep.setConfigBody("testbody");
484 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
485 .headers(headers)).andExpect(status().isBadRequest());
486 pep.setConfigBodyType(PolicyType.OTHER);
487 pep.setRiskLevel("test");
488 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
489 .headers(headers)).andExpect(status().isBadRequest());
490 pep.setRiskLevel("4");
491 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
492 .headers(headers)).andExpect(status().isBadRequest());
493 pep.setOnapName("ec nam-e");
494 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
495 .headers(headers)).andExpect(status().isBadRequest());
496 pep.setOnapName("onapName");
497 pep.setConfigName("tes config");
498 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
499 .headers(headers)).andExpect(status().isBadRequest());
500 pep.setConfigName("configName");
501 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
502 .headers(headers)).andExpect(status().isInternalServerError());
503 pep.setConfigBody("{'test':'test}");
504 pep.setConfigBodyType(PolicyType.JSON);
505 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
506 .headers(headers)).andExpect(status().isInternalServerError());
507 Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
508 Map<String,String> matching = new HashMap<>();
509 matching.put("key", "value");
510 attributes.put(AttributeType.MATCHING, matching);
511 pep.setAttributes(attributes);
512 pep.setConfigBody("testBody");
513 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
514 .headers(headers)).andExpect(status().isInternalServerError());
518 public void closedLoopPolicyTests() throws Exception{
519 PolicyParameters pep = new PolicyParameters();
520 pep.setPolicyName("test.name");
521 pep.setPolicyDescription("good");
522 pep.setTtlDate(new Date());
523 pep.setRequestID(UUID.randomUUID());
524 setCreateUpdateImpl();
525 // Checks for Closed loop Policy.
526 pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
527 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
528 .headers(headers)).andExpect(status().isBadRequest());
529 pep.setConfigBody("te stá");
530 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
531 .headers(headers)).andExpect(status().isBadRequest());
532 pep.setConfigBody("testBody");
533 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
534 .headers(headers)).andExpect(status().isBadRequest());
535 pep.setConfigBody("{\"key\":\"value\"}");
536 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
537 .headers(headers)).andExpect(status().isBadRequest());
538 pep.setConfigBody("{\"onapname\":\"\"}");
539 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
540 .headers(headers)).andExpect(status().isBadRequest());
541 pep.setConfigBody("{\"onapname\":\"test\"}");
542 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
543 .headers(headers)).andExpect(status().isInternalServerError());
544 pep.setRiskLevel("test");
545 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
546 .headers(headers)).andExpect(status().isBadRequest());
547 pep.setRiskLevel("4");
548 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
549 .headers(headers)).andExpect(status().isInternalServerError());
550 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
551 .headers(headers)).andExpect(status().isInternalServerError());
555 public void closedLoopPMTests() throws Exception{
556 PolicyParameters pep = new PolicyParameters();
557 pep.setPolicyName("test.name");
558 pep.setPolicyDescription("good");
559 pep.setTtlDate(new Date());
560 pep.setRequestID(UUID.randomUUID());
561 setCreateUpdateImpl();
562 // Checks for Closed loop Policy.
563 pep.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
564 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
565 .headers(headers)).andExpect(status().isBadRequest());
566 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
567 .headers(headers)).andExpect(status().isBadRequest());
568 pep.setConfigBody("te stá");
569 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
570 .headers(headers)).andExpect(status().isBadRequest());
571 pep.setConfigBody("testBody");
572 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
573 .headers(headers)).andExpect(status().isBadRequest());
574 pep.setConfigBody("{\"key\":\"value\"}");
575 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
576 .headers(headers)).andExpect(status().isBadRequest());
577 pep.setConfigBody("{\"onapname\":\"\"}");
578 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
579 .headers(headers)).andExpect(status().isBadRequest());
580 pep.setConfigBody("{\"onapname\":\"test\"}");
581 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
582 .headers(headers)).andExpect(status().isBadRequest());
583 pep.setConfigBody("{\"onapname\":\"test\", \"serviceTypePolicyName\":\"value\"}");
584 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
585 .headers(headers)).andExpect(status().isInternalServerError());
586 pep.setRiskLevel("test");
587 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
588 .headers(headers)).andExpect(status().isBadRequest());
589 pep.setRiskLevel("4");
590 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
591 .headers(headers)).andExpect(status().isInternalServerError());
592 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
593 .headers(headers)).andExpect(status().isInternalServerError());
597 public void firewallPolicyTests() throws Exception{
598 PolicyParameters pep = new PolicyParameters();
599 pep.setPolicyName("test.name");
600 pep.setPolicyDescription("good");
601 pep.setTtlDate(new Date());
602 pep.setRequestID(UUID.randomUUID());
603 setCreateUpdateImpl();
604 // Checks for Closed loop Policy.
605 pep.setPolicyConfigType(PolicyConfigType.Firewall);
606 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
607 .headers(headers)).andExpect(status().isBadRequest());
608 pep.setConfigBody("te st");
609 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
610 .headers(headers)).andExpect(status().isBadRequest());
611 pep.setConfigBody("{}");
612 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
613 .headers(headers)).andExpect(status().isBadRequest());
614 pep.setConfigBody("{\"test\":\"test\"}");
615 pep.setRiskLevel("test");
616 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
617 .headers(headers)).andExpect(status().isBadRequest());
618 pep.setRiskLevel("4");
619 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
620 .headers(headers)).andExpect(status().isBadRequest());
621 pep.setConfigBody("{\"configName\":\"test\"}");
622 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
623 .headers(headers)).andExpect(status().isInternalServerError());
624 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
625 .headers(headers)).andExpect(status().isInternalServerError());
629 public void microServicePolicyTests() throws Exception{
630 PolicyParameters pep = new PolicyParameters();
631 pep.setPolicyName("test.name");
632 pep.setPolicyDescription("good");
633 pep.setTtlDate(new Date());
634 pep.setRequestID(UUID.randomUUID());
635 setCreateUpdateImpl();
636 // Checks for Closed loop Policy.
637 pep.setPolicyConfigType(PolicyConfigType.MicroService);
638 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
639 .headers(headers)).andExpect(status().isBadRequest());
640 pep.setConfigBody("te st");
641 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
642 .headers(headers)).andExpect(status().isBadRequest());
643 pep.setConfigBody("{}");
644 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
645 .headers(headers)).andExpect(status().isBadRequest());
646 pep.setConfigBody("{\"test\":\"test\"}");
647 pep.setOnapName(" ");
648 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
649 .headers(headers)).andExpect(status().isBadRequest());
650 pep.setOnapName("testonap");
651 pep.setRiskLevel("fail");
652 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
653 .headers(headers)).andExpect(status().isBadRequest());
654 pep.setRiskLevel("4");
655 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
656 .headers(headers)).andExpect(status().isInternalServerError());
657 pep.setConfigBody("{\"service\":\"test\",\"uuid\":\"test\",\"location\":\"test\",\"configName\":\"test\",\"description\":\"test\",\"priority\":\"test\",\"version\":\"test\"}");
658 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
659 .headers(headers)).andExpect(status().isInternalServerError());
663 public void actionDecisionPolicyCreationTests() throws Exception{
664 PolicyParameters pep = new PolicyParameters();
665 pep.setPolicyName("test.name");
666 pep.setPolicyDescription("good");
667 pep.setTtlDate(new Date());
668 pep.setRequestID(UUID.randomUUID());
669 setCreateUpdateImpl();
670 // Checks for action Policy.
671 pep.setPolicyClass(PolicyClass.Action);
672 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
673 .headers(headers)).andExpect(status().isBadRequest());
674 Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
675 pep.setAttributes(attributes);
676 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
677 .headers(headers)).andExpect(status().isBadRequest());
678 attributes.put(AttributeType.MATCHING, new HashMap<>());
679 pep.setAttributes(attributes);
680 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
681 .headers(headers)).andExpect(status().isBadRequest());
682 Map<String,String> matching = new HashMap<>();
683 matching.put("key", "value");
684 attributes.put(AttributeType.MATCHING, matching);
685 pep.setAttributes(attributes);
686 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
687 .headers(headers)).andExpect(status().isBadRequest());
688 pep.setActionAttribute("A1");
689 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
690 .headers(headers)).andExpect(status().isBadRequest());
691 pep.setActionPerformer("PEX");
692 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
693 .headers(headers)).andExpect(status().isBadRequest());
694 pep.setActionPerformer("PEP");
695 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
696 .headers(headers)).andExpect(status().isInternalServerError());
697 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
698 .headers(headers)).andExpect(status().isInternalServerError());
699 // Checks for Decision Policy.
700 pep.setPolicyClass(PolicyClass.Decision);
701 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
702 .headers(headers)).andExpect(status().isBadRequest());
703 pep.setOnapName("xyz");
704 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
705 .headers(headers)).andExpect(status().isInternalServerError());
706 attributes.remove(AttributeType.MATCHING);
707 attributes.put(AttributeType.SETTINGS, matching);
708 pep.setAttributes(attributes);
709 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
710 .headers(headers)).andExpect(status().isInternalServerError());
711 attributes.put(AttributeType.MATCHING, matching);
712 pep.setAttributes(attributes);
713 mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
714 .headers(headers)).andExpect(status().isInternalServerError());
715 mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
716 .headers(headers)).andExpect(status().isInternalServerError());
720 public void createUpdateDictionaryTests() throws Exception{
721 DictionaryParameters pep = new DictionaryParameters();
723 mockMvc.perform(put("/createDictionaryItem")).andExpect(status().isBadRequest());
724 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
725 mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
727 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
728 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
729 pep.setDictionaryType(DictionaryType.MicroService);
730 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
731 .headers(headers)).andExpect(status().isBadRequest());
732 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
733 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
734 pep.setDictionary("test dict");
735 pep.setRequestID(UUID.randomUUID());
736 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
737 .headers(headers)).andExpect(status().isBadRequest());
738 pep.setDictionaryJson("{\"test\":\"value\"}");
739 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
740 .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isInternalServerError());
741 pep.setDictionaryJson("test123");
742 mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
743 .headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
744 pep.setDictionary("MicroServiceDictionary");
745 mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
746 .headers(headers)).andExpect(status().isBadRequest());
750 public void getDictionaryTests() throws Exception{
751 DictionaryParameters pep = new DictionaryParameters();
753 mockMvc.perform(post("/getDictionaryItems")).andExpect(status().isBadRequest());
754 mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
756 mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
757 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
758 pep.setDictionaryType(DictionaryType.Common);
759 mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
760 .headers(headers).header(UUIDHEADER, UUID.randomUUID().toString())).andExpect(status().isBadRequest());
761 pep.setDictionary("OnapName");
762 mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
763 .headers(headers)).andExpect(status().isInternalServerError());
764 pep.setRequestID(UUID.randomUUID());
765 mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
766 .headers(headers)).andExpect(status().isInternalServerError());
770 public void policyEngineImportTests() throws Exception{
772 mockMvc.perform(post("/policyEngineImport")).andExpect(status().isBadRequest());
776 public void oldConfigAPITests() throws Exception{
777 ConfigPolicyAPIRequest pep = new ConfigPolicyAPIRequest();
779 mockMvc.perform(put("/createConfig")).andExpect(status().isBadRequest());
780 mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
781 mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
783 mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
784 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
785 pep.setPolicyScope("test");
786 mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
787 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
788 pep.setPolicyName("name");
789 mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
790 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
791 pep.setConfigType("OTHER");
792 mockMvc.perform(put("/createConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
793 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
794 pep.setTtlDate(new Date().toString());
795 mockMvc.perform(put("/updateConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
796 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
800 public void oldFirewallAPITests() throws Exception{
801 ConfigFirewallPolicyAPIRequest pep = new ConfigFirewallPolicyAPIRequest();
803 mockMvc.perform(put("/createFirewallConfig")).andExpect(status().isBadRequest());
804 mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
805 mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON).header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
807 mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
808 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
809 pep.setPolicyScope("test");
810 mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
811 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
812 pep.setPolicyName("name");
813 mockMvc.perform(put("/createFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
814 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
815 pep.setTtlDate(new Date().toString());
816 mockMvc.perform(put("/updateFirewallConfig").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
817 .headers(headers).header(UUIDHEADER, "tes123")).andExpect(status().isBadRequest());
820 private void setCreateUpdateImpl() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
821 Method setter = XACMLPdpServlet.class.getDeclaredMethod("setCreateUpdatePolicyConstructor", String.class);
822 setter.setAccessible(true);
823 setter.invoke(new XACMLPdpServlet(), CreateUpdatePolicyServiceImpl.class.getName());
828 public void getCountTest() throws Exception {
829 mockMvc.perform(get("/count"))
830 .andExpect(status().isOk());