policy/engine jdk11 upgrades
[policy/engine.git] / PolicyEngineAPI / src / test / java / org / onap / policy / std / StdPolicyEngineTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineAPI
4  * ================================================================================
5  * Copyright (C) 2018 Ericsson. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
8  * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.std;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.ArgumentMatchers.eq;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.doThrow;
32 import static org.mockito.Mockito.spy;
33 import static org.onap.policy.std.utils.PolicyCommonConfigConstants.CONFIG_NAME;
34 import static org.onap.policy.std.utils.PolicyCommonConfigConstants.ONAP_NAME;
35 import static org.onap.policy.std.utils.PolicyConfigConstants.CLIENT_ID_PROP_NAME;
36 import static org.onap.policy.std.utils.PolicyConfigConstants.CLIENT_KEY_PROP_NAME;
37 import static org.onap.policy.std.utils.PolicyConfigConstants.COMMA;
38 import static org.onap.policy.std.utils.PolicyConfigConstants.CREATE_DICTIONARY_ITEM_RESOURCE_NAME;
39 import static org.onap.policy.std.utils.PolicyConfigConstants.CREATE_POLICY_RESOURCE_NAME;
40 import static org.onap.policy.std.utils.PolicyConfigConstants.DELETE_POLICY_RESOURCE_NAME;
41 import static org.onap.policy.std.utils.PolicyConfigConstants.DMAAP;
42 import static org.onap.policy.std.utils.PolicyConfigConstants.ENVIRONMENT_PROP_NAME;
43 import static org.onap.policy.std.utils.PolicyConfigConstants.GET_CONFIG_RESOURCE_NAME;
44 import static org.onap.policy.std.utils.PolicyConfigConstants.GET_DECISION_RESOURCE_NAME;
45 import static org.onap.policy.std.utils.PolicyConfigConstants.GET_DICTIONARY_ITEMS_RESOURCE_NAME;
46 import static org.onap.policy.std.utils.PolicyConfigConstants.GET_METRICS_RESOURCE_NAME;
47 import static org.onap.policy.std.utils.PolicyConfigConstants.NOTIFICATION_SERVERS_PROP_NAME;
48 import static org.onap.policy.std.utils.PolicyConfigConstants.NOTIFICATION_TOPIC_PROP_NAME;
49 import static org.onap.policy.std.utils.PolicyConfigConstants.NOTIFICATION_TYPE_PROP_NAME;
50 import static org.onap.policy.std.utils.PolicyConfigConstants.PDP_URL_PROP_NAME;
51 import static org.onap.policy.std.utils.PolicyConfigConstants.POLICY_ENGINE_IMPORT_RESOURCE_NAME;
52 import static org.onap.policy.std.utils.PolicyConfigConstants.PUSH_POLICY_RESOURCE_NAME;
53 import static org.onap.policy.std.utils.PolicyConfigConstants.SEND_EVENT_RESOURCE_NAME;
54 import static org.onap.policy.std.utils.PolicyConfigConstants.UEB;
55 import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_DICTIONARY_ITEM_RESOURCE_NAME;
56 import static org.onap.policy.std.utils.PolicyConfigConstants.UPDATE_POLICY_RESOURCE_NAME;
57 import java.io.BufferedWriter;
58 import java.io.File;
59 import java.io.IOException;
60 import java.io.StringReader;
61 import java.nio.file.Files;
62 import java.util.Arrays;
63 import java.util.Collection;
64 import java.util.Collections;
65 import java.util.Date;
66 import java.util.HashMap;
67 import java.util.Map;
68 import java.util.Properties;
69 import java.util.UUID;
70 import javax.json.Json;
71 import javax.json.JsonObject;
72 import javax.json.JsonReader;
73 import org.junit.Rule;
74 import org.junit.Test;
75 import org.junit.rules.TemporaryFolder;
76 import org.junit.runner.RunWith;
77 import org.mockito.Mockito;
78 import org.onap.policy.api.ConfigRequestParameters;
79 import org.onap.policy.api.DecisionRequestParameters;
80 import org.onap.policy.api.DecisionResponse;
81 import org.onap.policy.api.DeletePolicyParameters;
82 import org.onap.policy.api.DictionaryParameters;
83 import org.onap.policy.api.DictionaryResponse;
84 import org.onap.policy.api.EventRequestParameters;
85 import org.onap.policy.api.ImportParameters;
86 import org.onap.policy.api.MetricsRequestParameters;
87 import org.onap.policy.api.MetricsResponse;
88 import org.onap.policy.api.NotificationScheme;
89 import org.onap.policy.api.PolicyChangeResponse;
90 import org.onap.policy.api.PolicyConfig;
91 import org.onap.policy.api.PolicyConfigException;
92 import org.onap.policy.api.PolicyConfigStatus;
93 import org.onap.policy.api.PolicyConfigType;
94 import org.onap.policy.api.PolicyDecision;
95 import org.onap.policy.api.PolicyDecisionException;
96 import org.onap.policy.api.PolicyEngineException;
97 import org.onap.policy.api.PolicyEventException;
98 import org.onap.policy.api.PolicyException;
99 import org.onap.policy.api.PolicyParameters;
100 import org.onap.policy.api.PolicyResponse;
101 import org.onap.policy.api.PolicyResponseStatus;
102 import org.onap.policy.api.PolicyType;
103 import org.onap.policy.api.PushPolicyParameters;
104 import org.onap.policy.models.APIDictionaryResponse;
105 import org.onap.policy.models.APIPolicyConfigResponse;
106 import org.onap.policy.std.utils.PolicyConfigConstants;
107 import org.powermock.core.classloader.annotations.PowerMockIgnore;
108 import org.powermock.core.classloader.annotations.PrepareForTest;
109 import org.powermock.modules.junit4.PowerMockRunner;
110 import org.springframework.http.HttpMethod;
111 import org.springframework.http.HttpStatus;
112 import org.springframework.http.ResponseEntity;
113 import org.springframework.web.client.HttpClientErrorException;
114 import org.springframework.web.client.RestClientException;
115
116 @RunWith(PowerMockRunner.class)
117 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
118 @PrepareForTest(StdPolicyEngine.class)
119 public class StdPolicyEngineTest {
120
121     private static final String ONAP_NAME_VAL = "ONAP_NAME";
122     private static final String POLICY_VERSION = "1.0.0";
123     private static final String POLICY_NAME = "ONAP";
124     private static final String COMMENTS = "";
125     private static final UUID REQUEST_UUID = UUID.randomUUID();
126     private static final String SERVER_NAME = "localhost.com";
127     private static final String PDP_PROP_VALUE = "http://localhost:8092/pdp/ , test, test";
128     private static final String PDP_PROP_VALUE_1 = "https://localhost:8091/pdp/ , onap, onap";
129     private static final String JSON_CONFIGURATION = "{\"name\":\"value\"}";
130     private static final String XML_CONFIGURATION =
131             "<map><entry><string>name</string><string>value</string></entry></map>";
132
133     @Rule
134     public TemporaryFolder temporaryFolder = new TemporaryFolder();
135
136     private static final String CONFIG_PROPERTIES_FILE = "config_pass.properties";
137     private static final String INVALID_CONFIG_PROPERTY_FILE = "config_fail.properties";
138
139     @Test
140     public void testStdPolicyEngineInitialize_noException() throws Exception {
141         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
142
143         creatPropertyFile(file, getDefaultProperties());
144
145         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
146         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
147         assertEquals("TEST", StdPolicyEngine.getEnvironment());
148         assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
149         assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
150         assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME),
151                 policyEngine.getNotificationURLList());
152     }
153
154     @Test
155     public void testStdPolicyEngineWithPropertiesInitialize_noException() throws Exception {
156         final StdPolicyEngine policyEngine =
157                 new StdPolicyEngine(getDefaultProperties(), (String) null);
158         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
159         assertEquals("TEST", StdPolicyEngine.getEnvironment());
160         assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
161         assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
162         assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME),
163                 policyEngine.getNotificationURLList());
164     }
165
166     @Test
167     public void testStdPolicyEngineInitializeWithSingleServerName_noException() throws Exception {
168         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
169
170         final Properties properties = new Properties();
171         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
172         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
173         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
174         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
175         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
176         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
177         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
178         creatPropertyFile(file, properties);
179
180         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
181         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
182         assertEquals(Arrays.asList(SERVER_NAME), policyEngine.getNotificationURLList());
183     }
184
185     @Test
186     public void testStdPolicyEngineInitializeWithSingleNotificationType_noException()
187             throws Exception {
188         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
189
190         final Properties properties = new Properties();
191         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
192         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
193         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
194         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
195         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
196         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
197         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
198         creatPropertyFile(file, properties);
199
200         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
201         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
202         assertEquals(Arrays.asList(UEB), policyEngine.getNotificationType());
203     }
204
205     @Test(expected = PolicyEngineException.class)
206     public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception()
207             throws PolicyEngineException {
208         new StdPolicyEngine("Invalid.properties", (String) null);
209     }
210
211     @Test(expected = PolicyEngineException.class)
212     public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception()
213             throws Exception {
214         final File emptyFile = temporaryFolder.newFile("EmptyFile.txt");
215         new StdPolicyEngine(emptyFile.toString(), (String) null);
216     }
217
218     @Test(expected = PolicyEngineException.class)
219     public void testStdPolicyEngineInitialize_NullArguments_Exception() throws Exception {
220         new StdPolicyEngine((String) null, (String) null);
221     }
222
223     @Test(expected = PolicyEngineException.class)
224     public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception()
225             throws Exception {
226         new StdPolicyEngine((Properties) null, (String) null);
227     }
228
229     @Test(expected = PolicyEngineException.class)
230     public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception()
231             throws Exception {
232         final File file = temporaryFolder.newFile(INVALID_CONFIG_PROPERTY_FILE);
233         final Properties properties = new Properties();
234         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
235         creatPropertyFile(file, properties);
236
237         new StdPolicyEngine(file.toString(), (String) null);
238     }
239
240     @Test
241     public void testStdPolicyEngineInitialize_MultiplePdp_noException() throws Exception {
242         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
243
244         final Properties properties = new Properties();
245         properties.setProperty(PDP_URL_PROP_NAME,
246                 PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1);
247         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
248         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
249         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
250         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
251         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
252         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
253         creatPropertyFile(file, properties);
254
255         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
256         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
257         assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
258         StdPolicyEngine.rotatePDPList();
259         assertEquals("https://localhost:8091/pdp/", StdPolicyEngine.getPDPURL());
260         assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
261         assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME),
262                 policyEngine.getNotificationURLList());
263     }
264
265     @Test(expected = PolicyEngineException.class)
266     public void testStdPolicyEngineInitialize_NoPDP_noException() throws Exception {
267         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
268
269         final Properties properties = new Properties();
270         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
271         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
272         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
273         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
274         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
275         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
276         creatPropertyFile(file, properties);
277
278         new StdPolicyEngine(file.toString(), (String) null);
279     }
280
281     @Test
282     public void testStdPolicyEngineInitializeNotificationTypeDMMAP_noException() throws Exception {
283         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
284
285         final Properties properties = new Properties();
286         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
287         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
288         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
289         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, DMAAP);
290         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
291         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
292         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
293         creatPropertyFile(file, properties);
294
295         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
296         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
297
298         assertEquals(Arrays.asList(DMAAP), policyEngine.getNotificationType());
299
300     }
301
302     @Test
303     public void testStdPolicyEngineSendEvent_noException() throws Exception {
304         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
305         doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED))
306                 .when(spyPolicyEngine)
307                 .callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
308
309         final Collection<PolicyResponse> actualPolicyResponses =
310                 spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
311
312         assertEquals(1, actualPolicyResponses.size());
313
314     }
315
316     @Test(expected = PolicyEventException.class)
317     public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception()
318             throws Exception {
319         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
320         spyPolicyEngine.sendEvent((EventRequestParameters) null);
321     }
322
323     @Test(expected = PolicyEventException.class)
324     public void testStdPolicyEngineSendEvent_EventRequestParameters_CallPDPThrow401Exception_Exception()
325             throws Exception {
326         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
327         Mockito.doThrow(new RuntimeException(new RestClientException("Error 401")))
328                 .when(spyPolicyEngine).callNewPDP(any(), any(), any(), any());
329         spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
330     }
331
332     @Test
333     public void testStdPolicyEngineSendEvent_EventRequestParameters_noException() throws Exception {
334         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
335
336         final ResponseEntity<StdPolicyResponse[]> stubbedResponse =
337                 new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED);
338
339         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME),
340                 any(), any(), any());
341
342         final EventRequestParameters eventRequestParameters = new EventRequestParameters();
343         eventRequestParameters.setEventAttributes(Collections.emptyMap());
344         eventRequestParameters.setRequestID(REQUEST_UUID);
345
346         final Collection<PolicyResponse> actualPolicyResponses =
347                 spyPolicyEngine.sendEvent(eventRequestParameters);
348
349         assertEquals(1, actualPolicyResponses.size());
350
351     }
352
353     @Test
354     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException()
355             throws Exception {
356         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
357
358         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
359                 getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION),
360                 HttpStatus.ACCEPTED);
361
362         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
363                 eq(HttpMethod.POST), any(), any());
364
365         final Collection<PolicyConfig> actualPolicyResponses =
366                 spyPolicyEngine.getConfig(new ConfigRequestParameters());
367
368         assertEquals(1, actualPolicyResponses.size());
369
370         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
371         assertNotNull(actualPolicyConfig.toJSON());
372
373     }
374
375     @Test
376     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException()
377             throws Exception {
378         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
379
380         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
381                 getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED);
382
383         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
384                 eq(HttpMethod.POST), any(), any());
385
386         final Collection<PolicyConfig> actualPolicyResponses =
387                 spyPolicyEngine.getConfig(new ConfigRequestParameters());
388
389         assertEquals(1, actualPolicyResponses.size());
390
391         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
392         assertNotNull(actualPolicyConfig.toOther());
393
394     }
395
396     @Test
397     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException()
398             throws Exception {
399         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
400
401         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
402                 getAPIPolicyConfigResponse(PolicyType.XML, XML_CONFIGURATION), HttpStatus.ACCEPTED);
403
404         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
405                 eq(HttpMethod.POST), any(), any());
406
407         final Collection<PolicyConfig> actualPolicyResponses =
408                 spyPolicyEngine.getConfig(new ConfigRequestParameters());
409
410         assertEquals(1, actualPolicyResponses.size());
411
412         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
413         assertNotNull(actualPolicyConfig.toXML());
414
415     }
416
417     @Test
418     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigProperties_noException()
419             throws Exception {
420         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
421
422         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
423                 getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED);
424
425         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
426                 eq(HttpMethod.POST), any(), any());
427
428         final Collection<PolicyConfig> actualPolicyResponses =
429                 spyPolicyEngine.getConfig(new ConfigRequestParameters());
430
431         assertEquals(1, actualPolicyResponses.size());
432
433         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
434         assertNotNull(actualPolicyConfig.toProperties());
435
436     }
437
438     @Test(expected = PolicyConfigException.class)
439     public void testStdPolicyEngineSendEvent_ConfigRequestParameters_CallPDPThrow404Exception_Exception()
440             throws Exception {
441         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
442         doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine)
443                 .callNewPDP(any(), any(), any(), any());
444         spyPolicyEngine.getConfig(new ConfigRequestParameters());
445     }
446
447     @Test
448     public void testStdPolicyEngineListConfig_ConfigRequestParametersPolicyConfigProperties_noException()
449             throws Exception {
450         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
451
452         final APIPolicyConfigResponse[] apiPolicyConfigResponse =
453                 getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION);
454
455         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
456                 new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
457
458         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
459                 eq(HttpMethod.POST), any(), any());
460
461         final Collection<String> actualResponse =
462                 spyPolicyEngine.listConfig(new ConfigRequestParameters());
463         assertEquals(1, actualResponse.size());
464         assertNotNull(actualResponse.iterator().next());
465
466     }
467
468     @Test
469     public void testStdPolicyEngineListConfig_ConfigRequestParametersMessageConfigContainsPE300_noException()
470             throws Exception {
471         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
472
473         final APIPolicyConfigResponse[] apiPolicyConfigResponse = getAPIPolicyConfigResponse(
474                 PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300);
475
476         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
477                 new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
478
479         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME),
480                 eq(HttpMethod.POST), any(), any());
481
482         final Collection<String> actualResponse =
483                 spyPolicyEngine.listConfig(new ConfigRequestParameters());
484
485         assertEquals(1, actualResponse.size());
486
487     }
488
489     @Test
490     public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException()
491             throws Exception {
492         final Properties defaultProperties = getDefaultProperties();
493         defaultProperties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "test");
494         final StdPolicyEngine spyPolicyEngine =
495                 getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties);
496
497         final Collection<String> actualResponse =
498                 spyPolicyEngine.listConfig(new ConfigRequestParameters());
499
500         assertEquals(1, actualResponse.size());
501
502     }
503
504     @Test
505     public void testStdPolicyEnginGetDecision_PolicyDecision_noException() throws Exception {
506
507         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
508
509         final ResponseEntity<StdDecisionResponse> stubbedResponse =
510                 new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
511
512         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME),
513                 eq(HttpMethod.POST), any(), any());
514
515         final DecisionResponse actualResponse =
516                 spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
517
518         assertNotNull(actualResponse);
519     }
520
521     @Test(expected = PolicyDecisionException.class)
522     public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception()
523             throws Exception {
524         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
525         doThrow(new RuntimeException(new RestClientException("Error 400"))).when(spyPolicyEngine)
526                 .callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
527         spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
528     }
529
530     @Test
531     public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException()
532             throws Exception {
533
534         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
535
536         final ResponseEntity<StdDecisionResponse> stubbedResponse =
537                 new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
538
539         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME),
540                 eq(HttpMethod.POST), any(), any());
541
542         final DecisionRequestParameters requestParameters = new DecisionRequestParameters();
543         requestParameters.setOnapName(ONAP_NAME_VAL);
544         requestParameters.setRequestID(REQUEST_UUID);
545         requestParameters.setDecisionAttributes(Collections.emptyMap());
546
547         final DecisionResponse actualResponse = spyPolicyEngine.getDecision(requestParameters);
548
549         assertNotNull(actualResponse);
550     }
551
552     @Test(expected = PolicyDecisionException.class)
553     public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception()
554             throws Exception {
555         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
556         spyPolicyEngine.getDecision((DecisionRequestParameters) null);
557     }
558
559     @Test
560     public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException()
561             throws Exception {
562
563         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
564
565         final ResponseEntity<String> stubbedResponse =
566                 new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED);
567
568         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME),
569                 eq(HttpMethod.GET), any(), any());
570
571         final MetricsResponse actualResponse =
572                 spyPolicyEngine.getMetrics(new MetricsRequestParameters());
573         assertNotNull(actualResponse);
574         assertEquals(HttpStatus.ACCEPTED.value(), actualResponse.getResponseCode());
575
576     }
577
578     @Test
579     public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowHttpException_ResponseWithHttpCode()
580             throws Exception {
581         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
582         doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY)))
583                 .when(spyPolicyEngine)
584                 .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any());
585
586         final MetricsResponse actualResponse =
587                 spyPolicyEngine.getMetrics(new MetricsRequestParameters());
588         assertNotNull(actualResponse);
589         assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
590
591     }
592
593     @Test(expected = PolicyException.class)
594     public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowPolicyException_Exception()
595             throws Exception {
596         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
597         doThrow(PolicyException.class).when(spyPolicyEngine)
598                 .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any());
599
600         spyPolicyEngine.getMetrics(new MetricsRequestParameters());
601
602     }
603
604     @Test
605     public void testStdPolicyEnginPushPolicy_PushPolicyParameters_noException() throws Exception {
606
607         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
608
609         final ResponseEntity<String> stubbedResponse =
610                 new ResponseEntity<>("Successful", HttpStatus.OK);
611
612         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
613                 eq(HttpMethod.PUT), any(), any());
614
615         final PolicyChangeResponse actualResponse =
616                 spyPolicyEngine.pushPolicy(new PushPolicyParameters());
617
618         assertNotNull(actualResponse);
619         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
620     }
621
622     @Test
623     public void testStdPolicyEnginePushPolicy_PushPolicyParametersThrowsHttpClientErrorException_ResponseWithHttpCode()
624             throws Exception {
625         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
626         doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY)))
627                 .when(spyPolicyEngine)
628                 .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
629
630         final PolicyChangeResponse actualResponse =
631                 spyPolicyEngine.pushPolicy(new PushPolicyParameters());
632
633         assertNotNull(actualResponse);
634         assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
635
636     }
637
638     @Test(expected = PolicyException.class)
639     public void testStdPolicyEnginePushPolicy_PushPolicyParameters_Exception() throws Exception {
640         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
641         doThrow(PolicyException.class).when(spyPolicyEngine)
642                 .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
643
644         spyPolicyEngine.pushPolicy(new PushPolicyParameters());
645
646     }
647
648     @Test
649     public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException()
650             throws Exception {
651
652         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
653
654         final ResponseEntity<String> stubbedResponse =
655                 new ResponseEntity<>("Successful", HttpStatus.OK);
656
657         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(DELETE_POLICY_RESOURCE_NAME),
658                 eq(HttpMethod.DELETE), any(), any());
659
660         final PolicyChangeResponse actualResponse =
661                 spyPolicyEngine.deletePolicy(new DeletePolicyParameters());
662
663         assertNotNull(actualResponse);
664         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
665     }
666
667     @Test
668     public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException()
669             throws Exception {
670
671         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
672
673         final ResponseEntity<APIDictionaryResponse> stubbedResponse =
674                 new ResponseEntity<>(getAPIDictionaryResponse(), HttpStatus.OK);
675
676         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(
677                 eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
678
679         final DictionaryResponse actualResponse =
680                 spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
681
682         assertNotNull(actualResponse);
683     }
684
685     @Test
686     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp400ExceptionThrown_ResponseWithHttpCode()
687             throws Exception {
688         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
689         doThrow(new RuntimeException(
690                 new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400")))
691                         .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME),
692                                 eq(HttpMethod.POST), any(), any());
693
694         final DictionaryResponse actualResponse =
695                 spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
696
697         assertNotNull(actualResponse);
698         assertEquals(HttpStatus.BAD_REQUEST.value(), actualResponse.getResponseCode());
699
700     }
701
702     @Test
703     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp401ExceptionThrown_ResponseWithHttpCode()
704             throws Exception {
705         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
706         doThrow(new RuntimeException(
707                 new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401")))
708                         .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME),
709                                 eq(HttpMethod.POST), any(), any());
710
711         final DictionaryResponse actualResponse =
712                 spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
713
714         assertNotNull(actualResponse);
715         assertEquals(HttpStatus.UNAUTHORIZED.value(), actualResponse.getResponseCode());
716
717     }
718
719     @Test
720     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithRunTimeExceptionThrown_ResponseWithHttpCode()
721             throws Exception {
722         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
723         doThrow(new RuntimeException(
724                 new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error")))
725                         .when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME),
726                                 eq(HttpMethod.POST), any(), any());
727
728         final DictionaryResponse actualResponse =
729                 spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
730
731         assertNotNull(actualResponse);
732         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), actualResponse.getResponseCode());
733
734     }
735
736     @Test
737     public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException()
738             throws Exception {
739
740         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
741
742         final ResponseEntity<String> stubbedResponse =
743                 new ResponseEntity<>("Successful", HttpStatus.OK);
744
745         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(
746                 eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
747
748         final PolicyChangeResponse actualResponse =
749                 spyPolicyEngine.createDictionaryItem(new DictionaryParameters());
750
751         assertNotNull(actualResponse);
752         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
753     }
754
755     @Test
756     public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException()
757             throws Exception {
758
759         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
760
761         final ResponseEntity<String> stubbedResponse =
762                 new ResponseEntity<>("Successful", HttpStatus.OK);
763
764         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(
765                 eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
766
767         final PolicyChangeResponse actualResponse =
768                 spyPolicyEngine.updateDictionaryItem(new DictionaryParameters());
769
770         assertNotNull(actualResponse);
771         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
772     }
773
774     @Test
775     public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException()
776             throws Exception {
777         final File emptyfile = temporaryFolder.newFile("emptyFile.txt");
778         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
779
780         final ResponseEntity<String> stubbedResponse =
781                 new ResponseEntity<>("Successful", HttpStatus.OK);
782
783         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(
784                 eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
785
786         final ImportParameters importParameters = new ImportParameters();
787         importParameters.setFilePath(emptyfile.toString());
788         final PolicyChangeResponse actualResponse =
789                 spyPolicyEngine.policyEngineImport(importParameters);
790
791         assertNotNull(actualResponse);
792         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
793     }
794
795     @Test
796     public void testStdPolicyEnginCreatePolicy_PolicyParameters_noException() throws Exception {
797         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
798
799         final ResponseEntity<String> stubbedResponse =
800                 new ResponseEntity<>("Successful", HttpStatus.OK);
801
802         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME),
803                 eq(HttpMethod.PUT), any(), any());
804
805         final PolicyChangeResponse actualResponse =
806                 spyPolicyEngine.createPolicy(new PolicyParameters());
807
808         assertNotNull(actualResponse);
809         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
810     }
811
812     @Test
813     public void testStdPolicyEnginUpdatePolicy_PolicyParameters_noException() throws Exception {
814         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
815
816         final ResponseEntity<String> stubbedResponse =
817                 new ResponseEntity<>("Successful", HttpStatus.OK);
818
819         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
820                 eq(HttpMethod.PUT), any(), any());
821
822         final PolicyChangeResponse actualResponse =
823                 spyPolicyEngine.updatePolicy(new PolicyParameters());
824
825         assertNotNull(actualResponse);
826         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
827     }
828
829     @Test(expected = PolicyException.class)
830     public void testStdPolicyEnginPushPolicy_NullValues_Exception() throws Exception {
831         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
832
833         spyPolicyEngine.pushPolicy(null, null, null, null, null);
834     }
835
836     @Test(expected = PolicyException.class)
837     public void testStdPolicyEnginPushPolicy_EmptyPolicyScope_Exception() throws Exception {
838         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
839
840         spyPolicyEngine.pushPolicy("", null, null, null, null);
841     }
842
843     @Test(expected = PolicyException.class)
844     public void testStdPolicyEnginPushPolicy_EmptyPolicyName_Exception() throws Exception {
845         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
846
847         spyPolicyEngine.pushPolicy("POLICY_SCOPE", "", null, null, null);
848     }
849
850     @Test
851     public void testStdPolicyEnginPushPolicy_PolicyParameters_noException() throws Exception {
852         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
853
854         final ResponseEntity<String> stubbedResponse =
855                 new ResponseEntity<>("Successful", HttpStatus.OK);
856
857         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
858                 eq(HttpMethod.PUT), any(), any());
859
860         final String actualResponse = spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL,
861                 "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID);
862
863         assertNotNull(actualResponse);
864     }
865
866     @Test
867     public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException()
868             throws Exception {
869         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
870
871         final ResponseEntity<String> stubbedResponse =
872                 new ResponseEntity<>("Successful", HttpStatus.OK);
873
874         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
875                 eq(HttpMethod.PUT), any(), any());
876
877         final String actualResponse = spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME",
878                 ONAP_NAME_VAL, ONAP_NAME_VAL, "CONFIG_NAME", Collections.emptyMap(),
879                 PolicyType.JSON.toString().toUpperCase(), "", "POLICY_SCOPE", REQUEST_UUID, "", "",
880                 "", new Date().toString(), true);
881
882         assertNotNull(actualResponse);
883     }
884
885     @Test(expected = PolicyException.class)
886     public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception()
887             throws Exception {
888         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
889
890         spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null,
891                 null, null, null, null, null, true);
892     }
893
894     @Test
895     public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException()
896             throws Exception {
897         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
898
899         final ResponseEntity<String> stubbedResponse =
900                 new ResponseEntity<>("Successful", HttpStatus.OK);
901
902         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME),
903                 eq(HttpMethod.PUT), any(), any());
904
905         final String actualResponse = spyPolicyEngine.createUpdateConfigFirewallPolicy(
906                 "POLICY_NAME", getJsonObject(JSON_CONFIGURATION), "POLICY_SCOPE", REQUEST_UUID, "",
907                 "", "", new Date().toString(), true);
908
909         assertNotNull(actualResponse);
910     }
911
912     private JsonObject getJsonObject(final String jsonString) {
913         try (final JsonReader jsonReader = Json.createReader(new StringReader(jsonString));) {
914             return jsonReader.readObject();
915         }
916     }
917
918     private StdPolicyEngine getSpyPolicyEngine() throws IOException, PolicyEngineException {
919         return getSpyPolicyEngine(CONFIG_PROPERTIES_FILE, getDefaultProperties());
920     }
921
922     private StdPolicyEngine getSpyPolicyEngine(final String filename, final Properties properties)
923             throws IOException, PolicyEngineException {
924         final File file = temporaryFolder.newFile(filename);
925
926         creatPropertyFile(file, properties);
927
928         final StdPolicyEngine spyPolicyEngine =
929                 spy(new StdPolicyEngine(file.toString(), (String) null));
930         spyPolicyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
931         return spyPolicyEngine;
932     }
933
934     private Properties getDefaultProperties() {
935         final Properties properties = new Properties();
936         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
937         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
938         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
939         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
940         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
941         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
942         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
943         properties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "false");
944         return properties;
945     }
946
947     private StdDecisionResponse getStdDecisionResponse() {
948         final StdDecisionResponse response = new StdDecisionResponse();
949         response.setDecision(PolicyDecision.PERMIT);
950         response.setDetails(PolicyDecision.PERMIT.name());
951
952         return response;
953     }
954
955     private APIDictionaryResponse getAPIDictionaryResponse() {
956         final APIDictionaryResponse response = new APIDictionaryResponse();
957         response.setResponseCode(0);
958         response.setResponseMessage("");
959         response.setDictionaryData(Collections.<String, String>emptyMap());
960         response.setDictionaryJson(Collections.<String, String>emptyMap());
961         return response;
962     }
963
964     private StdPolicyResponse[] getStdPolicyResponse() {
965         final StdPolicyResponse response = new StdPolicyResponse();
966         response.setPolicyResponseStatus(PolicyResponseStatus.ACTION_TAKEN);
967         return new StdPolicyResponse[] {response};
968     }
969
970     private void creatPropertyFile(final File file, final Properties properties)
971             throws IOException {
972         try (final BufferedWriter bufferedWriter = Files.newBufferedWriter(file.toPath());) {
973             properties.store(bufferedWriter, COMMENTS);
974         }
975     }
976
977     private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
978             final String configuration) {
979
980         return getAPIPolicyConfigResponse(policyType, configuration, null);
981     }
982
983     private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
984             final String configuration, final String policyConfigMessage) {
985         final APIPolicyConfigResponse configResponse = new APIPolicyConfigResponse();
986         configResponse.setConfig(configuration);
987         configResponse.setMatchingConditions(getMatchingConditions());
988         configResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED);
989         configResponse.setPolicyName(POLICY_NAME);
990         configResponse.setPolicyType(PolicyConfigType.BRMS_RAW);
991         configResponse.setType(policyType);
992         configResponse.setPolicyVersion(POLICY_VERSION);
993         configResponse.setProperty(Collections.emptyMap());
994         configResponse.setPolicyConfigMessage(policyConfigMessage);
995
996         return new APIPolicyConfigResponse[] {configResponse};
997     }
998
999     private Map<String, String> getMatchingConditions() {
1000         final Map<String, String> attributes = new HashMap<>();
1001         attributes.put(ONAP_NAME, POLICY_NAME);
1002         attributes.put(CONFIG_NAME, "Configuration_name");
1003         return attributes;
1004     }
1005
1006 }