Fixes for sonar critical issues
[policy/engine.git] / PolicyEngineAPI / src / test / java / org / onap / policy / test / PolicyEngineInterfaceTest.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.onap.policy.test;
22
23 import java.io.StringReader;
24 import java.net.HttpURLConnection;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.Map;
28 import java.util.UUID;
29
30 import javax.json.Json;
31 import javax.json.JsonObject;
32 import javax.json.JsonReader;
33
34 import org.mockito.Mockito;
35 import org.onap.policy.api.AttributeType;
36 import org.onap.policy.api.ConfigRequestParameters;
37 import org.onap.policy.api.DecisionRequestParameters;
38 import org.onap.policy.api.DecisionResponse;
39 import org.onap.policy.api.DeletePolicyCondition;
40 import org.onap.policy.api.DeletePolicyParameters;
41 import org.onap.policy.api.EventRequestParameters;
42 import org.onap.policy.api.ImportParameters;
43 import org.onap.policy.api.ImportParameters.IMPORT_TYPE;
44 import org.onap.policy.api.NotificationHandler;
45 import org.onap.policy.api.NotificationScheme;
46 import org.onap.policy.api.PDPNotification;
47 import org.onap.policy.api.PolicyChangeResponse;
48 import org.onap.policy.api.PolicyClass;
49 import org.onap.policy.api.PolicyConfig;
50 import org.onap.policy.api.PolicyConfigException;
51 import org.onap.policy.api.PolicyDecisionException;
52 import org.onap.policy.api.PolicyEngine;
53 import org.onap.policy.api.PolicyEngineException;
54 import org.onap.policy.api.PolicyEventException;
55 import org.onap.policy.api.PolicyParameters;
56 import org.onap.policy.api.PolicyResponse;
57 import org.onap.policy.api.PushPolicyParameters;
58 import org.onap.policy.common.logging.flexlogger.FlexLogger;
59 import org.onap.policy.common.logging.flexlogger.Logger;
60 import org.onap.policy.std.StdPDPNotification;
61 import org.onap.policy.std.StdPolicyChangeResponse;
62 import org.onap.policy.std.StdPolicyResponse;
63
64 import junit.framework.TestCase;
65
66 /**
67  * The class <code>PolicyEngineInterfaceTest</code> contains tests for the
68  * class {@link <code>PolicyEngine</code>}
69  *
70  * @pattern JUnit Test Case
71  *
72  * @generatedBy CodePro at 5/27/16 10:33 AM
73  *
74  *
75  * @version $Revision$
76  */
77 public class PolicyEngineInterfaceTest extends TestCase {
78
79         private static final Logger logger = FlexLogger.getLogger(PolicyEngineInterfaceTest.class);
80
81         private PolicyEngine policyEngine = null;
82         private PolicyEngine mockPolicyEngine = null;
83         private Collection<PolicyConfig> policyConfig = null;
84         private UUID requestID = UUID.randomUUID();
85
86
87         PolicyChangeResponse result = null;
88         StdPolicyChangeResponse response = new StdPolicyChangeResponse();
89         
90         
91         /**
92          * Construct new test instance
93          *
94          * @param name the test name
95          */
96         public PolicyEngineInterfaceTest(String name) {
97                 super(name);
98         }
99
100         /**
101          * Perform pre-test initialization
102          *
103          * @throws Exception
104          *
105          * @see TestCase#setUp()
106          */
107         public void setUp() throws Exception {
108                 try {
109                         policyEngine = new PolicyEngine("Test/config_pass.properties");
110                 } catch (PolicyEngineException e) {
111                         logger.error(e.getMessage());
112                         fail("PolicyEngine Instantiation Error" + e);
113                 }
114                 logger.info("Loaded.. PolicyEngine");
115                 
116                 mockPolicyEngine = Mockito.mock(PolicyEngine.class);
117                 HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
118                 Mockito.when(conn.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
119
120         }
121
122         /**
123          * Perform post-test clean up
124          *
125          * @throws Exception
126          *
127          * @see TestCase#tearDown()
128          */
129         public void tearDown() throws Exception {
130                 super.tearDown();
131                 // Add additional tear down code here
132         }
133
134         /**
135          * Run the Collection<PolicyConfig> getConfigByPolicyName(String) method
136          * test
137          */
138         @SuppressWarnings("deprecation")
139         public void testGetConfigByPolicyName() {
140                 String policyName = null;
141                 try{
142                         policyConfig = policyEngine.getConfigByPolicyName(policyName);
143                 } catch (PolicyConfigException e){
144                         logger.warn(e.getMessage());
145                 }
146                 assertNull(policyConfig);
147         }
148         
149         @SuppressWarnings("deprecation")
150         public void testGetConfigByPolicyName2() {
151                 String policyName = null;
152                 
153                 try{
154                         policyConfig = policyEngine.getConfigByPolicyName(policyName, requestID);
155                 } catch (PolicyConfigException e){
156                         logger.warn(e.getMessage());
157                 }
158                 assertNull(policyConfig);
159         }
160
161         /**
162          * Run the Collection<PolicyConfig> getConfig(String) method test
163          */
164         @SuppressWarnings("deprecation")
165         public void testGetConfig() {
166                 String onapName = null;
167                 
168                 try{
169                         policyConfig = policyEngine.getConfig(onapName);
170                 } catch (PolicyConfigException e){
171                         logger.warn(e.getMessage());
172                 }
173                 assertNull(policyConfig);
174         }
175         
176         @SuppressWarnings("deprecation")
177         public void testGetConfig2() {
178                 String onapName = null;
179
180                 try{
181                         policyConfig = policyEngine.getConfig(onapName,requestID);
182                 } catch (PolicyConfigException e){
183                         logger.warn(e.getMessage());
184                 }
185                 assertNull(policyConfig);
186         }
187
188         
189         @SuppressWarnings("deprecation")
190         public void testGetConfig3() {
191                 String onapName = null;
192                 String configName = null;
193
194                 try{
195                         policyConfig = policyEngine.getConfig(onapName,configName,requestID);
196                 } catch (PolicyConfigException e){
197                         logger.warn(e.getMessage());
198                 }
199                 assertNull(policyConfig);
200         }
201
202         @SuppressWarnings("deprecation")
203         public void testGetConfig4() {
204                 String onapName = null;
205                 String configName = null;
206                 Map<String,String> configAttributes = null;
207                 
208                 try{
209                         policyConfig = policyEngine.getConfig(onapName,configName,configAttributes);
210                 } catch (PolicyConfigException e){
211                         logger.warn(e.getMessage());
212                 }
213                 assertNull(policyConfig);
214         }
215         
216         @SuppressWarnings("deprecation")
217         public void testGetConfig5() {
218                 String onapName = null;
219                 String configName = null;
220                 Map<String,String> configAttributes = null;
221                 
222                 try{
223                         policyConfig = policyEngine.getConfig(onapName,configName,configAttributes,requestID);
224                 } catch (PolicyConfigException e){
225                         logger.warn(e.getMessage());
226                 }
227                 assertNull(policyConfig);
228         }
229         
230         public void testGetConfig6() {
231                 ConfigRequestParameters parameters = new ConfigRequestParameters();
232                 
233                 try{
234                         policyConfig = policyEngine.getConfig(parameters);
235                 } catch (PolicyConfigException e){
236                         logger.warn(e.getMessage());
237                 }
238                 assertNull(policyConfig);
239         }
240
241
242         /**
243          * Run the Collection<PolicyResponse> sendEvent(Map<String,String>) method
244          * test
245          */
246         @SuppressWarnings("deprecation")
247         public void testSendEvent()
248         {
249                 Collection<PolicyResponse> result = null;
250                 Collection<StdPolicyResponse> response = null;
251                 Map<String,String> eventAttributes = null;
252                 
253                 try {
254                         Mockito.when(mockPolicyEngine.sendEvent(eventAttributes)).thenReturn(result);
255                         result = mockPolicyEngine.sendEvent(eventAttributes);
256                 } catch (PolicyEventException e) {
257                         logger.error("Exception Occured"+e);
258                 }
259                 
260                 
261                 assertEquals(result,response);
262         
263         }
264         
265         @SuppressWarnings("deprecation")
266         public void testSendEvent2()
267         {
268                 Collection<PolicyResponse> result = null;
269                 Collection<StdPolicyResponse> response = null;
270                 Map<String,String> eventAttributes = null;
271                 
272                 try {
273                         Mockito.when(mockPolicyEngine.sendEvent(eventAttributes,requestID)).thenReturn(result);
274                         result = mockPolicyEngine.sendEvent(eventAttributes,requestID);
275                 } catch (PolicyEventException e) {
276                         logger.error("Exception Occured"+e);
277                 }
278                 
279                 
280                 assertEquals(result,response);
281         
282         }
283         
284         public void testSendEvent3()
285         {
286                 Collection<PolicyResponse> result = null;
287                 Collection<StdPolicyResponse> response = null;
288                 EventRequestParameters parameters = new EventRequestParameters();
289                 
290                 try {
291                         Mockito.when(mockPolicyEngine.sendEvent(parameters)).thenReturn(result);
292                         result = mockPolicyEngine.sendEvent(parameters);
293                 } catch (PolicyEventException e) {
294                         logger.error("Exception Occured"+e);
295                 }
296                 
297                 assertEquals(result,response);
298         
299         }
300         
301         
302         
303         /**
304          * Run the PolicyDecision getDecision(String, Map<String,String>) method
305          * test
306          */
307         @SuppressWarnings("deprecation")
308         public void testGetDecision()
309         {
310                 String onapComponentName = null;
311                 Map<String,String> decisionAttributes = null;
312                 
313                 DecisionResponse result = null;
314                 
315                 try {
316                         Mockito.when(mockPolicyEngine.getDecision(onapComponentName,decisionAttributes)).thenReturn(null);
317                         result = mockPolicyEngine.getDecision(onapComponentName,decisionAttributes);
318                 } catch (PolicyDecisionException e) {
319                         logger.error("Exception Occured"+e);
320                 }
321                 
322                 assertEquals(result,null);
323         }
324         
325         @SuppressWarnings("deprecation")
326         public void testGetDecision2()
327         {
328                 String onapComponentName = null;
329                 Map<String,String> decisionAttributes = null;
330                 
331                 DecisionResponse result = null;
332                 
333                 try {   
334                         Mockito.when(mockPolicyEngine.getDecision(onapComponentName,decisionAttributes,requestID)).thenReturn(null);
335                         result = mockPolicyEngine.getDecision(onapComponentName,decisionAttributes);
336                 } catch (PolicyDecisionException e) {
337                         logger.error("Exception Occured"+e);
338                 }
339                 
340                 assertEquals(result,null);
341         }
342         
343         public void testGetDecision3()
344         {
345                 DecisionRequestParameters parameters = new DecisionRequestParameters();
346                 DecisionResponse result = null;
347                 
348                 try {
349                         Mockito.when(mockPolicyEngine.getDecision(parameters)).thenReturn(null);
350                         result = mockPolicyEngine.getDecision(parameters);
351                 } catch (PolicyDecisionException e) {
352                         logger.error("Exception Occured"+e);
353                 }
354                 
355                 assertEquals(result,null);
356         }
357         
358         /**
359          * Run the void setNotification(NotificationScheme, NotificationHandler)
360          * method test
361          */
362         public void testSetNotification() {
363                 // add test code here
364                 
365                 NotificationScheme scheme = null;
366                 NotificationHandler handler = null;
367
368                 Mockito.doNothing().when(mockPolicyEngine).setNotification(scheme, handler);
369                 mockPolicyEngine.setNotification(scheme, handler);
370                 //assertTrue(true);
371         }
372
373         /**
374          * Run the void clearNotification() method test
375          */
376         public void testClearNotification() {
377                 // add test code here
378
379                 Mockito.doNothing().when(mockPolicyEngine).clearNotification();
380                 mockPolicyEngine.clearNotification();
381                 //assertTrue(true);
382         }
383
384         /**
385          * Run the void setScheme(NotificationScheme) method test
386          */
387         public void testSetScheme() {
388                 NotificationScheme scheme = null;
389                 
390                 Mockito.doNothing().when(mockPolicyEngine).setScheme(scheme);
391                 mockPolicyEngine.setScheme(scheme);
392                 //assertTrue(true);
393         }
394
395         /**
396          * Run the PDPNotification getNotification() method test
397          */
398         public void testGetNotification() {
399                 PDPNotification result = null;
400                 StdPDPNotification response = null;
401                 Mockito.when(mockPolicyEngine.getNotification()).thenReturn(response);
402                 result = mockPolicyEngine.getNotification();
403                 
404                 assertEquals(result,response);
405         }
406
407         /**
408          * Run the String createConfigPolicy(String, String, String, String,
409          * Map<String,String>, String, String, String, UUID) method test
410          */
411         @SuppressWarnings("deprecation")
412         public void testCreateConfigPolicy()
413         {
414                 String response = "success";
415                 String result = null;
416                 try {
417                 
418                         Mockito.when(mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response);
419                         result = mockPolicyEngine.createConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null);
420
421                 } catch (Exception e) {
422                         logger.warn(e.getMessage());
423                 }
424                 assertEquals(result, response);
425         }
426         
427         /**
428          * Run the String updateConfigPolicy(String, String, String, String,
429          * Map<String,String>, String, String, String, UUID) method test
430          */
431         @SuppressWarnings("deprecation")
432         public void testUpdateConfigPolicy()
433         {
434                 String response = "success";
435                 String result = null;
436                 try {
437                 
438                         Mockito.when(mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null)).thenReturn(response);
439                         result = mockPolicyEngine.updateConfigPolicy("testPolicy","test","test","testConfig",null,"OTHER","test","test",null, null, null, null, null);
440
441                 } catch (Exception e) {
442                         logger.warn(e.getMessage());
443                 }
444                 assertEquals(result, response);
445         }
446         
447         /**
448          * Run the String createConfigFirewallPolicy(String, JsonObject, String,
449          * UUID) method test
450          */
451         @SuppressWarnings("deprecation")
452         public void testCreateConfigFirewallPolicy() {
453                 String response = "success";
454                 String result = null;
455                 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\":\"SUBNET\",\"value\":\"10.11.12.13/14\"},{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]},{\"name\":\"PL_CCE3\",\"description\":\"CCE Routers\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"1607Rule\",\"fromZones\":[\"Trusted\"],\"toZones\":[\"Untrusted\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"value\":\"PL_CCE3\"},{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"1607Group\"}],\"action\":\"accept\",\"description\":\"Rule for 1607 templates\",\"enabled\":true,\"log\":true}]}";
456                 JsonObject jsonObj = buildJSON(json);
457                 try {
458                 
459                         Mockito.when(mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response);
460                         result = mockPolicyEngine.createConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null);
461
462                 } catch (Exception e) {
463                         logger.warn(e.getMessage());
464                 }
465                 assertEquals(result, response);
466         }
467
468         /**
469          * Run the String updateConfigFirewallPolicy(String, JsonObject, String,
470          * UUID) method test
471          */
472         @SuppressWarnings("deprecation")
473         public void testUpdateConfigFirewallPolicy() {
474                 String response = "success";
475                 String result = null;
476                 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\":\"SUBNET\",\"value\":\"10.11.12.13/14\"},{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]},{\"name\":\"PL_CCE3\",\"description\":\"CCE Routers\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"10.11.12.13/14\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"1607Rule\",\"fromZones\":[\"Trusted\"],\"toZones\":[\"Untrusted\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"value\":\"PL_CCE3\"},{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"value\":\"1607Group\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"1607Group\"}],\"action\":\"accept\",\"description\":\"Rule for 1607 templates\",\"enabled\":true,\"log\":true}]}";
477                 JsonObject jsonObj = buildJSON(json);
478                 try {
479                 
480                         Mockito.when(mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null)).thenReturn(response);
481                         result = mockPolicyEngine.updateConfigFirewallPolicy("testPolicy",jsonObj, "test", null, null, null, null, null);
482
483                 } catch (Exception e) {
484                         logger.warn(e.getMessage());
485                 }
486                 assertEquals(result, response);
487         }
488
489         /**
490          * Run the PolicyChangeResponse createPolicy(PolicyParameters) method test
491          */
492         public void testCreatePolicy() {
493                 response.setResponseMessage("success");
494                 PolicyChangeResponse result = null;
495                 PolicyParameters policyParameters = new PolicyParameters();
496
497         policyParameters.setPolicyClass(PolicyClass.Action); //required
498         policyParameters.setPolicyName("test.junitTest"); //required
499         policyParameters.setPolicyDescription("testing");  //optional
500         
501         //Set the Component Attributes... These are Optional
502         Map<String, String> configAttributes = new HashMap<String, String>(); 
503         configAttributes.put("test", "testing");
504         
505         Map<AttributeType, Map<String,String>> attributes = new HashMap<AttributeType, Map<String,String>>();
506         attributes.put(AttributeType.MATCHING, configAttributes);
507         policyParameters.setAttributes(attributes);
508                 
509         policyParameters.setActionPerformer("PEP");
510         policyParameters.setActionAttribute("testing");
511         policyParameters.setRequestID(UUID.randomUUID());
512                 
513                 try {
514                         
515                         //stdPolicyEngine = Mockito.mock(StdPolicyEngine.class);
516                         //Mockito.when(stdPolicyEngine.callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Action"}, null, "Action")).thenReturn(callPapResponse);
517                         Mockito.when(mockPolicyEngine.createPolicy(policyParameters)).thenReturn(response);
518                         result = mockPolicyEngine.createPolicy(policyParameters);
519                         
520                 } catch (Exception e) {
521                         logger.warn(e.getMessage());
522                         logger.error("Exception Occured"+e);
523                 }
524                 assertEquals(result, response);
525         }
526
527         /**
528          * Run the PolicyChangeResponse updatePolicy(PolicyParameters) method test
529          */
530         public void testUpdatePolicy() {
531                 response.setResponseMessage("success");
532                 PolicyChangeResponse result = null;
533                 PolicyParameters policyParameters = new PolicyParameters();
534
535         policyParameters.setPolicyClass(PolicyClass.Action); //required
536         policyParameters.setPolicyName("test.junitTest"); //required
537         policyParameters.setPolicyDescription("testing");  //optional
538         
539         //Set the Component Attributes... These are Optional
540         Map<String, String> configAttributes = new HashMap<String, String>(); 
541         configAttributes.put("test", "testing");
542         
543         Map<AttributeType, Map<String,String>> attributes = new HashMap<AttributeType, Map<String,String>>();
544         attributes.put(AttributeType.MATCHING, configAttributes);
545         policyParameters.setAttributes(attributes);
546                 
547         policyParameters.setActionPerformer("PEP");
548         policyParameters.setActionAttribute("testing");
549         policyParameters.setRequestID(UUID.randomUUID());
550                 
551                 try {
552                 
553                         Mockito.when(mockPolicyEngine.updatePolicy(policyParameters)).thenReturn(response);
554                         result = mockPolicyEngine.updatePolicy(policyParameters);
555                         
556                 } catch (Exception e) {
557                         logger.warn(e.getMessage());
558                 }
559                 assertEquals(result, response);
560         }
561
562         /**
563          * Run the String pushPolicy(String, String, String, String, UUID) method
564          * test
565          */
566         @SuppressWarnings("deprecation")
567         public void testPushPolicy() {
568                 String response = "Success";
569                 String result = null;
570                 try {
571                         
572                         Mockito.when(mockPolicyEngine.pushPolicy("testing","test","Base","default",requestID)).thenReturn(response);
573                         result = mockPolicyEngine.pushPolicy("testing","test","Base","default",requestID);
574                         
575                 } catch (Exception e) {
576                         logger.warn(e.getMessage());
577                 }
578                 
579                 assertEquals(result, response);
580         }
581
582         public void testPushPolicy2() {
583                 PushPolicyParameters policyParameters = new PushPolicyParameters();
584                 PolicyChangeResponse result = null;
585                 
586                 //String policyScope = null;
587                 policyParameters.setPolicyName("test.junitTest");
588                 policyParameters.setPolicyType("Action");
589                 policyParameters.setPdpGroup("Default");
590                 
591                 try {
592                         
593                         Mockito.when(mockPolicyEngine.pushPolicy(policyParameters)).thenReturn(response);
594                         result = mockPolicyEngine.pushPolicy(policyParameters);
595                         
596                 } catch (Exception e) {
597                         logger.warn(e.getMessage());
598                 }
599                 
600                 assertEquals(result, response);
601         }
602
603         /**
604          * Run the PolicyChangeResponse deletePolicy(DeletePolicyParameters) method
605          * test
606          */
607         public void testDeletePolicy() {
608                 DeletePolicyParameters policyParameters = new DeletePolicyParameters();
609                 PolicyChangeResponse result = null;
610                 
611                 //String policyScope = null;
612                 policyParameters.setPolicyName("test.junitTest.1.xml");
613                 policyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
614                 policyParameters.setPolicyComponent("PAP");
615                 policyParameters.setPdpGroup("Default");
616                 
617                 try {
618                         
619                         Mockito.when(mockPolicyEngine.deletePolicy(policyParameters)).thenReturn(response);
620                         result = mockPolicyEngine.deletePolicy(policyParameters);
621                         
622                 } catch (Exception e) {
623                         logger.warn(e.getMessage());
624                 }
625                 
626                 assertEquals(result, response);
627         }
628
629         /**
630          * Run the PolicyChangeResponse policyEngineImport(ImportParameters) method
631          * test
632          */
633         public void testPolicyEngineImport() {
634                 ImportParameters importParameters = new ImportParameters();
635                 PolicyChangeResponse result = null;
636                 
637         importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip");
638         importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance");
639                 
640         importParameters.setRequestID(UUID.randomUUID());
641         importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE);
642         importParameters.setVersion("1607-2");
643
644                 
645                 try {
646                         
647                         Mockito.when(mockPolicyEngine.policyEngineImport(importParameters)).thenReturn(response);
648                         result = mockPolicyEngine.policyEngineImport(importParameters);
649                         
650                 } catch (Exception e) {
651                         logger.warn(e.getMessage());
652                 }
653                 
654                 assertEquals(result, response);
655         }
656         
657     private static JsonObject buildJSON(String jsonString) {
658         JsonObject json = null;;
659         if (jsonString != null) {
660             StringReader in = null;
661              
662             in = new StringReader(jsonString);
663              
664             JsonReader jsonReader = Json.createReader(in);
665             json = jsonReader.readObject();        
666         } 
667         
668         return json;
669     }
670 }