+ @Test
+ public void editBRMSRawPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_BRMS_Raw_TestBRMSRawPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_BRMS_Raw_TestBRMSRawPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("OTHER");
+ configurationEntity.setConfigurationName("com.Config_BRMS_Raw_TestBRMSRawPolicy.1.txt");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_BRMS_Raw_TestBRMSRawPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editClosedLoopFaultPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_Fault_TestClosedLoopPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_Fault_TestClosedLoopPolicy.1.json"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_Fault_TestClosedLoopPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("JSON");
+ configurationEntity.setConfigurationName("com.Config_Fault_TestClosedLoopPolicy.1.json");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Config_Fault_TestClosedLoopPolicy.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_Fault_TestClosedLoopPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editClosedLoopPMPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_PM_TestClosedLoopPMPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_PM_TestClosedLoopPMPolicy.1.json"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_PM_TestClosedLoopPMPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("JSON");
+ configurationEntity.setConfigurationName("com.Config_PM_TestClosedLoopPMPolicy.1.json");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Config_PM_TestClosedLoopPMPolicy.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_PM_TestClosedLoopPMPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editMicroServicePolicyTest(){
+ GroupPolicyScopeList groupData = new GroupPolicyScopeList();
+ groupData.setGroupName("Test");
+ groupData.setGroupList("resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop");
+ List<Object> groupListData = new ArrayList<>();
+ groupListData.add(groupData);
+ commonClassDao = mock(CommonClassDao.class);
+ CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao);
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_MS_vFirewall.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_MS_vFirewall.1.json"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_MS_vFirewall.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("JSON");
+ configurationEntity.setConfigurationName("com.Config_MS_vFirewall.1.json");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Config_MS_vFirewall.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", "resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop")).thenReturn(groupListData);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_MS_vFirewall.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editFirewallPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_FW_TestFireWallPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_FW_TestFireWallPolicy.1.json"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_FW_TestFireWallPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("JSON");
+ configurationEntity.setConfigurationName("com.Config_FW_TestFireWallPolicy.1.json");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Config_FW_TestFireWallPolicy.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_FW_TestFireWallPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editActionPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Action_TestActionPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Action_TestActionPolicy.1.json"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Action_TestActionPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ActionBodyEntity configurationEntity = new ActionBodyEntity();
+ configurationEntity.setActionBody(configData);
+ configurationEntity.setActionBodyName("com.Action_TestActionPolicy.1.json");
+ entity.setActionBodyEntity(configurationEntity);
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Action_TestActionPolicy.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Action_TestActionPolicy.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editDecisionPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ policyData.add(entity);
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ PolicyController controller = mock(PolicyController.class);
+ List<String> list = new ArrayList<>();
+ list.add("{params: { mode: 'EDITFILE', path: '/com/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml', onlyFolders: false}}");
+ for(int i =0; i < list.size(); i++){
+ BufferedReader reader = new BufferedReader(new StringReader(list.get(i)));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ when(controller.getRoles("Test")).thenReturn(rolesdata);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml' and scope ='com'")).thenReturn(policyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }