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