Initial OpenECOMP policy/engine commit
[policy/engine.git] / PolicyEngineAPI / src / test / java / org / openecomp / policy / std / test / StdPolicyEngineTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineAPI
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
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.openecomp.policy.std.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.io.BufferedReader;
29 import java.io.File;
30 import java.io.FileReader;
31 import java.io.IOException;
32 import java.io.StringReader;
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.Map;
40 import java.util.UUID;
41
42 import javax.json.Json;
43 import javax.json.JsonObject;
44 import javax.json.JsonReader;
45
46 import org.junit.After;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.mockito.Mockito;
50 import org.openecomp.policy.api.AttributeType;
51 import org.openecomp.policy.api.ConfigRequestParameters;
52 import org.openecomp.policy.api.DecisionRequestParameters;
53 import org.openecomp.policy.api.DecisionResponse;
54 import org.openecomp.policy.api.DeletePolicyCondition;
55 import org.openecomp.policy.api.DeletePolicyParameters;
56 import org.openecomp.policy.api.DictionaryParameters;
57 import org.openecomp.policy.api.DictionaryType;
58 import org.openecomp.policy.api.EventRequestParameters;
59 import org.openecomp.policy.api.ImportParameters;
60 import org.openecomp.policy.api.NotificationHandler;
61 import org.openecomp.policy.api.NotificationScheme;
62 import org.openecomp.policy.api.PolicyChangeResponse;
63 import org.openecomp.policy.api.PolicyClass;
64 import org.openecomp.policy.api.PolicyConfig;
65 import org.openecomp.policy.api.PolicyConfigStatus;
66 import org.openecomp.policy.api.PolicyConfigType;
67 import org.openecomp.policy.api.PolicyDecision;
68 import org.openecomp.policy.api.PolicyParameters;
69 import org.openecomp.policy.api.PolicyResponse;
70 import org.openecomp.policy.api.PolicyType;
71 import org.openecomp.policy.api.PushPolicyParameters;
72 import org.openecomp.policy.api.ImportParameters.IMPORT_TYPE;
73 import org.openecomp.policy.std.StdDecisionResponse;
74 import org.openecomp.policy.std.StdPolicyChangeResponse;
75 import org.openecomp.policy.std.StdPolicyConfig;
76 import org.openecomp.policy.std.StdPolicyEngine;
77 import org.openecomp.policy.std.StdPolicyResponse;
78
79 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
80 import org.openecomp.policy.common.logging.flexlogger.Logger;
81
82 /**
83  * The class <code>StdPolicyEngineTest</code> contains tests for the class <code>{@link StdPolicyEngine}</code>.
84  *
85  * @generatedBy CodePro at 6/3/16 2:03 PM
86  * @version $Revision: 1.0 $
87  */
88 public class StdPolicyEngineTest {
89         
90         private static final Logger logger = FlexLogger.getLogger(StdPolicyEngine.class);
91
92         private StdPolicyEngine fixture = null;
93         private StdPolicyEngine mockEngine = null;
94         
95         PolicyChangeResponse result = null;
96         StdPolicyChangeResponse response = new StdPolicyChangeResponse();
97         PolicyParameters policyParameters = new PolicyParameters();
98         String json = null;
99         
100         /**
101          * Perform pre-test initialization.
102          *
103          * @throws Exception
104          *         if the initialization fails for some reason
105          *
106          * @generatedBy CodePro at 6/3/16 2:03 PM
107          */
108         @Before
109         public void setUp()
110                 throws Exception {
111                 fixture = new StdPolicyEngine("Test/config_pass.properties");
112                 
113                 //Mocks
114                 mockEngine = Mockito.mock(StdPolicyEngine.class);
115         }
116         
117     private static JsonObject buildJSON(String jsonString) {
118         JsonObject json = null;;
119         if (jsonString != null) {
120             StringReader in = null;
121              
122             in = new StringReader(jsonString);
123              
124             JsonReader jsonReader = Json.createReader(in);
125             json = jsonReader.readObject();        
126         } 
127         
128         return json;
129     }
130     
131         //Reads a File and converts into a String. 
132         private static String readFile( String file ) throws IOException {
133             BufferedReader reader = new BufferedReader( new FileReader (file));
134             String         line = null;
135             StringBuilder  stringBuilder = new StringBuilder();
136             String         ls = System.getProperty("line.separator");
137
138             try {
139                 while( ( line = reader.readLine() ) != null ) {
140                     stringBuilder.append( line );
141                     stringBuilder.append( ls );
142                 }
143
144                 return stringBuilder.toString();
145             } finally {
146                 reader.close();
147             }
148         }
149
150         /**
151          * Run the StdPolicyEngine(String) constructor test.
152          *
153          * @throws Exception
154          *
155          * @generatedBy CodePro at 6/3/16 2:03 PM
156          */
157         @Test
158         public void testStdPolicyEngine()
159                 throws Exception {
160                 String propertyFilePath = "Test/config_pass.properties";
161
162                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath);
163
164                 assertNotNull(result);
165         }
166
167         /**
168          * Run the StdPolicyEngine(String) constructor test.
169          *
170          * @throws Exception
171          *
172          * @generatedBy CodePro at 6/3/16 2:03 PM
173          */
174 /*      @Test
175         public void testStdPolicyEngine_2()
176                 throws Exception {
177                 String propertyFilePath = "http";
178
179                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath);
180
181                 assertNull(result);
182         }
183 */
184         /**
185          * Run the StdPolicyEngine(String,NotificationScheme) constructor test.
186          *
187          * @throws Exception
188          *
189          * @generatedBy CodePro at 6/3/16 2:03 PM
190          */
191         @Test
192         public void testStdPolicyEngine_3()
193                 throws Exception {
194                 String propertyFilePath = "Test/config_pass.properties";
195                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
196
197                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme);
198
199                 assertNotNull(result);
200         }
201
202         /**
203          * Run the StdPolicyEngine(String,NotificationScheme) constructor test.
204          *
205          * @throws Exception
206          *
207          * @generatedBy CodePro at 6/3/16 2:03 PM
208          */
209 /*      @Test
210         public void testStdPolicyEngine_4()
211                 throws Exception {
212                 String propertyFilePath = "http";
213                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
214
215                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme);
216
217                 // add additional test code here
218                 // An unexpected exception was thrown in user code while executing this test:
219                 //    java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.StdPolicyEngine
220                 assertNull(result);
221         }*/
222
223         /**
224          * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test.
225          *
226          * @throws Exception
227          *
228          * @generatedBy CodePro at 6/3/16 2:03 PM
229          */
230 /*      @Test
231         public void testStdPolicyEngine_5()
232                 throws Exception {
233                 String propertyFilePath = "Test/config_pass.properties";
234                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
235                 NotificationHandler handler = new Handler();
236
237                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler);
238
239                 assertNull(result);
240         }*/
241
242         /**
243          * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test.
244          *
245          * @throws Exception
246          *
247          * @generatedBy CodePro at 6/3/16 2:03 PM
248          */
249 /*      @Test
250         public void testStdPolicyEngine_6()
251                 throws Exception {
252                 String propertyFilePath = "http";
253                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
254                 NotificationHandler handler = new Handler();
255
256                 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler);
257
258                 assertNull(result);
259         }
260 */
261         /**
262          * Run the StdPolicyEngine(List<String>,List<String>,List<String>,List<String>,NotificationScheme,NotificationHandler,String) constructor test.
263          *
264          * @throws Exception
265          *
266          * @generatedBy CodePro at 6/3/16 2:03 PM
267          */
268 /*      @Test
269         public void testStdPolicyEngine_8()
270                 throws Exception {
271                 List<String> configURL = new LinkedList();
272                 List<String> configPapURL = new LinkedList();
273                 List<String> encodingPAP = new LinkedList();
274                 List<String> encoding = new LinkedList();
275                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
276                 NotificationHandler handler = new Handler();
277                 String clientAuth = "TEST";
278
279                 StdPolicyEngine result = new StdPolicyEngine(configURL, configPapURL, encodingPAP, encoding, scheme, handler, clientAuth);
280
281                 // add additional test code here
282                 // An unexpected exception was thrown in user code while executing this test:
283                 //    java.lang.NoClassDefFoundError: Could not initialize class org.openecomp.policy.std.StdPolicyEngine
284                 assertNull(result);
285         }
286 */
287         /**
288          * Run the Collection<PolicyConfig> config(ConfigRequestParameters) method test.
289          *
290          * @throws Exception
291          *
292          * @generatedBy CodePro at 6/3/16 2:03 PM
293          */
294         @Test
295         public void testConfig()
296                 throws Exception {
297                 String configMessage = "Error in Calling the Configuration URL java.lang.Exception: PE500 - Process Flow Issue: Cannot open a connection to the configURL";
298                 PolicyConfigStatus configStatus = PolicyConfigStatus.CONFIG_NOT_FOUND;
299                 String policyName = "JunitTest.Config_testing";
300                 String policyVersion = "1";
301                                 
302                 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
303                 configRequestParameters.setPolicyName(".*");
304                 Collection<PolicyConfig> result = fixture.config(configRequestParameters);              
305                 
306                 //assertEquals(response, result);
307                 for(PolicyConfig policyConfig: result){
308                         assertEquals(policyName, policyConfig.getPolicyName());
309                         assertEquals(policyVersion, policyConfig.getPolicyVersion());
310                         assertEquals(configStatus, policyConfig.getPolicyConfigStatus());
311                         assertEquals(configMessage, policyConfig.getPolicyConfigMessage());
312                 }
313         }
314         
315         
316         /**
317          * Run the Collection<String> listConfig(ConfigRequestParameters) method test.
318          *
319          * @throws Exception
320          *
321          */
322         @Test
323         public void testListConfig()
324                 throws Exception {
325                 
326                 Collection<String> response = new ArrayList<String>();
327                 response.add("Policy Name: listConfigTest");
328
329                 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
330                 configRequestParameters.setPolicyName(".*");
331                 Collection<String> result = fixture.listConfig(configRequestParameters);
332
333                 assertEquals(result, response);
334         }
335
336         /**
337          * Run the String copyFile(String,String,StdPAPPolicy,String,UUID) method test.
338          *
339          * @throws Exception
340          *
341          * @generatedBy CodePro at 6/3/16 2:03 PM
342          */
343 /*      @Test
344         public void testCopyFile()
345                 throws Exception {
346                 String policyId = "test.testing";
347                 String group = "default";
348                 URI selectedURI = null;
349                 StdPDPPolicy policy = new StdPDPPolicy("testing", true, "test", selectedURI, true, "test", "testing", "1");     
350                 StdPAPPolicy location = new StdPAPPolicy(policy.getLocation());
351                 String clientScope = "Config";
352                 UUID requestID = UUID.randomUUID();
353
354                 String result = fixture.copyFile(policyId, group, location, clientScope, requestID);
355
356                 assertNotNull(result);
357         }*/
358
359         /**
360          * Run the String copyPolicy(PDPPolicy,String,String,UUID) method test.
361          *
362          * @throws Exception
363          *
364          * @generatedBy CodePro at 6/3/16 2:03 PM
365          */
366 /*      @Test
367         public void testCopyPolicy()
368                 throws Exception {
369                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
370                 URI selectedURI = null;
371                 
372                 StdPDPPolicy policy = new StdPDPPolicy("testing", true, "test", selectedURI, true, "test", "testing", "1");
373                 String group = "default";
374                 String policyType = "Base";
375                 UUID requestID = UUID.randomUUID();
376
377                 String result = fixture.copyPolicy(policy, group, policyType, requestID);
378                 
379                 assertNotNull(result);
380         }
381 */
382         /**
383          * Run the String createConfigFirewallPolicy(String,JsonObject,String,UUID) method test.
384          *
385          * @throws Exception
386          *
387          * @generatedBy CodePro at 6/3/16 2:03 PM
388          */
389         @Test
390         public void testCreateConfigFirewallPolicy()
391                 throws Exception {
392                 
393                 response.setResponseMessage("success");
394                 PolicyParameters policyParameters = new PolicyParameters();
395                 policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); 
396
397                 String json= "{\"serviceTypeId\": \"/v0/firewall/pan\",\"configName\": \"rule1607\",\"deploymentOption\":{\"deployNow\": false},\"securityZoneId\": \"/v0/firewall/pan\",\"serviceGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"SList\"},{\"type\": \"REFERENCE\",\"name\": \"Syslog\"}]}, {\"name\": \"Syslog\",\"description\": \"NA\",\"type\": \"SERVICE\",\"transportProtocol\": \"udp\",\"appProtocol\": null,\"ports\": \"514\"}, {\"name\": \"SList\",\"description\": \"Service List\",\"type\": \"SERVICE\",\"transportProtocol\": \"tcp\",\"appProtocol\": null,\"ports\": \"8080\"}],\"addressGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"},{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]},{\"name\": \"PL_CCE3\",\"description\": \"CCE Routers\",\"members\":[{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]}],\"firewallRuleList\": [{\"position\": \"1\",\"ruleName\": \"1607Rule\",\"fromZones\": [\"Trusted\"],\"toZones\": [\"Untrusted\"],\"negateSource\": false,\"negateDestination\": false,\"sourceList\": [{\"type\": \"REFERENCE\",\"name\": \"PL_CCE3\"}, {\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"destinationList\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"sourceServices\": [],\"destServices\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"action\": \"accept\",\"description\": \"Rule for 1607 templates\",\"enabled\": true,\"log\": true}]}";
398                 policyParameters.setConfigBody(json);
399                 policyParameters.setPolicyName("test.testing");
400
401                 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
402
403                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
404         }
405
406         /**
407          * Run the String createConfigPolicy(String,String,String,String,Map<String,String>,String,String,String,UUID) method test.
408          *
409          * @throws Exception
410          *
411          * @generatedBy CodePro at 6/3/16 2:03 PM
412          */
413         @Test
414         public void testCreateConfigPolicy()
415                 throws Exception {
416                 response.setResponseMessage("success");
417                 PolicyParameters policyParameters = new PolicyParameters();
418                 policyParameters.setPolicyConfigType(PolicyConfigType.Base);
419                 policyParameters.setPolicyName("test.junittest");
420                 policyParameters.setPolicyDescription("testing junit");
421                 policyParameters.setEcompName("test");
422                 policyParameters.setConfigName("testname");
423         Map<String, String> configAttributes = new HashMap<String, String>(); 
424         configAttributes.put("Template", "SampleTemplate");
425         configAttributes.put("controller", "default"); 
426         configAttributes.put("SamPoll", "30");
427         configAttributes.put("value", "abcd"); 
428                 Map<AttributeType, Map<String,String>> attributes = new HashMap<AttributeType, Map<String,String>>();
429         attributes.put(AttributeType.MATCHING, configAttributes);
430         policyParameters.setAttributes(attributes);
431                 policyParameters.setRequestID(UUID.randomUUID());
432                 policyParameters.setConfigBodyType(PolicyType.OTHER);
433                 policyParameters.setConfigBody("test");
434                 
435                 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
436
437                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
438         }
439
440
441         /**
442          * Run the String createUpdateActionPolicy(String,String,Map<String,String>,List<String>,List<String>,List<String>,List<String>,String,String,String,Boolean,UUID) method test.
443          *
444          * @throws Exception
445          *
446          * @generatedBy CodePro at 6/3/16 2:03 PM
447          */
448         @Test
449         public void testCreateUpdateActionPolicy_Create()
450                 throws Exception {
451                 response.setResponseMessage("success");
452                 PolicyParameters policyParameters = new PolicyParameters();
453                 policyParameters.setPolicyClass(PolicyClass.Action); 
454                 policyParameters.setPolicyName("test.junittest");
455                 policyParameters.setPolicyDescription("testing");
456         Map<String, String> configAttributes = new HashMap<String, String>(); 
457         configAttributes.put("Template", "UpdateTemplate");
458         configAttributes.put("controller", "default"); 
459         configAttributes.put("SamPoll", "30");
460         configAttributes.put("value", "abcd"); 
461         Map<AttributeType, Map<String,String>> attributes = new HashMap<AttributeType, Map<String,String>>();
462         attributes.put(AttributeType.MATCHING, configAttributes);
463         policyParameters.setAttributes(attributes);
464         policyParameters.setActionPerformer("PDP");
465         policyParameters.setActionAttribute("test");
466
467                 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
468
469                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
470         }
471         
472         /**
473          * Run the String createUpdateActionPolicy(String,String,Map<String,String>,List<String>,List<String>,List<String>,List<String>,String,String,String,Boolean,UUID) method test.
474          *
475          * @throws Exception
476          *
477          * @generatedBy CodePro at 6/3/16 2:03 PM
478          */
479         @Test
480         public void testCreateUpdateActionPolicy_Update()
481                 throws Exception {
482                 response.setResponseMessage("success");
483                 PolicyParameters policyParameters = new PolicyParameters();
484                 policyParameters.setPolicyClass(PolicyClass.Action); 
485                 policyParameters.setPolicyName("test.junittest");
486                 policyParameters.setPolicyDescription("testing");
487         Map<String, String> configAttributes = new HashMap<String, String>(); 
488         configAttributes.put("Template", "UpdateTemplate");
489         configAttributes.put("controller", "default"); 
490         configAttributes.put("SamPoll", "30");
491         configAttributes.put("value", "abcd"); 
492         Map<AttributeType, Map<String,String>> attributes = new HashMap<AttributeType, Map<String,String>>();
493         attributes.put(AttributeType.MATCHING, configAttributes);
494         policyParameters.setAttributes(attributes);
495         policyParameters.setActionPerformer("PDP");
496         policyParameters.setActionAttribute("test");
497
498                 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
499
500                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
501         }
502
503
504         /**
505          * Run the String createUpdateBRMSParamPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID,Map<AttributeType,Map<String,String>>) method test.
506          *
507          * @throws Exception
508          *
509          * @generatedBy CodePro at 6/3/16 2:03 PM
510          */
511         @Test
512         public void testCreateUpdateBRMSParamPolicy_Create()
513                 throws Exception {
514                 response.setResponseMessage("success");
515                 PolicyParameters policyParameters = new PolicyParameters();
516                 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); 
517                 policyParameters.setPolicyName("test.testing");
518                 policyParameters.setPolicyDescription("testing");
519         Map<String, String> ruleAttributes = new HashMap<String, String>();
520         ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary. 
521         ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name.
522         ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us. 
523         ruleAttributes.put("value", "abcd"); // Template specific key and value set by us. 
524         Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
525         attributes.put(AttributeType.RULE, ruleAttributes);
526         policyParameters.setAttributes(attributes);
527         
528                 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
529                 
530                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
531         }
532         
533         /**
534          * Run the String createUpdateBRMSParamPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID,Map<AttributeType,Map<String,String>>) method test.
535          *
536          * @throws Exception
537          *
538          * @generatedBy CodePro at 6/3/16 2:03 PM
539          */
540         @Test
541         public void testCreateUpdateBRMSParamPolicy_Update()
542                 throws Exception {
543                 response.setResponseMessage("success");
544                 PolicyParameters policyParameters = new PolicyParameters();
545                 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); 
546                 policyParameters.setPolicyName("test.testing");
547                 policyParameters.setPolicyDescription("testing");
548         Map<String, String> ruleAttributes = new HashMap<String, String>();
549         ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary. 
550         ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name.
551         ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us. 
552         ruleAttributes.put("value", "abcd"); // Template specific key and value set by us. 
553         Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
554         attributes.put(AttributeType.RULE, ruleAttributes);
555         policyParameters.setAttributes(attributes);
556         
557                 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
558                 
559                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
560         }
561
562         /**
563          * Run the String createUpdateBRMSRawPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID) method test.
564          *
565          * @throws Exception
566          *
567          * @generatedBy CodePro at 6/3/16 2:03 PM
568          */
569         @Test
570         public void testCreateUpdateBRMSRawPolicy_Create()
571                 throws Exception {
572                 response.setResponseMessage("success");
573                 PolicyParameters policyParameters = new PolicyParameters();
574                 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM); 
575                 policyParameters.setPolicyName("test.testing");
576                 policyParameters.setPolicyDescription("testing");
577         Map<String, String> attrib= new HashMap<String,String>();
578         attrib.put("cpu","80");
579         attrib.put("memory", "50");
580         Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
581         attributes.put(AttributeType.RULE, attrib);
582         
583         policyParameters.setAttributes(attributes);
584         
585         File rawBodyFile = null;
586                 Path file = Paths.get("Test/test.Config_BRMS_Raw_TestBrmsPolicy.1.txt");
587                 rawBodyFile = file.toFile();
588                 
589                 policyParameters.setConfigBody(readFile(rawBodyFile.toString()));               
590         
591                 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
592                 
593                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
594         }
595         
596         /** 
597          * Run the PolicyChangeResponse createDictionaryItem(DictionaryParameters) method test.
598          * 
599          * @throws Exception
600          * 
601          */
602         @Test
603         public void testCreateDictionaryItem() throws Exception {
604                 response.setResponseMessage("success");
605                 DictionaryParameters parameters = new DictionaryParameters();
606                 
607                 parameters.setDictionaryType(DictionaryType.Common);
608                 parameters.setDictionary("Attribute");
609                 
610                 Map<String,String> fields = new HashMap<String,String>();
611                 fields.put("ATTRIBUTEID", "A5:");
612                 fields.put("DATATYPE", "user");
613                 fields.put("DESCRIPTION", "testing something");
614                 fields.put("ATTRIBUTEVALUE", "1,2,A,B");
615                 fields.put("PRIORITY", "High");
616                 Map<AttributeType, Map<String,String>> dictionaryFields = new HashMap<AttributeType, Map<String,String>>();
617                 dictionaryFields.put(AttributeType.DICTIONARY, fields);
618                 
619                 parameters.setDictionaryFields(dictionaryFields);
620
621                 PolicyChangeResponse result = fixture.createDictionaryItem(parameters);
622
623                 assertEquals(response.getResponseMessage(), result.getResponseMessage());
624         }
625         
626
627         /**
628          * Run the PolicyDecision decide(DecisionRequestParameters) method test.
629          *
630          * @throws Exception
631          *
632          * @generatedBy CodePro at 6/3/16 2:03 PM
633          */
634         @Test
635         public void testDecide()
636                 throws Exception {
637                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
638                 StdDecisionResponse response = new StdDecisionResponse();
639                 response.setDecision(PolicyDecision.PERMIT);
640                 
641                 DecisionRequestParameters decisionRequestParameters = new DecisionRequestParameters();
642                 decisionRequestParameters.setECOMPComponentName("testEcompName");
643                 Map<String,String> decisionAttributes = new HashMap<String,String>();
644                 decisionAttributes.put("key", "value");
645                 decisionRequestParameters.setDecisionAttributes(decisionAttributes);
646                 decisionRequestParameters.setRequestID(UUID.randomUUID());
647                 
648                 Mockito.when(mockEngine.decide(decisionRequestParameters)).thenReturn(response);
649                 DecisionResponse result = mockEngine.decide(decisionRequestParameters);
650
651                 assertNotNull(result);
652         }
653
654         /**
655          * Run the PolicyChangeResponse deletePolicy(DeletePolicyParameters) method test.
656          *
657          * @throws Exception
658          *
659          * @generatedBy CodePro at 6/3/16 2:03 PM
660          */
661         @Test
662         public void testDeletePolicy()
663                 throws Exception {
664                 response.setResponseMessage("success");
665                 DeletePolicyParameters parameters = new DeletePolicyParameters();
666                 parameters.setDeleteCondition(DeletePolicyCondition.ALL);
667                 parameters.setPolicyComponent("PAP");
668                 parameters.setPolicyName("testing.Config_junittest.1.xml");
669
670                 PolicyChangeResponse result = fixture.deletePolicy(parameters);
671
672                 assertNotNull(result);
673         }
674
675         /**
676          * Run the Collection<PolicyResponse> event(EventRequestParameters) method test.
677          *
678          * @throws Exception
679          *
680          * @generatedBy CodePro at 6/3/16 2:03 PM
681          */
682         @Test
683         public void testEvent()
684                 throws Exception {
685                 
686                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
687                 StdPolicyResponse response = new StdPolicyResponse();
688                 response.setPolicyResponseMessage("tested");
689                 Collection<PolicyResponse> mockResult = new HashSet<PolicyResponse>();
690                 mockResult.add(response);
691                 StdPolicyEngine mockEngine = Mockito.mock(StdPolicyEngine.class);
692                 
693                 Map<String,String> eventAttributes = new HashMap<String,String>();
694                 eventAttributes.put("key", "test");
695                 EventRequestParameters eventRequestParameters = new EventRequestParameters(eventAttributes, UUID.randomUUID());
696                 Mockito.when(mockEngine.event(eventRequestParameters)).thenReturn(mockResult);
697
698                 Collection<PolicyResponse> result = mockEngine.event(eventRequestParameters);
699                 
700                 assertEquals(result, mockResult);
701         }
702
703         /**
704          * Run the PDPNotification getNotification() method test.
705          *
706          * @throws Exception
707          *
708          * @generatedBy CodePro at 6/3/16 2:03 PM
709          */
710 /*      @Test
711         public void testGetNotification()
712                 throws Exception {
713                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
714
715                 PDPNotification result = fixture.getNotification();
716
717                 assertNull(result);
718         }*/
719
720         /**
721          * Run the NotificationHandler getNotificationHandler() method test.
722          *
723          * @throws Exception
724          *
725          * @generatedBy CodePro at 6/3/16 2:03 PM
726          */
727         @Test
728         public void testGetNotificationHandler()
729                 throws Exception {
730                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
731
732                 NotificationHandler result = fixture.getNotificationHandler();
733
734                 assertNull(result);
735         }
736
737         /**
738          * Run the String getPAPURL() method test.
739          *
740          * @throws Exception
741          *
742          * @generatedBy CodePro at 6/3/16 2:03 PM
743          */
744         @Test
745         public void testGetPAPURL()
746                 throws Exception {
747
748                 String result = StdPolicyEngine.getPAPURL();
749
750                 assertNotNull(result);
751         }
752
753         /**
754          * Run the String getPDPURL() method test.
755          *
756          * @throws Exception
757          *
758          * @generatedBy CodePro at 6/3/16 2:03 PM
759          */
760         @Test
761         public void testGetPDPURL()
762                 throws Exception {
763
764                 String result = StdPolicyEngine.getPDPURL();
765
766                 assertNotNull(result);
767         }
768
769         /**
770          * Run the NotificationScheme getScheme() method test.
771          *
772          * @throws Exception
773          *
774          * @generatedBy CodePro at 6/3/16 2:03 PM
775          */
776         @Test
777         public void testGetScheme()
778                 throws Exception {
779                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
780
781                 NotificationScheme result = fixture.getScheme();
782
783                 assertNull(result);
784         }
785
786         /**
787          * Run the boolean isJSONValid(String) method test.
788          *
789          * @throws Exception
790          *
791          * @generatedBy CodePro at 6/3/16 2:03 PM
792          */
793         @Test
794         public void testIsJSONValid()
795                 throws Exception {
796                 String data = "{\"test\": \"testing\"}";
797
798                 boolean result = StdPolicyEngine.isJSONValid(data);
799
800                 assertTrue(result);
801         }
802
803         /**
804          * Run the void notification(NotificationScheme,NotificationHandler) method test.
805          *
806          * @throws Exception
807          *
808          * @generatedBy CodePro at 6/3/16 2:03 PM
809          */
810 /*      @Test
811         public void testNotification()
812                 throws Exception {
813                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
814                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
815                 Handler handler = new Handler();
816
817                 fixture.notification(scheme, handler);
818
819         }
820 */
821         /**
822          * Run the PolicyChangeResponse policyEngineImport(ImportParameters) method test.
823          *
824          * @throws Exception
825          *
826          * @generatedBy CodePro at 6/3/16 2:03 PM
827          */
828         @Test
829         public void testPolicyEngineImport()
830                 throws Exception {
831                 response.setResponseMessage("success");
832                 ImportParameters importParameters = new ImportParameters();
833                 importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance");
834                 importParameters.setVersion("1607-2");
835                 importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip");
836                 importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE);
837                 
838                 PolicyChangeResponse result = fixture.policyEngineImport(importParameters);
839
840                 assertNotNull(result);
841                 
842         }
843
844         /**
845          * Run the Collection<PolicyConfig> policyName(String,UUID) method test.
846          *
847          * @throws Exception
848          *
849          * @generatedBy CodePro at 6/3/16 2:03 PM
850          */
851         @Test
852         public void testPolicyName()
853                 throws Exception {
854                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
855                 StdPolicyConfig config = new StdPolicyConfig();
856                 config.setPolicyName("testing");
857                 Collection<PolicyConfig> response = new HashSet<PolicyConfig>();
858                 response.add(config);
859                 String policyName = "test.testing";
860                 UUID requestID = UUID.randomUUID();
861                 
862                 Mockito.when(mockEngine.policyName(policyName, requestID)).thenReturn(response);
863                 Collection<PolicyConfig> result = mockEngine.policyName(policyName, requestID);
864
865                 assertEquals(result, response);
866         }
867
868         /**
869          * Run the PolicyChangeResponse pushPolicy(PushPolicyParameters) method test.
870          *
871          * @throws Exception
872          *
873          * @generatedBy CodePro at 6/3/16 2:03 PM
874          */
875         @Test
876         public void testPushPolicy()
877                 throws Exception {
878                 response.setResponseMessage("success");
879                 
880                 response.setResponseMessage("success");
881                 PolicyChangeResponse result = null;
882                 
883                 PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
884                 pushPolicyParameters.setPolicyName("test.testPolicy");
885                 pushPolicyParameters.setPdpGroup("default");
886                 pushPolicyParameters.setPolicyType("Base");
887                 
888                 try {
889                 
890                         Mockito.when(mockEngine.pushPolicy(pushPolicyParameters)).thenReturn(response);
891                         result = mockEngine.pushPolicy(pushPolicyParameters);
892                         
893                 } catch (Exception e) {
894                         logger.warn(e.getMessage());
895                 }
896                 assertEquals(result, response);
897         }
898
899         /**
900          * Run the void rotateList() method test.
901          *
902          * @throws Exception
903          *
904          * @generatedBy CodePro at 6/3/16 2:03 PM
905          */
906         @Test
907         public void testRotateList()
908                 throws Exception {
909
910                 StdPolicyEngine.rotateList();
911
912         }
913
914         /**
915          * Run the void setScheme(NotificationScheme) method test.
916          *
917          * @throws Exception
918          *
919          * @generatedBy CodePro at 6/3/16 2:03 PM
920          */
921         @Test
922         public void testSetScheme()
923                 throws Exception {
924                 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
925                 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
926
927                 fixture.setScheme(scheme);
928
929         }
930
931         /**
932          * Run the void stopNotification() method test.
933          *
934          * @throws Exception
935          *
936          * @generatedBy CodePro at 6/3/16 2:03 PM
937          */
938 /*      @Test
939         public void testStopNotification_1()
940                 throws Exception {
941                 Handler handler = new Handler();
942         
943                 Mockito.doNothing().when(mockStdPolicyEngine).notification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
944                 StdPolicyEngine fixture = new StdPolicyEngine("Test/config_pass.properties", NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
945                 
946                 //verify(mockStdPolicyEngine, times(1)).fixture("Test/config_pass.properties", NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
947
948                 fixture.stopNotification();
949         }*/
950
951         /**
952          * Run the String updateConfigFirewallPolicy(String,JsonObject,String,UUID) method test.
953          *
954          * @throws Exception
955          *
956          * @generatedBy CodePro at 6/3/16 2:03 PM
957          */
958         @Test
959         public void testUpdateConfigFirewallPolicy()
960                 throws Exception {
961                 response.setResponseMessage("success");
962                 String json= "{\"serviceTypeId\": \"/v0/firewall/pan\",\"configName\": \"rule1607\",\"deploymentOption\":{\"deployNow\": false},\"securityZoneId\": \"/v0/firewall/pan\",\"serviceGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"SList\"},{\"type\": \"REFERENCE\",\"name\": \"Syslog\"}]}, {\"name\": \"Syslog\",\"description\": \"NA\",\"type\": \"SERVICE\",\"transportProtocol\": \"udp\",\"appProtocol\": null,\"ports\": \"514\"}, {\"name\": \"SList\",\"description\": \"Service List\",\"type\": \"SERVICE\",\"transportProtocol\": \"tcp\",\"appProtocol\": null,\"ports\": \"8080\"}],\"addressGroups\": [{\"name\": \"1607Group\",\"description\": null,\"members\": [{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"},{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]},{\"name\": \"PL_CCE3\",\"description\": \"CCE Routers\",\"members\":[{\"type\": \"REFERENCE\",\"name\": \"10.11.12.13/14\"}]}],\"firewallRuleList\": [{\"position\": \"1\",\"ruleName\": \"1607Rule\",\"fromZones\": [\"Trusted\"],\"toZones\": [\"Untrusted\"],\"negateSource\": false,\"negateDestination\": false,\"sourceList\": [{\"type\": \"REFERENCE\",\"name\": \"PL_CCE3\"}, {\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"destinationList\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"sourceServices\": [],\"destServices\": [{\"type\": \"REFERENCE\",\"name\": \"1607Group\"}],\"action\": \"accept\",\"description\": \"Rule for 1607 templates\",\"enabled\": true,\"log\": true}]}";
963                 String policyName = "testing";
964                 JsonObject firewallJson = buildJSON(json);
965                 String policyScope = "test";
966                 UUID requestID = UUID.randomUUID();
967                 String riskLevel  = "";
968                 String riskType = "";
969                 String guard = "";
970                 String date = "";
971
972                 String result = fixture.updateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel,  riskType, guard,  date);
973
974                 assertNotNull(result);
975         }
976
977
978         /**
979          * Perform post-test clean-up.
980          *
981          * @throws Exception
982          *         if the clean-up fails for some reason
983          *
984          * @generatedBy CodePro at 6/3/16 2:03 PM
985          */
986         @After
987         public void tearDown()
988                 throws Exception {
989                 // Add additional tear down code here
990         }
991
992         /**
993          * Launch the test.
994          *
995          * @param args the command line arguments
996          *
997          * @generatedBy CodePro at 6/3/16 2:03 PM
998          */
999         public static void main(String[] args) {
1000                 new org.junit.runner.JUnitCore().run(StdPolicyEngineTest.class);
1001         }
1002 }