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