summaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src/test/java/org
diff options
context:
space:
mode:
authorTarun Tej Velaga <tt3868@att.com>2017-07-24 17:13:43 +0000
committerTarun Tej Velaga <tt3868@att.com>2017-07-25 14:23:59 +0000
commite92ff832cf993db876f22b2d27562fedf59f5043 (patch)
tree47429eeaaf4241905d7ea1f71dbdb5c2d0504618 /POLICY-SDK-APP/src/test/java/org
parent570290dc6ba8198e653022c2f6f8e5d01cfa8d1b (diff)
[Policy-52, Policy-92, Policy-93] Policy Enhancements and bugfixes
Change-Id: I5675cf4527e17963b3142cf7184c0df31a766197 Signed-off-by: Tarun Tej Velaga <tt3868@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src/test/java/org')
-rw-r--r--POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java423
-rw-r--r--POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java35
-rw-r--r--POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java1
3 files changed, 448 insertions, 11 deletions
diff --git a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java
index 773955d85..a25027679 100644
--- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java
@@ -19,11 +19,16 @@
*/
package org.openecomp.policy.admin;
+import static org.junit.Assert.fail;
+
import java.io.BufferedReader;
+import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -33,8 +38,13 @@ import org.junit.Test;
import org.mockito.Mockito;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
+import org.openecomp.policy.controller.CreateDcaeMicroServiceController;
import org.openecomp.policy.controller.PolicyController;
import org.openecomp.policy.model.Roles;
+import org.openecomp.policy.rest.dao.CommonClassDao;
+import org.openecomp.policy.rest.jpa.ActionBodyEntity;
+import org.openecomp.policy.rest.jpa.ConfigurationDataEntity;
+import org.openecomp.policy.rest.jpa.GroupPolicyScopeList;
import org.openecomp.policy.rest.jpa.PolicyEditorScopes;
import org.openecomp.policy.rest.jpa.PolicyEntity;
import org.openecomp.policy.rest.jpa.PolicyVersion;
@@ -43,11 +53,13 @@ import org.openecomp.policy.rest.jpa.UserInfo;
public class PolicyManagerServletTest extends Mockito{
private static Logger logger = FlexLogger.getLogger(PolicyManagerServletTest.class);
+ private List<String> headers = new ArrayList<String>();
private static List<Object> rolesdata;
- private static List<Object> policyData;
+ private static List<Object> basePolicyData;
private static List<Object> policyEditorScopes;
private static List<Object> policyVersion;
+ private static CommonClassDao commonClassDao;
@Before
public void setUp() throws Exception{
@@ -68,7 +80,7 @@ public class PolicyManagerServletTest extends Mockito{
rolesdata.add(roles1);
//PolicyEntity Data
- policyData = new ArrayList<>();
+ basePolicyData = new ArrayList<>();
String policyContent = "";
try {
ClassLoader classLoader = getClass().getClassLoader();
@@ -80,7 +92,13 @@ public class PolicyManagerServletTest extends Mockito{
entity.setPolicyName("Config_SampleTest.1.xml");
entity.setPolicyData(policyContent);
entity.setScope("com");
- policyData.add(entity);
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody("Sample Test");
+ configurationEntity.setConfigType("OTHER");
+ configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt");
+ configurationEntity.setDescription("test");
+ entity.setConfigurationData(configurationEntity);
+ basePolicyData.add(entity);
//PolicyEditorScopes data
policyEditorScopes = new ArrayList<>();
@@ -107,6 +125,21 @@ public class PolicyManagerServletTest extends Mockito{
}
@Test
+ public void testInit(){
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ ServletConfig servletConfig = mock(ServletConfig.class);
+ try {
+ when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers));
+ when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.admin.properties");
+ System.setProperty("xacml.rest.admin.closedLoopJSON", new File(".").getCanonicalPath() + File.separator + "src"+ File.separator + "test" + File.separator + "resources" + File.separator + "JSONConfig.json");
+ servlet.init(servletConfig);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+
+ @Test
public void testDescribePolicy(){
PolicyManagerServlet servlet = new PolicyManagerServlet();
HttpServletRequest request = mock(HttpServletRequest.class);
@@ -116,11 +149,12 @@ public class PolicyManagerServletTest extends Mockito{
BufferedReader reader = new BufferedReader(new StringReader("{params: { mode: 'DESCRIBEPOLICYFILE', path: 'com.Config_SampleTest1206.1.xml'}}"));
try {
when(request.getReader()).thenReturn(reader);
- when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(policyData);
+ when(controller.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(basePolicyData);
servlet.setPolicyController(controller);
servlet.doPost(request, response);
} catch (Exception e1) {
logger.error("Exception Occured"+e1);
+ fail();
}
}
@@ -147,9 +181,390 @@ public class PolicyManagerServletTest extends Mockito{
servlet.doPost(request, response);
} catch (Exception e1) {
logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void editBasePolicyTest(){
+ 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_SampleTest1206.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_SampleTest1206.1.xml' and scope ='com'")).thenReturn(basePolicyData);
+ servlet.setPolicyController(controller);
+ servlet.setTestUserId("Test");
+ servlet.doPost(request, response);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
}
}
}
+ @Test
+ public void editBRMSParamPolicyTest(){
+ List<Object> policyData = new ArrayList<>();
+ String policyContent = "";
+ String configData = "";
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml"));
+ configData = IOUtils.toString(classLoader.getResourceAsStream("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ PolicyEntity entity = new PolicyEntity();
+ entity.setPolicyName("Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml");
+ entity.setPolicyData(policyContent);
+ entity.setScope("com");
+ ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity();
+ configurationEntity.setConfigBody(configData);
+ configurationEntity.setConfigType("OTHER");
+ configurationEntity.setConfigurationName("com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.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_Param_BRMSParamvFWDemoPolicy.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_Param_BRMSParamvFWDemoPolicy.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 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();
+ }
+ }
+ }
}
diff --git a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java
index 43b8a6f25..07bd54939 100644
--- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java
@@ -19,10 +19,12 @@
*/
package org.openecomp.policy.controller;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.BufferedReader;
+import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -41,12 +43,20 @@ public class AdminTabControllerTest {
private static Logger logger = FlexLogger.getLogger(AdminTabControllerTest.class);
private static CommonClassDao commonClassDao;
+ private HttpServletRequest request;
+ private MockHttpServletResponse response;
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
+
+ request = mock(HttpServletRequest.class);
+ response = new MockHttpServletResponse();
+
+ AdminTabController.setCommonClassDao(commonClassDao);
+
GlobalRoleSettings globalRole = new GlobalRoleSettings();
globalRole.setLockdown(true);
globalRole.setRole("super-admin");
@@ -57,17 +67,28 @@ public class AdminTabControllerTest {
@Test
public void testGetAdminRole(){
- HttpServletRequest request = mock(HttpServletRequest.class);
- MockHttpServletResponse response = new MockHttpServletResponse();
-
AdminTabController admin = new AdminTabController();
- AdminTabController.setCommonClassDao(commonClassDao);
- admin.getAdminTabEntityData(request, response);
-
try {
+ admin.getAdminTabEntityData(request, response);
assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("lockdowndata"));
} catch (UnsupportedEncodingException e) {
logger.error("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testSaveAdminRole() throws Exception{
+ AdminTabController admin = new AdminTabController();
+ String data = "{\"lockdowndata\":{\"lockdown\":true}}";
+ BufferedReader reader = new BufferedReader(new StringReader(data));
+ try {
+ when(request.getReader()).thenReturn(reader);
+ admin.saveAdminTabLockdownValue(request, response);
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas"));
+ } catch (UnsupportedEncodingException e) {
+ logger.error("Exception Occured"+e);
+ fail();
}
}
diff --git a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java
index b4619b852..ca915440e 100644
--- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java
@@ -169,6 +169,7 @@ public class CreateDcaeMicroServiceControllerTest {
//expect: uniqueKeys should contain a string value
CreateDcaeMicroServiceController controllerA = new CreateDcaeMicroServiceController();
String str = "testing\\.byCorrectWay\\.OfDATA";
+ String value = null;
assertEquals(1, controllerA.stringBetweenDots(str));
//expect: uniqueKeys should not contain a string value