[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / admin / PolicyManagerServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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 package org.onap.policy.admin;
21
22 import static org.junit.Assert.fail;
23
24 import java.io.BufferedReader;
25 import java.io.File;
26 import java.io.StringReader;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31 import javax.servlet.ServletConfig;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34
35 import org.apache.commons.io.IOUtils;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.controller.CreateDcaeMicroServiceController;
42 import org.onap.policy.controller.PolicyController;
43 import org.onap.policy.model.Roles;
44 import org.onap.policy.rest.dao.CommonClassDao;
45 import org.onap.policy.rest.jpa.ActionBodyEntity;
46 import org.onap.policy.rest.jpa.ConfigurationDataEntity;
47 import org.onap.policy.rest.jpa.GroupPolicyScopeList;
48 import org.onap.policy.rest.jpa.PolicyEditorScopes;
49 import org.onap.policy.rest.jpa.PolicyEntity;
50 import org.onap.policy.rest.jpa.PolicyVersion;
51 import org.onap.policy.rest.jpa.UserInfo;
52
53 public class PolicyManagerServletTest extends Mockito{
54         
55         private static Logger logger = FlexLogger.getLogger(PolicyManagerServletTest.class);
56         private List<String> headers = new ArrayList<String>();
57
58         private static List<Object> rolesdata;
59         private static List<Object> basePolicyData;
60         private static List<Object> policyEditorScopes;
61         private static List<Object> policyVersion;
62         private static CommonClassDao commonClassDao;
63         
64         @Before
65         public void setUp() throws Exception{
66                 logger.info("setUp: Entering");
67                 UserInfo userinfo = new UserInfo();
68                 userinfo.setUserLoginId("Test");
69                 userinfo.setUserName("Test");
70                 //Roles Data
71         rolesdata = new ArrayList<>();
72         Roles roles = new Roles();
73         roles.setLoginId("Test");
74         roles.setRole("super-admin");
75         Roles roles1 = new Roles();
76         roles1.setLoginId("Test");
77         roles1.setRole("admin");
78         roles1.setScope("['com','Test']");
79         rolesdata.add(roles);
80         rolesdata.add(roles1);
81         
82         //PolicyEntity Data
83         basePolicyData = new ArrayList<>();
84         String policyContent = "";
85         try {
86                         ClassLoader classLoader = getClass().getClassLoader();
87                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml"));
88                 } catch (Exception e1) {
89                         logger.error("Exception Occured"+e1);
90                 }
91         PolicyEntity entity = new PolicyEntity();
92         entity.setPolicyName("Config_SampleTest.1.xml");
93         entity.setPolicyData(policyContent);
94         entity.setScope("com");
95         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
96         configurationEntity.setConfigBody("Sample Test");
97         configurationEntity.setConfigType("OTHER");
98         configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt");
99         configurationEntity.setDescription("test");
100         entity.setConfigurationData(configurationEntity);
101         basePolicyData.add(entity);
102         
103         //PolicyEditorScopes data
104         policyEditorScopes = new ArrayList<>();
105         PolicyEditorScopes scopes = new PolicyEditorScopes();
106         scopes.setScopeName("com");
107         scopes.setUserCreatedBy(userinfo);
108         scopes.setUserModifiedBy(userinfo);
109         PolicyEditorScopes scopes1 = new PolicyEditorScopes();
110         scopes1.setScopeName("com\\Test");
111         scopes1.setUserCreatedBy(userinfo);
112         scopes1.setUserModifiedBy(userinfo);
113         policyEditorScopes.add(scopes);
114         policyEditorScopes.add(scopes1);
115         
116         //PolicyVersion data
117         policyVersion = new ArrayList<>();
118         PolicyVersion policy = new PolicyVersion();
119         policy.setPolicyName("com\\Config_SampleTest1206");
120         policy.setActiveVersion(1);
121         policy.setHigherVersion(1);
122         policy.setCreatedBy("Test");
123         policy.setModifiedBy("Test");
124         policyVersion.add(policy);
125         }
126         
127         @Test
128         public void testInit(){
129                 PolicyManagerServlet servlet = new PolicyManagerServlet();
130                 ServletConfig servletConfig = mock(ServletConfig.class);       
131         try {
132                 when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
133                 when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.admin.properties");
134                 System.setProperty("xacml.rest.admin.closedLoopJSON", new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "JSONConfig.json");
135                         servlet.init(servletConfig);
136                 } catch (Exception e1) {
137                         logger.error("Exception Occured"+e1);
138                         fail();
139                 }
140         }
141         
142         @SuppressWarnings("static-access")
143         @Test
144         public void testDescribePolicy(){
145                 PolicyManagerServlet servlet = new PolicyManagerServlet();
146                 HttpServletRequest request = mock(HttpServletRequest.class);       
147         HttpServletResponse response = mock(HttpServletResponse.class);  
148         PolicyController controller = mock(PolicyController.class);
149         
150         BufferedReader reader = new BufferedReader(new StringReader("{params: { mode: 'DESCRIBEPOLICYFILE', path: 'com.Config_SampleTest1206.1.xml'}}"));
151         try {
152                         when(request.getReader()).thenReturn(reader);
153                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(basePolicyData);
154                         servlet.setPolicyController(controller);
155                         servlet.doPost(request, response);
156                 } catch (Exception e1) {
157                         logger.error("Exception Occured"+e1);
158                         fail();
159                 }
160         }
161         
162         
163         @SuppressWarnings("static-access")
164         @Test
165         public void testPolicyScopeList(){
166                 PolicyManagerServlet servlet = new PolicyManagerServlet();
167                 HttpServletRequest request = mock(HttpServletRequest.class);       
168         HttpServletResponse response = mock(HttpServletResponse.class); 
169         PolicyController controller = mock(PolicyController.class);
170         List<String> list = new ArrayList<>();
171         list.add("{params: { mode: 'LIST', path: '/', onlyFolders: false}}");
172         list.add("{params: { mode: 'LIST', path: '/com', onlyFolders: false}}");
173         for(int i =0; i < list.size(); i++){
174                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
175             try {
176                         when(request.getReader()).thenReturn(reader);
177                         when(controller.getRoles("Test")).thenReturn(rolesdata);
178                         when(controller.getDataByQuery("from PolicyEditorScopes")).thenReturn(policyEditorScopes);
179                         when(controller.getDataByQuery("from PolicyEditorScopes where SCOPENAME like 'com%'")).thenReturn(policyEditorScopes);
180                         when(controller.getDataByQuery("from PolicyVersion where POLICY_NAME like 'com%'")).thenReturn(policyVersion);
181                         servlet.setPolicyController(controller);
182                         servlet.setTestUserId("Test");
183                         servlet.doPost(request, response);
184                 } catch (Exception e1) {
185                         logger.error("Exception Occured"+e1);
186                         fail();
187                 }
188         }
189         }
190         
191         @SuppressWarnings("static-access")
192         @Test
193         public void editBasePolicyTest(){
194                 PolicyManagerServlet servlet = new PolicyManagerServlet();
195                 HttpServletRequest request = mock(HttpServletRequest.class);       
196         HttpServletResponse response = mock(HttpServletResponse.class); 
197         PolicyController controller = mock(PolicyController.class);
198         List<String> list = new ArrayList<>();
199         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_SampleTest1206.1.xml', onlyFolders: false}}");
200         for(int i =0; i < list.size(); i++){
201                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
202             try {
203                         when(request.getReader()).thenReturn(reader);
204                         when(controller.getRoles("Test")).thenReturn(rolesdata);
205                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(basePolicyData);
206                         servlet.setPolicyController(controller);
207                         servlet.setTestUserId("Test");
208                         servlet.doPost(request, response);
209                 } catch (Exception e1) {
210                         logger.error("Exception Occured"+e1);
211                         fail();
212                 }
213         }
214         }
215         
216         @SuppressWarnings("static-access")
217         @Test
218         public void editBRMSParamPolicyTest(){
219                 List<Object> policyData = new ArrayList<>();
220         String policyContent = "";
221         String configData = "";
222         try {
223                         ClassLoader classLoader = getClass().getClassLoader();
224                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml"));
225                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt"));
226                 } catch (Exception e1) {
227                         logger.error("Exception Occured"+e1);
228                 }
229         PolicyEntity entity = new PolicyEntity();
230         entity.setPolicyName("Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml");
231         entity.setPolicyData(policyContent);
232         entity.setScope("com");
233         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
234         configurationEntity.setConfigBody(configData);
235         configurationEntity.setConfigType("OTHER");
236         configurationEntity.setConfigurationName("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt");
237         configurationEntity.setDescription("test");
238         entity.setConfigurationData(configurationEntity);
239         policyData.add(entity);
240                 PolicyManagerServlet servlet = new PolicyManagerServlet();
241                 HttpServletRequest request = mock(HttpServletRequest.class);       
242         HttpServletResponse response = mock(HttpServletResponse.class); 
243         PolicyController controller = mock(PolicyController.class);
244         List<String> list = new ArrayList<>();
245         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml', onlyFolders: false}}");
246         for(int i =0; i < list.size(); i++){
247                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
248             try {
249                         when(request.getReader()).thenReturn(reader);
250                         when(controller.getRoles("Test")).thenReturn(rolesdata);
251                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
252                         servlet.setPolicyController(controller);
253                         servlet.setTestUserId("Test");
254                         servlet.doPost(request, response);
255                 } catch (Exception e1) {
256                         logger.error("Exception Occured"+e1);
257                         fail();
258                 }
259         }
260         }
261
262         @SuppressWarnings("static-access")
263         @Test
264         public void editBRMSRawPolicyTest(){
265                 List<Object> policyData = new ArrayList<>();
266         String policyContent = "";
267         String configData = "";
268         try {
269                         ClassLoader classLoader = getClass().getClassLoader();
270                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_BRMS_Raw_TestBRMSRawPolicy.1.xml"));
271                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt"));
272                 } catch (Exception e1) {
273                         logger.error("Exception Occured"+e1);
274                 }
275         PolicyEntity entity = new PolicyEntity();
276         entity.setPolicyName("Config_BRMS_Raw_TestBRMSRawPolicy.1.xml");
277         entity.setPolicyData(policyContent);
278         entity.setScope("com");
279         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
280         configurationEntity.setConfigBody(configData);
281         configurationEntity.setConfigType("OTHER");
282         configurationEntity.setConfigurationName("com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt");
283         configurationEntity.setDescription("test");
284         entity.setConfigurationData(configurationEntity);
285         policyData.add(entity);
286                 PolicyManagerServlet servlet = new PolicyManagerServlet();
287                 HttpServletRequest request = mock(HttpServletRequest.class);       
288         HttpServletResponse response = mock(HttpServletResponse.class); 
289         PolicyController controller = mock(PolicyController.class);
290         List<String> list = new ArrayList<>();
291         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml', onlyFolders: false}}");
292         for(int i =0; i < list.size(); i++){
293                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
294             try {
295                         when(request.getReader()).thenReturn(reader);
296                         when(controller.getRoles("Test")).thenReturn(rolesdata);
297                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_BRMS_Raw_TestBRMSRawPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
298                         servlet.setPolicyController(controller);
299                         servlet.setTestUserId("Test");
300                         servlet.doPost(request, response);
301                 } catch (Exception e1) {
302                         logger.error("Exception Occured"+e1);
303                         fail();
304                 }
305         }
306         }
307         
308         @SuppressWarnings("static-access")
309         @Test
310         public void editClosedLoopFaultPolicyTest(){
311                 List<Object> policyData = new ArrayList<>();
312         String policyContent = "";
313         String configData = "";
314         try {
315                         ClassLoader classLoader = getClass().getClassLoader();
316                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_Fault_TestClosedLoopPolicy.1.xml"));
317                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_Fault_TestClosedLoopPolicy.1.json"));
318                 } catch (Exception e1) {
319                         logger.error("Exception Occured"+e1);
320                 }
321         PolicyEntity entity = new PolicyEntity();
322         entity.setPolicyName("Config_Fault_TestClosedLoopPolicy.1.xml");
323         entity.setPolicyData(policyContent);
324         entity.setScope("com");
325         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
326         configurationEntity.setConfigBody(configData);
327         configurationEntity.setConfigType("JSON");
328         configurationEntity.setConfigurationName("com.Config_Fault_TestClosedLoopPolicy.1.json");
329         configurationEntity.setDescription("test");
330         entity.setConfigurationData(configurationEntity);
331         policyData.add(entity);
332                 PolicyManagerServlet servlet = new PolicyManagerServlet();
333                 HttpServletRequest request = mock(HttpServletRequest.class);       
334         HttpServletResponse response = mock(HttpServletResponse.class); 
335         PolicyController controller = mock(PolicyController.class);
336         List<String> list = new ArrayList<>();
337         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_Fault_TestClosedLoopPolicy.1.xml', onlyFolders: false}}");
338         for(int i =0; i < list.size(); i++){
339                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
340             try {
341                         when(request.getReader()).thenReturn(reader);
342                         when(controller.getRoles("Test")).thenReturn(rolesdata);
343                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_Fault_TestClosedLoopPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
344                         servlet.setPolicyController(controller);
345                         servlet.setTestUserId("Test");
346                         servlet.doPost(request, response);
347                 } catch (Exception e1) {
348                         logger.error("Exception Occured"+e1);
349                         fail();
350                 }
351         }
352         }
353         
354         @SuppressWarnings("static-access")
355         @Test
356         public void editClosedLoopPMPolicyTest(){
357                 List<Object> policyData = new ArrayList<>();
358         String policyContent = "";
359         String configData = "";
360         try {
361                         ClassLoader classLoader = getClass().getClassLoader();
362                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_PM_TestClosedLoopPMPolicy.1.xml"));
363                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_PM_TestClosedLoopPMPolicy.1.json"));
364                 } catch (Exception e1) {
365                         logger.error("Exception Occured"+e1);
366                 }
367         PolicyEntity entity = new PolicyEntity();
368         entity.setPolicyName("Config_PM_TestClosedLoopPMPolicy.1.xml");
369         entity.setPolicyData(policyContent);
370         entity.setScope("com");
371         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
372         configurationEntity.setConfigBody(configData);
373         configurationEntity.setConfigType("JSON");
374         configurationEntity.setConfigurationName("com.Config_PM_TestClosedLoopPMPolicy.1.json");
375         configurationEntity.setDescription("test");
376         entity.setConfigurationData(configurationEntity);
377         policyData.add(entity);
378                 PolicyManagerServlet servlet = new PolicyManagerServlet();
379                 HttpServletRequest request = mock(HttpServletRequest.class);       
380         HttpServletResponse response = mock(HttpServletResponse.class); 
381         PolicyController controller = mock(PolicyController.class);
382         List<String> list = new ArrayList<>();
383         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_PM_TestClosedLoopPMPolicy.1.xml', onlyFolders: false}}");
384         for(int i =0; i < list.size(); i++){
385                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
386             try {
387                         when(request.getReader()).thenReturn(reader);
388                         when(controller.getRoles("Test")).thenReturn(rolesdata);
389                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_PM_TestClosedLoopPMPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
390                         servlet.setPolicyController(controller);
391                         servlet.setTestUserId("Test");
392                         servlet.doPost(request, response);
393                 } catch (Exception e1) {
394                         logger.error("Exception Occured"+e1);
395                         fail();
396                 }
397         }
398         }
399         
400         @SuppressWarnings("static-access")
401         @Test
402         public void editMicroServicePolicyTest(){
403                 GroupPolicyScopeList groupData = new  GroupPolicyScopeList();
404                 groupData.setGroupName("Test");
405                 groupData.setGroupList("resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop");
406                 List<Object> groupListData = new ArrayList<>();
407                 groupListData.add(groupData);
408                 commonClassDao = mock(CommonClassDao.class);
409                 CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
410                 List<Object> policyData = new ArrayList<>();
411         String policyContent = "";
412         String configData = "";
413         try {
414                         ClassLoader classLoader = getClass().getClassLoader();
415                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_MS_vFirewall.1.xml"));
416                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_MS_vFirewall.1.json"));
417                 } catch (Exception e1) {
418                         logger.error("Exception Occured"+e1);
419                 }
420         PolicyEntity entity = new PolicyEntity();
421         entity.setPolicyName("Config_MS_vFirewall.1.xml");
422         entity.setPolicyData(policyContent);
423         entity.setScope("com");
424         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
425         configurationEntity.setConfigBody(configData);
426         configurationEntity.setConfigType("JSON");
427         configurationEntity.setConfigurationName("com.Config_MS_vFirewall.1.json");
428         configurationEntity.setDescription("test");
429         entity.setConfigurationData(configurationEntity);
430         policyData.add(entity);
431                 PolicyManagerServlet servlet = new PolicyManagerServlet();
432                 HttpServletRequest request = mock(HttpServletRequest.class);       
433         HttpServletResponse response = mock(HttpServletResponse.class); 
434         PolicyController controller = mock(PolicyController.class);
435         List<String> list = new ArrayList<>();
436         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_MS_vFirewall.1.xml', onlyFolders: false}}");
437         for(int i =0; i < list.size(); i++){
438                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
439             try {
440                         when(request.getReader()).thenReturn(reader);
441                         when(commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", "resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop")).thenReturn(groupListData);
442                         when(controller.getRoles("Test")).thenReturn(rolesdata);
443                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_MS_vFirewall.1.xml' and scope ='com'")).thenReturn(policyData);
444                         servlet.setPolicyController(controller);
445                         servlet.setTestUserId("Test");
446                         servlet.doPost(request, response);
447                 } catch (Exception e1) {
448                         logger.error("Exception Occured"+e1);
449                         fail();
450                 }
451         }
452         }
453         
454         @SuppressWarnings("static-access")
455         @Test
456         public void editFirewallPolicyTest(){
457                 List<Object> policyData = new ArrayList<>();
458         String policyContent = "";
459         String configData = "";
460         try {
461                         ClassLoader classLoader = getClass().getClassLoader();
462                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_FW_TestFireWallPolicy.1.xml"));
463                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_FW_TestFireWallPolicy.1.json"));
464                 } catch (Exception e1) {
465                         logger.error("Exception Occured"+e1);
466                 }
467         PolicyEntity entity = new PolicyEntity();
468         entity.setPolicyName("Config_FW_TestFireWallPolicy.1.xml");
469         entity.setPolicyData(policyContent);
470         entity.setScope("com");
471         ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
472         configurationEntity.setConfigBody(configData);
473         configurationEntity.setConfigType("JSON");
474         configurationEntity.setConfigurationName("com.Config_FW_TestFireWallPolicy.1.json");
475         configurationEntity.setDescription("test");
476         entity.setConfigurationData(configurationEntity);
477         policyData.add(entity);
478                 PolicyManagerServlet servlet = new PolicyManagerServlet();
479                 HttpServletRequest request = mock(HttpServletRequest.class);       
480         HttpServletResponse response = mock(HttpServletResponse.class); 
481         PolicyController controller = mock(PolicyController.class);
482         List<String> list = new ArrayList<>();
483         list.add("{params: { mode: 'EDITFILE', path: '/com/Config_FW_TestFireWallPolicy.1.xml', onlyFolders: false}}");
484         for(int i =0; i < list.size(); i++){
485                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
486             try {
487                         when(request.getReader()).thenReturn(reader);
488                         when(controller.getRoles("Test")).thenReturn(rolesdata);
489                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_FW_TestFireWallPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
490                         servlet.setPolicyController(controller);
491                         servlet.setTestUserId("Test");
492                         servlet.doPost(request, response);
493                 } catch (Exception e1) {
494                         logger.error("Exception Occured"+e1);
495                         fail();
496                 }
497         }
498         }
499         
500         @SuppressWarnings("static-access")
501         @Test
502         public void editActionPolicyTest(){
503                 List<Object> policyData = new ArrayList<>();
504         String policyContent = "";
505         String configData = "";
506         try {
507                         ClassLoader classLoader = getClass().getClassLoader();
508                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Action_TestActionPolicy.1.xml"));
509                         configData = IOUtils.toString(classLoader.getResourceAsStream("com.Action_TestActionPolicy.1.json"));
510                 } catch (Exception e1) {
511                         logger.error("Exception Occured"+e1);
512                 }
513         PolicyEntity entity = new PolicyEntity();
514         entity.setPolicyName("Action_TestActionPolicy.1.xml");
515         entity.setPolicyData(policyContent);
516         entity.setScope("com");
517         ActionBodyEntity configurationEntity = new ActionBodyEntity();
518         configurationEntity.setActionBody(configData);
519         configurationEntity.setActionBodyName("com.Action_TestActionPolicy.1.json");
520         entity.setActionBodyEntity(configurationEntity);
521         policyData.add(entity);
522                 PolicyManagerServlet servlet = new PolicyManagerServlet();
523                 HttpServletRequest request = mock(HttpServletRequest.class);       
524         HttpServletResponse response = mock(HttpServletResponse.class); 
525         PolicyController controller = mock(PolicyController.class);
526         List<String> list = new ArrayList<>();
527         list.add("{params: { mode: 'EDITFILE', path: '/com/Action_TestActionPolicy.1.xml', onlyFolders: false}}");
528         for(int i =0; i < list.size(); i++){
529                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
530             try {
531                         when(request.getReader()).thenReturn(reader);
532                         when(controller.getRoles("Test")).thenReturn(rolesdata);
533                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Action_TestActionPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
534                         servlet.setPolicyController(controller);
535                         servlet.setTestUserId("Test");
536                         servlet.doPost(request, response);
537                 } catch (Exception e1) {
538                         logger.error("Exception Occured"+e1);
539                         fail();
540                 }
541         }
542         }
543         
544         @SuppressWarnings("static-access")
545         @Test
546         public void editDecisionPolicyTest(){
547                 List<Object> policyData = new ArrayList<>();
548         String policyContent = "";
549         try {
550                         ClassLoader classLoader = getClass().getClassLoader();
551                         policyContent = IOUtils.toString(classLoader.getResourceAsStream("Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml"));
552                 } catch (Exception e1) {
553                         logger.error("Exception Occured"+e1);
554                 }
555         PolicyEntity entity = new PolicyEntity();
556         entity.setPolicyName("Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml");
557         entity.setPolicyData(policyContent);
558         entity.setScope("com");
559         policyData.add(entity);
560                 PolicyManagerServlet servlet = new PolicyManagerServlet();
561                 HttpServletRequest request = mock(HttpServletRequest.class);       
562         HttpServletResponse response = mock(HttpServletResponse.class); 
563         PolicyController controller = mock(PolicyController.class);
564         List<String> list = new ArrayList<>();
565         list.add("{params: { mode: 'EDITFILE', path: '/com/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml', onlyFolders: false}}");
566         for(int i =0; i < list.size(); i++){
567                 BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
568             try {
569                         when(request.getReader()).thenReturn(reader);
570                         when(controller.getRoles("Test")).thenReturn(rolesdata);
571                         when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml' and scope ='com'")).thenReturn(policyData);
572                         servlet.setPolicyController(controller);
573                         servlet.setTestUserId("Test");
574                         servlet.doPost(request, response);
575                 } catch (Exception e1) {
576                         logger.error("Exception Occured"+e1);
577                         fail();
578                 }
579         }
580         }
581 }