2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.std.test;
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;
28 import java.io.BufferedReader;
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;
40 import java.util.UUID;
42 import javax.json.Json;
43 import javax.json.JsonObject;
44 import javax.json.JsonReader;
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;
79 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
80 import org.openecomp.policy.common.logging.flexlogger.Logger;
83 * The class <code>StdPolicyEngineTest</code> contains tests for the class <code>{@link StdPolicyEngine}</code>.
85 * @generatedBy CodePro at 6/3/16 2:03 PM
86 * @version $Revision: 1.0 $
88 public class StdPolicyEngineTest {
90 private static final Logger logger = FlexLogger.getLogger(StdPolicyEngine.class);
92 private StdPolicyEngine fixture = null;
93 private StdPolicyEngine mockEngine = null;
95 PolicyChangeResponse result = null;
96 StdPolicyChangeResponse response = new StdPolicyChangeResponse();
97 PolicyParameters policyParameters = new PolicyParameters();
101 * Perform pre-test initialization.
104 * if the initialization fails for some reason
106 * @generatedBy CodePro at 6/3/16 2:03 PM
111 fixture = new StdPolicyEngine("Test/config_pass.properties");
114 mockEngine = Mockito.mock(StdPolicyEngine.class);
117 private static JsonObject buildJSON(String jsonString) {
118 JsonObject json = null;;
119 if (jsonString != null) {
120 StringReader in = null;
122 in = new StringReader(jsonString);
124 JsonReader jsonReader = Json.createReader(in);
125 json = jsonReader.readObject();
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));
135 StringBuilder stringBuilder = new StringBuilder();
136 String ls = System.getProperty("line.separator");
139 while( ( line = reader.readLine() ) != null ) {
140 stringBuilder.append( line );
141 stringBuilder.append( ls );
144 return stringBuilder.toString();
151 * Run the StdPolicyEngine(String) constructor test.
155 * @generatedBy CodePro at 6/3/16 2:03 PM
158 public void testStdPolicyEngine()
160 String propertyFilePath = "Test/config_pass.properties";
162 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath);
164 assertNotNull(result);
168 * Run the StdPolicyEngine(String) constructor test.
172 * @generatedBy CodePro at 6/3/16 2:03 PM
175 public void testStdPolicyEngine_2()
177 String propertyFilePath = "http";
179 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath);
185 * Run the StdPolicyEngine(String,NotificationScheme) constructor test.
189 * @generatedBy CodePro at 6/3/16 2:03 PM
192 public void testStdPolicyEngine_3()
194 String propertyFilePath = "Test/config_pass.properties";
195 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
197 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme);
199 assertNotNull(result);
203 * Run the StdPolicyEngine(String,NotificationScheme) constructor test.
207 * @generatedBy CodePro at 6/3/16 2:03 PM
210 public void testStdPolicyEngine_4()
212 String propertyFilePath = "http";
213 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
215 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme);
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
224 * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test.
228 * @generatedBy CodePro at 6/3/16 2:03 PM
231 public void testStdPolicyEngine_5()
233 String propertyFilePath = "Test/config_pass.properties";
234 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
235 NotificationHandler handler = new Handler();
237 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler);
243 * Run the StdPolicyEngine(String,NotificationScheme,NotificationHandler) constructor test.
247 * @generatedBy CodePro at 6/3/16 2:03 PM
250 public void testStdPolicyEngine_6()
252 String propertyFilePath = "http";
253 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
254 NotificationHandler handler = new Handler();
256 StdPolicyEngine result = new StdPolicyEngine(propertyFilePath, scheme, handler);
262 * Run the StdPolicyEngine(List<String>,List<String>,List<String>,List<String>,NotificationScheme,NotificationHandler,String) constructor test.
266 * @generatedBy CodePro at 6/3/16 2:03 PM
269 public void testStdPolicyEngine_8()
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";
279 StdPolicyEngine result = new StdPolicyEngine(configURL, configPapURL, encodingPAP, encoding, scheme, handler, clientAuth);
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
288 * Run the Collection<PolicyConfig> config(ConfigRequestParameters) method test.
292 * @generatedBy CodePro at 6/3/16 2:03 PM
295 public void testConfig()
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";
302 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
303 configRequestParameters.setPolicyName(".*");
304 Collection<PolicyConfig> result = fixture.config(configRequestParameters);
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());
317 * Run the Collection<String> listConfig(ConfigRequestParameters) method test.
323 public void testListConfig()
326 Collection<String> response = new ArrayList<String>();
327 response.add("Policy Name: listConfigTest");
329 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
330 configRequestParameters.setPolicyName(".*");
331 Collection<String> result = fixture.listConfig(configRequestParameters);
333 assertEquals(result, response);
337 * Run the String copyFile(String,String,StdPAPPolicy,String,UUID) method test.
341 * @generatedBy CodePro at 6/3/16 2:03 PM
344 public void testCopyFile()
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();
354 String result = fixture.copyFile(policyId, group, location, clientScope, requestID);
356 assertNotNull(result);
360 * Run the String copyPolicy(PDPPolicy,String,String,UUID) method test.
364 * @generatedBy CodePro at 6/3/16 2:03 PM
367 public void testCopyPolicy()
369 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
370 URI selectedURI = null;
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();
377 String result = fixture.copyPolicy(policy, group, policyType, requestID);
379 assertNotNull(result);
383 * Run the String createConfigFirewallPolicy(String,JsonObject,String,UUID) method test.
387 * @generatedBy CodePro at 6/3/16 2:03 PM
390 public void testCreateConfigFirewallPolicy()
393 response.setResponseMessage("success");
394 PolicyParameters policyParameters = new PolicyParameters();
395 policyParameters.setPolicyConfigType(PolicyConfigType.Firewall);
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");
401 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
403 assertEquals(response.getResponseMessage(), result.getResponseMessage());
407 * Run the String createConfigPolicy(String,String,String,String,Map<String,String>,String,String,String,UUID) method test.
411 * @generatedBy CodePro at 6/3/16 2:03 PM
414 public void testCreateConfigPolicy()
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");
435 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
437 assertEquals(response.getResponseMessage(), result.getResponseMessage());
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.
446 * @generatedBy CodePro at 6/3/16 2:03 PM
449 public void testCreateUpdateActionPolicy_Create()
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");
467 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
469 assertEquals(response.getResponseMessage(), result.getResponseMessage());
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.
477 * @generatedBy CodePro at 6/3/16 2:03 PM
480 public void testCreateUpdateActionPolicy_Update()
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");
498 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
500 assertEquals(response.getResponseMessage(), result.getResponseMessage());
505 * Run the String createUpdateBRMSParamPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID,Map<AttributeType,Map<String,String>>) method test.
509 * @generatedBy CodePro at 6/3/16 2:03 PM
512 public void testCreateUpdateBRMSParamPolicy_Create()
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);
528 PolicyChangeResponse result = fixture.createPolicy(policyParameters);
530 assertEquals(response.getResponseMessage(), result.getResponseMessage());
534 * Run the String createUpdateBRMSParamPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID,Map<AttributeType,Map<String,String>>) method test.
538 * @generatedBy CodePro at 6/3/16 2:03 PM
541 public void testCreateUpdateBRMSParamPolicy_Update()
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);
557 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
559 assertEquals(response.getResponseMessage(), result.getResponseMessage());
563 * Run the String createUpdateBRMSRawPolicy(String,String,Map<AttributeType,Map<String,String>>,String,String,Boolean,UUID) method test.
567 * @generatedBy CodePro at 6/3/16 2:03 PM
570 public void testCreateUpdateBRMSRawPolicy_Create()
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);
583 policyParameters.setAttributes(attributes);
585 File rawBodyFile = null;
586 Path file = Paths.get("Test/test.Config_BRMS_Raw_TestBrmsPolicy.1.txt");
587 rawBodyFile = file.toFile();
589 policyParameters.setConfigBody(readFile(rawBodyFile.toString()));
591 PolicyChangeResponse result = fixture.updatePolicy(policyParameters);
593 assertEquals(response.getResponseMessage(), result.getResponseMessage());
597 * Run the PolicyChangeResponse createDictionaryItem(DictionaryParameters) method test.
603 public void testCreateDictionaryItem() throws Exception {
604 response.setResponseMessage("success");
605 DictionaryParameters parameters = new DictionaryParameters();
607 parameters.setDictionaryType(DictionaryType.Common);
608 parameters.setDictionary("Attribute");
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);
619 parameters.setDictionaryFields(dictionaryFields);
621 PolicyChangeResponse result = fixture.createDictionaryItem(parameters);
623 assertEquals(response.getResponseMessage(), result.getResponseMessage());
628 * Run the PolicyDecision decide(DecisionRequestParameters) method test.
632 * @generatedBy CodePro at 6/3/16 2:03 PM
635 public void testDecide()
637 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
638 StdDecisionResponse response = new StdDecisionResponse();
639 response.setDecision(PolicyDecision.PERMIT);
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());
648 Mockito.when(mockEngine.decide(decisionRequestParameters)).thenReturn(response);
649 DecisionResponse result = mockEngine.decide(decisionRequestParameters);
651 assertNotNull(result);
655 * Run the PolicyChangeResponse deletePolicy(DeletePolicyParameters) method test.
659 * @generatedBy CodePro at 6/3/16 2:03 PM
662 public void testDeletePolicy()
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");
670 PolicyChangeResponse result = fixture.deletePolicy(parameters);
672 assertNotNull(result);
676 * Run the Collection<PolicyResponse> event(EventRequestParameters) method test.
680 * @generatedBy CodePro at 6/3/16 2:03 PM
683 public void testEvent()
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);
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);
698 Collection<PolicyResponse> result = mockEngine.event(eventRequestParameters);
700 assertEquals(result, mockResult);
704 * Run the PDPNotification getNotification() method test.
708 * @generatedBy CodePro at 6/3/16 2:03 PM
711 public void testGetNotification()
713 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
715 PDPNotification result = fixture.getNotification();
721 * Run the NotificationHandler getNotificationHandler() method test.
725 * @generatedBy CodePro at 6/3/16 2:03 PM
728 public void testGetNotificationHandler()
730 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
732 NotificationHandler result = fixture.getNotificationHandler();
738 * Run the String getPAPURL() method test.
742 * @generatedBy CodePro at 6/3/16 2:03 PM
745 public void testGetPAPURL()
748 String result = StdPolicyEngine.getPAPURL();
750 assertNotNull(result);
754 * Run the String getPDPURL() method test.
758 * @generatedBy CodePro at 6/3/16 2:03 PM
761 public void testGetPDPURL()
764 String result = StdPolicyEngine.getPDPURL();
766 assertNotNull(result);
770 * Run the NotificationScheme getScheme() method test.
774 * @generatedBy CodePro at 6/3/16 2:03 PM
777 public void testGetScheme()
779 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
781 NotificationScheme result = fixture.getScheme();
787 * Run the boolean isJSONValid(String) method test.
791 * @generatedBy CodePro at 6/3/16 2:03 PM
794 public void testIsJSONValid()
796 String data = "{\"test\": \"testing\"}";
798 boolean result = StdPolicyEngine.isJSONValid(data);
804 * Run the void notification(NotificationScheme,NotificationHandler) method test.
808 * @generatedBy CodePro at 6/3/16 2:03 PM
811 public void testNotification()
813 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
814 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
815 Handler handler = new Handler();
817 fixture.notification(scheme, handler);
822 * Run the PolicyChangeResponse policyEngineImport(ImportParameters) method test.
826 * @generatedBy CodePro at 6/3/16 2:03 PM
829 public void testPolicyEngineImport()
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);
838 PolicyChangeResponse result = fixture.policyEngineImport(importParameters);
840 assertNotNull(result);
845 * Run the Collection<PolicyConfig> policyName(String,UUID) method test.
849 * @generatedBy CodePro at 6/3/16 2:03 PM
852 public void testPolicyName()
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();
862 Mockito.when(mockEngine.policyName(policyName, requestID)).thenReturn(response);
863 Collection<PolicyConfig> result = mockEngine.policyName(policyName, requestID);
865 assertEquals(result, response);
869 * Run the PolicyChangeResponse pushPolicy(PushPolicyParameters) method test.
873 * @generatedBy CodePro at 6/3/16 2:03 PM
876 public void testPushPolicy()
878 response.setResponseMessage("success");
880 response.setResponseMessage("success");
881 PolicyChangeResponse result = null;
883 PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
884 pushPolicyParameters.setPolicyName("test.testPolicy");
885 pushPolicyParameters.setPdpGroup("default");
886 pushPolicyParameters.setPolicyType("Base");
890 Mockito.when(mockEngine.pushPolicy(pushPolicyParameters)).thenReturn(response);
891 result = mockEngine.pushPolicy(pushPolicyParameters);
893 } catch (Exception e) {
894 logger.warn(e.getMessage());
896 assertEquals(result, response);
900 * Run the void rotateList() method test.
904 * @generatedBy CodePro at 6/3/16 2:03 PM
907 public void testRotateList()
910 StdPolicyEngine.rotateList();
915 * Run the void setScheme(NotificationScheme) method test.
919 * @generatedBy CodePro at 6/3/16 2:03 PM
922 public void testSetScheme()
924 //StdPolicyEngine fixture = new StdPolicyEngine("http", NotificationScheme.AUTO_ALL_NOTIFICATIONS, (NotificationHandler) null);
925 NotificationScheme scheme = NotificationScheme.AUTO_ALL_NOTIFICATIONS;
927 fixture.setScheme(scheme);
932 * Run the void stopNotification() method test.
936 * @generatedBy CodePro at 6/3/16 2:03 PM
939 public void testStopNotification_1()
941 Handler handler = new Handler();
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);
946 //verify(mockStdPolicyEngine, times(1)).fixture("Test/config_pass.properties", NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
948 fixture.stopNotification();
952 * Run the String updateConfigFirewallPolicy(String,JsonObject,String,UUID) method test.
956 * @generatedBy CodePro at 6/3/16 2:03 PM
959 public void testUpdateConfigFirewallPolicy()
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 = "";
972 String result = fixture.updateConfigFirewallPolicy(policyName, firewallJson, policyScope, requestID,riskLevel, riskType, guard, date);
974 assertNotNull(result);
979 * Perform post-test clean-up.
982 * if the clean-up fails for some reason
984 * @generatedBy CodePro at 6/3/16 2:03 PM
987 public void tearDown()
989 // Add additional tear down code here
995 * @param args the command line arguments
997 * @generatedBy CodePro at 6/3/16 2:03 PM
999 public static void main(String[] args) {
1000 new org.junit.runner.JUnitCore().run(StdPolicyEngineTest.class);