1218f1914e0b3fa490daf4e25cb65c387dec64dc
[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.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.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.mockito.junit.MockitoJUnitRunner;
76 import org.onap.policy.api.ConfigRequestParameters;
77 import org.onap.policy.api.DecisionRequestParameters;
78 import org.onap.policy.api.DecisionResponse;
79 import org.onap.policy.api.DeletePolicyParameters;
80 import org.onap.policy.api.DictionaryParameters;
81 import org.onap.policy.api.DictionaryResponse;
82 import org.onap.policy.api.EventRequestParameters;
83 import org.onap.policy.api.ImportParameters;
84 import org.onap.policy.api.MetricsRequestParameters;
85 import org.onap.policy.api.MetricsResponse;
86 import org.onap.policy.api.NotificationScheme;
87 import org.onap.policy.api.PolicyChangeResponse;
88 import org.onap.policy.api.PolicyConfig;
89 import org.onap.policy.api.PolicyConfigException;
90 import org.onap.policy.api.PolicyConfigStatus;
91 import org.onap.policy.api.PolicyConfigType;
92 import org.onap.policy.api.PolicyDecision;
93 import org.onap.policy.api.PolicyDecisionException;
94 import org.onap.policy.api.PolicyEngineException;
95 import org.onap.policy.api.PolicyEventException;
96 import org.onap.policy.api.PolicyException;
97 import org.onap.policy.api.PolicyParameters;
98 import org.onap.policy.api.PolicyResponse;
99 import org.onap.policy.api.PolicyResponseStatus;
100 import org.onap.policy.api.PolicyType;
101 import org.onap.policy.api.PushPolicyParameters;
102 import org.onap.policy.models.APIDictionaryResponse;
103 import org.onap.policy.models.APIPolicyConfigResponse;
104 import org.onap.policy.std.utils.PolicyConfigConstants;
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(MockitoJUnitRunner.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() throws Exception {
177         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
178
179         final Properties properties = new Properties();
180         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
181         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
182         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
183         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB);
184         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME);
185         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
186         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
187         creatPropertyFile(file, properties);
188
189         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
190         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
191         assertEquals(Arrays.asList(UEB), policyEngine.getNotificationType());
192     }
193
194     @Test(expected = PolicyEngineException.class)
195     public void testStdPolicyEngineInitialize_InvalidPropertyFile_Exception() throws PolicyEngineException {
196         new StdPolicyEngine("Invalid.properties", (String) null);
197     }
198
199     @Test(expected = PolicyEngineException.class)
200     public void testStdPolicyEngineInitialize_InvalidPropertyFileWithExt_Exception() throws Exception {
201         final File emptyFile = temporaryFolder.newFile("EmptyFile.txt");
202         new StdPolicyEngine(emptyFile.toString(), (String) null);
203     }
204
205     @Test(expected = PolicyEngineException.class)
206     public void testStdPolicyEngineInitialize_NullArguments_Exception() throws Exception {
207         new StdPolicyEngine((String)null, (String) null);
208     }
209
210     @Test(expected = PolicyEngineException.class)
211     public void testStdPolicyEngineWithPropertiesInitialize_NullArguments_Exception() throws Exception {
212         new StdPolicyEngine((Properties)null, (String) null);
213     }
214
215     @Test(expected = PolicyEngineException.class)
216     public void testStdPolicyEngineInitialize_PropertyFileMissingMandatoryProperties_Exception() throws Exception {
217         final File file = temporaryFolder.newFile(INVALID_CONFIG_PROPERTY_FILE);
218         final Properties properties = new Properties();
219         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
220         creatPropertyFile(file, properties);
221
222         new StdPolicyEngine(file.toString(), (String) null);
223     }
224
225     @Test
226     public void testStdPolicyEngineInitialize_MultiplePdp_noException() throws Exception {
227         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
228
229         final Properties properties = new Properties();
230         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE + PolicyConfigConstants.SEMICOLLON + PDP_PROP_VALUE_1);
231         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
232         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
233         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
234         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
235         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
236         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
237         creatPropertyFile(file, properties);
238
239         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
240         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
241         assertEquals("http://localhost:8092/pdp/", StdPolicyEngine.getPDPURL());
242         StdPolicyEngine.rotatePDPList();
243         assertEquals("https://localhost:8091/pdp/", StdPolicyEngine.getPDPURL());
244         assertEquals(Arrays.asList(UEB, DMAAP), policyEngine.getNotificationType());
245         assertEquals(Arrays.asList(SERVER_NAME, SERVER_NAME), policyEngine.getNotificationURLList());
246     }
247
248     @Test(expected = PolicyEngineException.class)
249     public void testStdPolicyEngineInitialize_NoPDP_noException() throws Exception {
250         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
251
252         final Properties properties = new Properties();
253         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
254         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
255         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
256         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
257         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
258         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
259         creatPropertyFile(file, properties);
260
261         new StdPolicyEngine(file.toString(), (String) null);
262     }
263
264     @Test
265     public void testStdPolicyEngineInitializeNotificationTypeDMMAP_noException() throws Exception {
266         final File file = temporaryFolder.newFile(CONFIG_PROPERTIES_FILE);
267
268         final Properties properties = new Properties();
269         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
270         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
271         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
272         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, DMAAP);
273         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
274         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
275         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
276         creatPropertyFile(file, properties);
277
278         final StdPolicyEngine policyEngine = new StdPolicyEngine(file.toString(), (String) null);
279         policyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
280
281         assertEquals(Arrays.asList(DMAAP), policyEngine.getNotificationType());
282
283     }
284
285     @Test
286     public void testStdPolicyEngineSendEvent_noException() throws Exception {
287         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
288         doReturn(new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED)).when(spyPolicyEngine)
289                 .callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
290
291         final Collection<PolicyResponse> actualPolicyResponses =
292                 spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
293
294         assertEquals(1, actualPolicyResponses.size());
295
296     }
297
298     @Test(expected = PolicyEventException.class)
299     public void testStdPolicyEngineSendEvent_NullEventRequestParameters_Exception() throws Exception {
300         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
301         spyPolicyEngine.sendEvent((EventRequestParameters) null);
302     }
303
304     @Test(expected = PolicyEventException.class)
305     public void testStdPolicyEngineSendEvent_EventRequestParameters_CallPDPThrow401Exception_Exception()
306             throws Exception {
307         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
308         Mockito.doThrow(new RuntimeException(new RestClientException("Error 401"))).when(spyPolicyEngine)
309                 .callNewPDP(any(), any(), any(), any());
310         spyPolicyEngine.sendEvent(Collections.emptyMap(), REQUEST_UUID);
311     }
312
313     @Test
314     public void testStdPolicyEngineSendEvent_EventRequestParameters_noException() throws Exception {
315         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
316
317         final ResponseEntity<StdPolicyResponse[]> stubbedResponse =
318                 new ResponseEntity<>(getStdPolicyResponse(), HttpStatus.ACCEPTED);
319
320         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(SEND_EVENT_RESOURCE_NAME), any(), any(), any());
321
322         final EventRequestParameters eventRequestParameters = new EventRequestParameters();
323         eventRequestParameters.setEventAttributes(Collections.emptyMap());
324         eventRequestParameters.setRequestID(REQUEST_UUID);
325
326         final Collection<PolicyResponse> actualPolicyResponses = spyPolicyEngine.sendEvent(eventRequestParameters);
327
328         assertEquals(1, actualPolicyResponses.size());
329
330     }
331
332     @Test
333     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigJSON_noException() throws Exception {
334         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
335
336         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
337                 getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION), HttpStatus.ACCEPTED);
338
339         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
340                 any(), any());
341
342         final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
343
344         assertEquals(1, actualPolicyResponses.size());
345
346         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
347         assertNotNull(actualPolicyConfig.toJSON());
348
349     }
350
351     @Test
352     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigOther_noException() throws Exception {
353         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
354
355         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
356                 new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.OTHER, COMMENTS), HttpStatus.ACCEPTED);
357
358         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
359                 any(), any());
360
361         final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
362
363         assertEquals(1, actualPolicyResponses.size());
364
365         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
366         assertNotNull(actualPolicyConfig.toOther());
367
368     }
369
370     @Test
371     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigXML_noException() throws Exception {
372         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
373
374         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse = new ResponseEntity<>(
375                 getAPIPolicyConfigResponse(PolicyType.XML, XML_CONFIGURATION), HttpStatus.ACCEPTED);
376
377         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
378                 any(), any());
379
380         final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
381
382         assertEquals(1, actualPolicyResponses.size());
383
384         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
385         assertNotNull(actualPolicyConfig.toXML());
386
387     }
388
389     @Test
390     public void testStdPolicyEngineGetConfig_ConfigRequestParametersPolicyConfigProperties_noException()
391             throws Exception {
392         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
393
394         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
395                 new ResponseEntity<>(getAPIPolicyConfigResponse(PolicyType.PROPERTIES, COMMENTS), HttpStatus.ACCEPTED);
396
397         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
398                 any(), any());
399
400         final Collection<PolicyConfig> actualPolicyResponses = spyPolicyEngine.getConfig(new ConfigRequestParameters());
401
402         assertEquals(1, actualPolicyResponses.size());
403
404         final PolicyConfig actualPolicyConfig = actualPolicyResponses.iterator().next();
405         assertNotNull(actualPolicyConfig.toProperties());
406
407     }
408
409     @Test(expected = PolicyConfigException.class)
410     public void testStdPolicyEngineSendEvent_ConfigRequestParameters_CallPDPThrow404Exception_Exception()
411             throws Exception {
412         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
413         doThrow(new RuntimeException(new RestClientException("Error 404"))).when(spyPolicyEngine).callNewPDP(any(),
414                 any(), any(), any());
415         spyPolicyEngine.getConfig(new ConfigRequestParameters());
416     }
417
418     @Test
419     public void testStdPolicyEngineListConfig_ConfigRequestParametersPolicyConfigProperties_noException()
420             throws Exception {
421         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
422
423         final APIPolicyConfigResponse[] apiPolicyConfigResponse =
424                 getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION);
425
426         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
427                 new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
428
429         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
430                 any(), any());
431
432         final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
433         assertEquals(1, actualResponse.size());
434         assertNotNull(actualResponse.iterator().next());
435
436     }
437
438     @Test
439     public void testStdPolicyEngineListConfig_ConfigRequestParametersMessageConfigContainsPE300_noException()
440             throws Exception {
441         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
442
443         final APIPolicyConfigResponse[] apiPolicyConfigResponse =
444                 getAPIPolicyConfigResponse(PolicyType.JSON, JSON_CONFIGURATION, PolicyConfigConstants.PE300);
445
446         final ResponseEntity<APIPolicyConfigResponse[]> stubbedResponse =
447                 new ResponseEntity<>(apiPolicyConfigResponse, HttpStatus.ACCEPTED);
448
449         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_CONFIG_RESOURCE_NAME), eq(HttpMethod.POST),
450                 any(), any());
451
452         final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
453
454         assertEquals(1, actualResponse.size());
455
456     }
457
458     @Test
459     public void testStdPolicyEngineListConfig_ConfigRequestParametersWithTestProperty_noException() throws Exception {
460         final Properties defaultProperties = getDefaultProperties();
461         defaultProperties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "test");
462         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine("test" + CONFIG_PROPERTIES_FILE, defaultProperties);
463
464         final Collection<String> actualResponse = spyPolicyEngine.listConfig(new ConfigRequestParameters());
465
466         assertEquals(1, actualResponse.size());
467
468     }
469
470     @Test
471     public void testStdPolicyEnginGetDecision_PolicyDecision_noException() throws Exception {
472
473         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
474
475         final ResponseEntity<StdDecisionResponse> stubbedResponse =
476                 new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
477
478         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST),
479                 any(), any());
480
481         final DecisionResponse actualResponse =
482                 spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
483
484         assertNotNull(actualResponse);
485     }
486
487     @Test(expected = PolicyDecisionException.class)
488     public void testStdPolicyEngineGetDecision_PolicyDecision_CallPDPThrow400Exception_Exception() throws Exception {
489         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
490         doThrow(new RuntimeException(new RestClientException("Error 400"))).when(spyPolicyEngine)
491                 .callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
492         spyPolicyEngine.getDecision(ONAP_NAME_VAL, Collections.emptyMap(), REQUEST_UUID);
493     }
494
495     @Test
496     public void testStdPolicyEnginGetDecision_DecisionRequestParameters_noException() throws Exception {
497
498         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
499
500         final ResponseEntity<StdDecisionResponse> stubbedResponse =
501                 new ResponseEntity<>(getStdDecisionResponse(), HttpStatus.ACCEPTED);
502
503         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DECISION_RESOURCE_NAME), eq(HttpMethod.POST),
504                 any(), any());
505
506         final DecisionRequestParameters requestParameters = new DecisionRequestParameters();
507         requestParameters.setOnapName(ONAP_NAME_VAL);
508         requestParameters.setRequestID(REQUEST_UUID);
509         requestParameters.setDecisionAttributes(Collections.emptyMap());
510
511         final DecisionResponse actualResponse = spyPolicyEngine.getDecision(requestParameters);
512
513         assertNotNull(actualResponse);
514     }
515
516     @Test(expected = PolicyDecisionException.class)
517     public void ttestStdPolicyEnginGetDecision_NullDecisionRequestParameters_Exception() throws Exception {
518         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
519         spyPolicyEngine.getDecision((DecisionRequestParameters) null);
520     }
521
522     @Test
523     public void testStdPolicyEnginGetMetrics_MetricsRequestParameters_noException() throws Exception {
524
525         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
526
527         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Metrics", HttpStatus.ACCEPTED);
528
529         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET),
530                 any(), any());
531
532         final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters());
533         assertNotNull(actualResponse);
534         assertEquals(HttpStatus.ACCEPTED.value(), actualResponse.getResponseCode());
535
536     }
537
538     @Test
539     public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowHttpException_ResponseWithHttpCode()
540             throws Exception {
541         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
542         doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine)
543                 .callNewPDP(eq(GET_METRICS_RESOURCE_NAME), eq(HttpMethod.GET), any(), any());
544
545         final MetricsResponse actualResponse = spyPolicyEngine.getMetrics(new MetricsRequestParameters());
546         assertNotNull(actualResponse);
547         assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
548
549     }
550
551     @Test(expected = PolicyException.class)
552     public void testStdPolicyEngineGetMetrics_MetricsRequestParametersCallPDPThrowPolicyException_Exception()
553             throws Exception {
554         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
555         doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(GET_METRICS_RESOURCE_NAME),
556                 eq(HttpMethod.GET), any(), any());
557
558         spyPolicyEngine.getMetrics(new MetricsRequestParameters());
559
560     }
561
562     @Test
563     public void testStdPolicyEnginPushPolicy_PushPolicyParameters_noException() throws Exception {
564
565         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
566
567         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
568
569         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
570                 any(), any());
571
572         final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters());
573
574         assertNotNull(actualResponse);
575         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
576     }
577
578     @Test
579     public void testStdPolicyEnginePushPolicy_PushPolicyParametersThrowsHttpClientErrorException_ResponseWithHttpCode()
580             throws Exception {
581         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
582         doThrow(new PolicyException(new HttpClientErrorException(HttpStatus.BAD_GATEWAY))).when(spyPolicyEngine)
583                 .callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT), any(), any());
584
585         final PolicyChangeResponse actualResponse = spyPolicyEngine.pushPolicy(new PushPolicyParameters());
586
587         assertNotNull(actualResponse);
588         assertEquals(HttpStatus.BAD_GATEWAY.value(), actualResponse.getResponseCode());
589
590     }
591
592     @Test(expected = PolicyException.class)
593     public void testStdPolicyEnginePushPolicy_PushPolicyParameters_Exception() throws Exception {
594         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
595         doThrow(PolicyException.class).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME),
596                 eq(HttpMethod.PUT), any(), any());
597
598         spyPolicyEngine.pushPolicy(new PushPolicyParameters());
599
600     }
601
602     @Test
603     public void testStdPolicyEnginDeletePolicy_DeletePolicyParameters_noException() throws Exception {
604
605         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
606
607         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
608
609         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(DELETE_POLICY_RESOURCE_NAME),
610                 eq(HttpMethod.DELETE), any(), any());
611
612         final PolicyChangeResponse actualResponse = spyPolicyEngine.deletePolicy(new DeletePolicyParameters());
613
614         assertNotNull(actualResponse);
615         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
616     }
617
618     @Test
619     public void testStdPolicyEnginGetDictionaryItem_DictionaryParameters_noException() throws Exception {
620
621         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
622
623         final ResponseEntity<APIDictionaryResponse> stubbedResponse =
624                 new ResponseEntity<>(getAPIDictionaryResponse(), HttpStatus.OK);
625
626         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME),
627                 eq(HttpMethod.POST), any(), any());
628
629         final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
630
631         assertNotNull(actualResponse);
632     }
633
634     @Test
635     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp400ExceptionThrown_ResponseWithHttpCode()
636             throws Exception {
637         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
638         doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Error 400")))
639                 .when(spyPolicyEngine)
640                 .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
641
642         final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
643
644         assertNotNull(actualResponse);
645         assertEquals(HttpStatus.BAD_REQUEST.value(), actualResponse.getResponseCode());
646
647     }
648
649     @Test
650     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithHttp401ExceptionThrown_ResponseWithHttpCode()
651             throws Exception {
652         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
653         doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.UNAUTHORIZED, "Error 401")))
654                 .when(spyPolicyEngine)
655                 .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
656
657         final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
658
659         assertNotNull(actualResponse);
660         assertEquals(HttpStatus.UNAUTHORIZED.value(), actualResponse.getResponseCode());
661
662     }
663
664     @Test
665     public void testStdPolicyGetDictionaryItem_DictionaryParametersWithRunTimeExceptionThrown_ResponseWithHttpCode()
666             throws Exception {
667         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
668         doThrow(new RuntimeException(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error")))
669                 .when(spyPolicyEngine)
670                 .callNewPDP(eq(GET_DICTIONARY_ITEMS_RESOURCE_NAME), eq(HttpMethod.POST), any(), any());
671
672         final DictionaryResponse actualResponse = spyPolicyEngine.getDictionaryItem(new DictionaryParameters());
673
674         assertNotNull(actualResponse);
675         assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), actualResponse.getResponseCode());
676
677     }
678
679     @Test
680     public void testStdPolicyEnginCreateDictionaryItem_DictionaryParameters_noException() throws Exception {
681
682         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
683
684         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
685
686         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_DICTIONARY_ITEM_RESOURCE_NAME),
687                 eq(HttpMethod.PUT), any(), any());
688
689         final PolicyChangeResponse actualResponse = spyPolicyEngine.createDictionaryItem(new DictionaryParameters());
690
691         assertNotNull(actualResponse);
692         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
693     }
694
695     @Test
696     public void testStdPolicyEnginUpdateDictionaryItem_DictionaryParameters_noException() throws Exception {
697
698         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
699
700         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
701
702         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_DICTIONARY_ITEM_RESOURCE_NAME),
703                 eq(HttpMethod.PUT), any(), any());
704
705         final PolicyChangeResponse actualResponse = spyPolicyEngine.updateDictionaryItem(new DictionaryParameters());
706
707         assertNotNull(actualResponse);
708         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
709     }
710
711     @Test
712     public void testStdPolicyEnginPolicyEngineImport_ImportParameters_noException() throws Exception {
713         final File emptyfile = temporaryFolder.newFile("emptyFile.txt");
714         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
715
716         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
717
718         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(POLICY_ENGINE_IMPORT_RESOURCE_NAME),
719                 eq(HttpMethod.POST), any(), any());
720
721         final ImportParameters importParameters = new ImportParameters();
722         importParameters.setFilePath(emptyfile.toString());
723         final PolicyChangeResponse actualResponse = spyPolicyEngine.policyEngineImport(importParameters);
724
725         assertNotNull(actualResponse);
726         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
727     }
728
729     @Test
730     public void testStdPolicyEnginCreatePolicy_PolicyParameters_noException() throws Exception {
731         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
732
733         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
734
735         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(CREATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
736                 any(), any());
737
738         final PolicyChangeResponse actualResponse = spyPolicyEngine.createPolicy(new PolicyParameters());
739
740         assertNotNull(actualResponse);
741         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
742     }
743
744     @Test
745     public void testStdPolicyEnginUpdatePolicy_PolicyParameters_noException() throws Exception {
746         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
747
748         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
749
750         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
751                 any(), any());
752
753         final PolicyChangeResponse actualResponse = spyPolicyEngine.updatePolicy(new PolicyParameters());
754
755         assertNotNull(actualResponse);
756         assertEquals(HttpStatus.OK.value(), actualResponse.getResponseCode());
757     }
758
759     @Test(expected = PolicyException.class)
760     public void testStdPolicyEnginPushPolicy_NullValues_Exception() throws Exception {
761         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
762
763         spyPolicyEngine.pushPolicy(null, null, null, null, null);
764     }
765
766     @Test(expected = PolicyException.class)
767     public void testStdPolicyEnginPushPolicy_EmptyPolicyScope_Exception() throws Exception {
768         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
769
770         spyPolicyEngine.pushPolicy("", null, null, null, null);
771     }
772
773     @Test(expected = PolicyException.class)
774     public void testStdPolicyEnginPushPolicy_EmptyPolicyName_Exception() throws Exception {
775         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
776
777         spyPolicyEngine.pushPolicy("POLICY_SCOPE", "", null, null, null);
778     }
779
780     @Test
781     public void testStdPolicyEnginPushPolicy_PolicyParameters_noException() throws Exception {
782         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
783
784         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
785
786         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(PUSH_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
787                 any(), any());
788
789         final String actualResponse =
790                 spyPolicyEngine.pushPolicy("POLICY_SCOPE", ONAP_NAME_VAL, "POLICY_TYPE", "POLICY_GROUP", REQUEST_UUID);
791
792         assertNotNull(actualResponse);
793     }
794
795     @Test
796     public void testStdPolicyEnginCreateUpdateConfigPolicy_PolicyParameters_noException() throws Exception {
797         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
798
799         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
800
801         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
802                 any(), any());
803
804         final String actualResponse = spyPolicyEngine.createUpdateConfigPolicy("POLICY_NAME", ONAP_NAME_VAL,
805                 ONAP_NAME_VAL, "CONFIG_NAME", Collections.emptyMap(), PolicyType.JSON.toString().toUpperCase(), "",
806                 "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true);
807
808         assertNotNull(actualResponse);
809     }
810
811     @Test(expected = PolicyException.class)
812     public void testStdPolicyEnginCreateUpdateConfigPolicy_NullPolicyName_Exception() throws Exception {
813         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
814
815         spyPolicyEngine.createUpdateConfigPolicy(null, null, null, null, null, null, null, null, null, null, null, null,
816                 null, true);
817     }
818
819     @Test
820     public void testStdPolicyEnginCreateUpdateConfigFirewallPolicy_PolicyParameters_noException() throws Exception {
821         final StdPolicyEngine spyPolicyEngine = getSpyPolicyEngine();
822
823         final ResponseEntity<String> stubbedResponse = new ResponseEntity<>("Successful", HttpStatus.OK);
824
825         doReturn(stubbedResponse).when(spyPolicyEngine).callNewPDP(eq(UPDATE_POLICY_RESOURCE_NAME), eq(HttpMethod.PUT),
826                 any(), any());
827
828         final String actualResponse =
829                 spyPolicyEngine.createUpdateConfigFirewallPolicy("POLICY_NAME", getJsonObject(JSON_CONFIGURATION),
830                         "POLICY_SCOPE", REQUEST_UUID, "", "", "", new Date().toString(), true);
831
832         assertNotNull(actualResponse);
833     }
834
835     private JsonObject getJsonObject(final String jsonString) {
836         try (final JsonReader jsonReader = Json.createReader(new StringReader(jsonString));) {
837             return jsonReader.readObject();
838         }
839     }
840
841     private StdPolicyEngine getSpyPolicyEngine() throws IOException, PolicyEngineException {
842         return getSpyPolicyEngine(CONFIG_PROPERTIES_FILE, getDefaultProperties());
843     }
844
845     private StdPolicyEngine getSpyPolicyEngine(final String filename, final Properties properties)
846             throws IOException, PolicyEngineException {
847         final File file = temporaryFolder.newFile(filename);
848
849         creatPropertyFile(file, properties);
850
851         final StdPolicyEngine spyPolicyEngine = spy(new StdPolicyEngine(file.toString(), (String) null));
852         spyPolicyEngine.setScheme(NotificationScheme.MANUAL_NOTIFICATIONS);
853         return spyPolicyEngine;
854     }
855
856     private Properties getDefaultProperties() {
857         final Properties properties = new Properties();
858         properties.setProperty(PDP_URL_PROP_NAME, PDP_PROP_VALUE);
859         properties.setProperty(CLIENT_ID_PROP_NAME, "test");
860         properties.setProperty(CLIENT_KEY_PROP_NAME, "test");
861         properties.setProperty(NOTIFICATION_TYPE_PROP_NAME, UEB + COMMA + DMAAP);
862         properties.setProperty(NOTIFICATION_SERVERS_PROP_NAME, SERVER_NAME + COMMA + SERVER_NAME);
863         properties.setProperty(NOTIFICATION_TOPIC_PROP_NAME, "test");
864         properties.setProperty(ENVIRONMENT_PROP_NAME, "TEST");
865         properties.setProperty(PolicyConfigConstants.JUNIT_PROP_NAME, "false");
866         return properties;
867     }
868
869     private StdDecisionResponse getStdDecisionResponse() {
870         final StdDecisionResponse response = new StdDecisionResponse();
871         response.setDecision(PolicyDecision.PERMIT);
872         response.setDetails(PolicyDecision.PERMIT.name());
873
874         return response;
875     }
876
877     private APIDictionaryResponse getAPIDictionaryResponse() {
878         final APIDictionaryResponse response = new APIDictionaryResponse();
879         response.setResponseCode(0);
880         response.setResponseMessage("");
881         response.setDictionaryData(Collections.<String, String>emptyMap());
882         response.setDictionaryJson(Collections.<String, String>emptyMap());
883         return response;
884     }
885
886     private StdPolicyResponse[] getStdPolicyResponse() {
887         final StdPolicyResponse response = new StdPolicyResponse();
888         response.setPolicyResponseStatus(PolicyResponseStatus.ACTION_TAKEN);
889         return new StdPolicyResponse[] {response};
890     }
891
892     private void creatPropertyFile(final File file, final Properties properties) throws IOException {
893         try (final BufferedWriter bufferedWriter = Files.newBufferedWriter(file.toPath());) {
894             properties.store(bufferedWriter, COMMENTS);
895         }
896     }
897
898     private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
899             final String configuration) {
900
901         return getAPIPolicyConfigResponse(policyType, configuration, null);
902     }
903
904     private APIPolicyConfigResponse[] getAPIPolicyConfigResponse(final PolicyType policyType,
905             final String configuration, final String policyConfigMessage) {
906         final APIPolicyConfigResponse configResponse = new APIPolicyConfigResponse();
907         configResponse.setConfig(configuration);
908         configResponse.setMatchingConditions(getMatchingConditions());
909         configResponse.setPolicyConfigStatus(PolicyConfigStatus.CONFIG_RETRIEVED);
910         configResponse.setPolicyName(POLICY_NAME);
911         configResponse.setPolicyType(PolicyConfigType.BRMS_RAW);
912         configResponse.setType(policyType);
913         configResponse.setPolicyVersion(POLICY_VERSION);
914         configResponse.setProperty(Collections.emptyMap());
915         configResponse.setPolicyConfigMessage(policyConfigMessage);
916
917         return new APIPolicyConfigResponse[] {configResponse};
918     }
919
920     private Map<String, String> getMatchingConditions() {
921         final Map<String, String> attributes = new HashMap<>();
922         attributes.put(ONAP_NAME, POLICY_NAME);
923         attributes.put(CONFIG_NAME, "Configuration_name");
924         return attributes;
925     }
926
927 }