From 073cc188efe9abb4c010cf674e34e2cf46ef1c52 Mon Sep 17 00:00:00 2001 From: Guo Ruijing Date: Mon, 31 Jul 2017 08:47:35 +0000 Subject: [POLICY-73] replace openecomp for policy-engine Change-Id: I54072f6bcd388c0e05562614ee89b4ae7ad67004 Signed-off-by: Guo Ruijing Signed-off-by: Pamela Dragosh --- .../policy/admin/PolicyManagerServletTest.java | 581 ++++++++++++++++++ .../policy/controller/AdminTabControllerTest.java | 95 +++ .../CreateDcaeMicroServiceControllerTest.java | 646 +++++++++++++++++++++ .../onap/policy/controller/PDPControllerTest.java | 98 ++++ .../policy/controller/PolicyControllerTest.java | 66 +++ .../policy/admin/PolicyManagerServletTest.java | 581 ------------------ .../policy/controller/AdminTabControllerTest.java | 95 --- .../CreateDcaeMicroServiceControllerTest.java | 646 --------------------- .../policy/controller/PDPControllerTest.java | 98 ---- .../policy/controller/PolicyControllerTest.java | 66 --- .../test/resources/Action_TestActionPolicy.1.xml | 2 +- .../Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml | 18 +- .../Config_BRMS_Raw_TestBRMSRawPolicy.1.xml | 20 +- .../resources/Config_FW_TestFireWallPolicy.1.xml | 14 +- .../Config_Fault_TestClosedLoopPolicy.1.xml | 16 +- .../src/test/resources/Config_MS_vFirewall.1.xml | 24 +- .../Config_PM_TestClosedLoopPMPolicy.1.xml | 18 +- .../src/test/resources/Config_SampleTest1206.1.xml | 18 +- ...sion_TestDecisionPolicyWithRuleAlgorithms.1.xml | 8 +- ....Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt | 100 ++-- .../com.Config_Fault_TestClosedLoopPolicy.1.json | 2 +- POLICY-SDK-APP/src/test/resources/logback.xml | 4 +- .../src/test/resources/schedulerPolicies1707.xmi | 44 +- 23 files changed, 1630 insertions(+), 1630 deletions(-) create mode 100644 POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java create mode 100644 POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java create mode 100644 POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java create mode 100644 POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java create mode 100644 POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java delete mode 100644 POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java delete mode 100644 POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java delete mode 100644 POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java delete mode 100644 POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PDPControllerTest.java delete mode 100644 POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PolicyControllerTest.java (limited to 'POLICY-SDK-APP/src/test') diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java new file mode 100644 index 000000000..e61742f1c --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java @@ -0,0 +1,581 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.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; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.controller.CreateDcaeMicroServiceController; +import org.onap.policy.controller.PolicyController; +import org.onap.policy.model.Roles; +import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.ActionBodyEntity; +import org.onap.policy.rest.jpa.ConfigurationDataEntity; +import org.onap.policy.rest.jpa.GroupPolicyScopeList; +import org.onap.policy.rest.jpa.PolicyEditorScopes; +import org.onap.policy.rest.jpa.PolicyEntity; +import org.onap.policy.rest.jpa.PolicyVersion; +import org.onap.policy.rest.jpa.UserInfo; + +public class PolicyManagerServletTest extends Mockito{ + + private static Logger logger = FlexLogger.getLogger(PolicyManagerServletTest.class); + private List headers = new ArrayList(); + + private static List rolesdata; + private static List basePolicyData; + private static List policyEditorScopes; + private static List policyVersion; + private static CommonClassDao commonClassDao; + + @Before + public void setUp() throws Exception{ + logger.info("setUp: Entering"); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId("Test"); + userinfo.setUserName("Test"); + //Roles Data + rolesdata = new ArrayList<>(); + Roles roles = new Roles(); + roles.setLoginId("Test"); + roles.setRole("super-admin"); + Roles roles1 = new Roles(); + roles1.setLoginId("Test"); + roles1.setRole("admin"); + roles1.setScope("['com','Test']"); + rolesdata.add(roles); + rolesdata.add(roles1); + + //PolicyEntity Data + basePolicyData = new ArrayList<>(); + String policyContent = ""; + try { + ClassLoader classLoader = getClass().getClassLoader(); + policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")); + } catch (Exception e1) { + logger.error("Exception Occured"+e1); + } + PolicyEntity entity = new PolicyEntity(); + entity.setPolicyName("Config_SampleTest.1.xml"); + entity.setPolicyData(policyContent); + entity.setScope("com"); + 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<>(); + PolicyEditorScopes scopes = new PolicyEditorScopes(); + scopes.setScopeName("com"); + scopes.setUserCreatedBy(userinfo); + scopes.setUserModifiedBy(userinfo); + PolicyEditorScopes scopes1 = new PolicyEditorScopes(); + scopes1.setScopeName("com\\Test"); + scopes1.setUserCreatedBy(userinfo); + scopes1.setUserModifiedBy(userinfo); + policyEditorScopes.add(scopes); + policyEditorScopes.add(scopes1); + + //PolicyVersion data + policyVersion = new ArrayList<>(); + PolicyVersion policy = new PolicyVersion(); + policy.setPolicyName("com\\Config_SampleTest1206"); + policy.setActiveVersion(1); + policy.setHigherVersion(1); + policy.setCreatedBy("Test"); + policy.setModifiedBy("Test"); + policyVersion.add(policy); + } + + @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(); + } + } + + @SuppressWarnings("static-access") + @Test + public void testDescribePolicy(){ + PolicyManagerServlet servlet = new PolicyManagerServlet(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + PolicyController controller = mock(PolicyController.class); + + 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(basePolicyData); + servlet.setPolicyController(controller); + servlet.doPost(request, response); + } catch (Exception e1) { + logger.error("Exception Occured"+e1); + fail(); + } + } + + + @SuppressWarnings("static-access") + @Test + public void testPolicyScopeList(){ + PolicyManagerServlet servlet = new PolicyManagerServlet(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + PolicyController controller = mock(PolicyController.class); + List list = new ArrayList<>(); + list.add("{params: { mode: 'LIST', path: '/', onlyFolders: false}}"); + list.add("{params: { mode: 'LIST', path: '/com', 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 PolicyEditorScopes")).thenReturn(policyEditorScopes); + when(controller.getDataByQuery("from PolicyEditorScopes where SCOPENAME like 'com%'")).thenReturn(policyEditorScopes); + when(controller.getDataByQuery("from PolicyVersion where POLICY_NAME like 'com%'")).thenReturn(policyVersion); + servlet.setPolicyController(controller); + servlet.setTestUserId("Test"); + servlet.doPost(request, response); + } catch (Exception e1) { + logger.error("Exception Occured"+e1); + fail(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editBasePolicyTest(){ + PolicyManagerServlet servlet = new PolicyManagerServlet(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + PolicyController controller = mock(PolicyController.class); + List 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editBRMSParamPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editBRMSRawPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editClosedLoopFaultPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editClosedLoopPMPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editMicroServicePolicyTest(){ + GroupPolicyScopeList groupData = new GroupPolicyScopeList(); + groupData.setGroupName("Test"); + groupData.setGroupList("resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop"); + List groupListData = new ArrayList<>(); + groupListData.add(groupData); + commonClassDao = mock(CommonClassDao.class); + CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editFirewallPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editActionPolicyTest(){ + List 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 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(); + } + } + } + + @SuppressWarnings("static-access") + @Test + public void editDecisionPolicyTest(){ + List 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 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/onap/policy/controller/AdminTabControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java new file mode 100644 index 000000000..0109cb503 --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/AdminTabControllerTest.java @@ -0,0 +1,95 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.controller; + +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; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.GlobalRoleSettings; +import org.springframework.mock.web.MockHttpServletResponse; + +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"); + List globalRoles = new ArrayList<>(); + globalRoles.add(globalRole); + when(commonClassDao.getData(GlobalRoleSettings.class)).thenReturn(globalRoles); + } + + @Test + public void testGetAdminRole(){ + AdminTabController admin = new AdminTabController(); + 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/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java new file mode 100644 index 000000000..a90e1b7dd --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java @@ -0,0 +1,646 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controller; + + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.rest.adapter.PolicyRestAdapter; +import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.ConfigurationDataEntity; +import org.onap.policy.rest.jpa.MicroServiceModels; +import org.onap.policy.rest.jpa.PolicyEntity; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jackson.JsonLoader; + +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; + +/** + * The class CreateDcaeMicroServiceControllerTest contains tests + * for the class {@link CreateDcaeMicroServiceController}* + * + * All JUnits are designed to run in the local development environment + * where they have write privileges and can execute time-sensitive + * tasks. + * + * + * + */ + +public class CreateDcaeMicroServiceControllerTest { + + private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class); + private static CommonClassDao commonClassDao; + private String jsonString = null; + private String configBodyString = null; + private HttpServletRequest request = null; + + @Before + public void setUp() throws Exception { + + logger.info("setUp: Entering"); + commonClassDao = mock(CommonClassDao.class); + List microServiceModelsData = new ArrayList(); + MicroServiceModels testData = new MicroServiceModels(); + testData.setVersion("OpenOnap-Junit"); + microServiceModelsData.add(testData); + + // mock the getDataById() call + when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "test")).thenReturn(microServiceModelsData); + + jsonString = "{\"policyData\": {\"error\": \"\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", " + + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", " + + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false}," + + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" }," + + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", " + + " \"policyDescription\": \"testing input\", \"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\"," + + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, " + + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }"; + + configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\",\"templateVersion\":\"1607\",\"version\":\"HD\"," + + "\"priority\":\"2\",\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\",\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\"," + + "\"name\":\"test\",\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\",\"target\":\"SNIRO\"}}"; + + request = mock(HttpServletRequest.class); + BufferedReader br = new BufferedReader(new StringReader(jsonString)); + // mock the getReader() call + when(request.getReader()).thenReturn(br); + + logger.info("setUp: exit"); + } + + + /** + * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, + * JsonNode) method test + */ + + @Test + public void testSetDataToPolicyRestAdapter() { + + logger.debug("testSetDataToPolicyRestAdapter: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); + + JsonNode root = null; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + PolicyRestAdapter policyData = null; + try { + root = JsonLoader.fromString(jsonString); + policyData = (PolicyRestAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); + } catch (Exception e) { + logger.error("testSetDataToPolicyRestAdapter", e); + } + + PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root); + assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty()); + + logger.debug("result.getJsonBody() : " + result.getJsonBody()); + logger.debug("testSetDataToPolicyRestAdapter: exit"); + } + + /** + * Run the void stringBetweenDots(String, String) method test + */ + + @Test + public void testStringBetweenDots() { + + logger.debug("testStringBetweenDots: enter"); + + //expect: uniqueKeys should contain a string value + CreateDcaeMicroServiceController controllerA = new CreateDcaeMicroServiceController(); + String str = "testing\\.byCorrectWay\\.OfDATA"; + assertEquals(1, controllerA.stringBetweenDots(str)); + + //expect: uniqueKeys should not contain a string value + str = "testing\byWrongtWay.\\OfDATA"; + CreateDcaeMicroServiceController controllerB = new CreateDcaeMicroServiceController(); + assertEquals(0, controllerB.stringBetweenDots(str)); + + logger.debug("testStringBetweenDots: exit"); + } + + /** + * Run the Map load(String) method test + */ + + @Test + public void testLoad() { + + logger.debug("testLoad: enter"); + + boolean isLocalTesting = true; + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + String fileName = null; + Map result = null; + try { + ClassLoader classLoader = getClass().getClassLoader(); + fileName = new File(classLoader.getResource("policy_tosca_tca_v1707.yml").getFile()).getAbsolutePath(); + } catch (Exception e1) { + logger.error("Exception Occured while loading file"+e1); + } + if(isLocalTesting){ + try { + result = controller.load(fileName); + } catch (IOException e) { + logger.error("testLoad", e); + result = null; + } + + assertTrue(result != null && !result.isEmpty()); + logger.debug("result : " + result); + } + + logger.debug("testLoad: exit"); + } + + /** + * Run the void parseTosca(String) method test + */ + + @Test + public void testParseTosca() { + + logger.debug("testParseTosca: enter"); + boolean isLocalTesting = true; + String fileName = null; + try { + ClassLoader classLoader = getClass().getClassLoader(); + fileName = new File(classLoader.getResource("policy_tosca_tca_v1707.yml").getFile()).getAbsolutePath(); + } catch (Exception e1) { + logger.error("Exception Occured while loading file"+e1); + } + + CreateDcaeMicroServiceController contoller = new CreateDcaeMicroServiceController(); + if(isLocalTesting){ + try { + contoller.parseTosca(fileName); + }catch (Exception e) { + fail("parseTosca caused error: " + e); + } + } + logger.debug("testParseTosca: exit"); + } + + /** + * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, + * HttpServletResponse) method test + */ + + @Test + public void testGetDCAEMSTemplateData() { + + logger.debug("testGetDCAEMSTemplateData: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + MockHttpServletResponse response = new MockHttpServletResponse(); + String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}"; + try { + + CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); + + BufferedReader br = new BufferedReader(new StringReader(msModelJson)); + // mock the getReader() call + when(request.getReader()).thenReturn(br); + + List microServiceModelsData = new ArrayList(); + MicroServiceModels testData = new MicroServiceModels(); + testData.setVersion("1707.4.1.2-Junit"); + microServiceModelsData.add(testData); + // mock the getDataById() call with the same MS model name + when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody")).thenReturn(microServiceModelsData); + + controller.getDCAEMSTemplateData(request, response); + + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData")); + + logger.debug("response: " + response.getContentAsString()); + + } catch (Exception e) { + logger.error("testGetDCAEMSTemplateData", e); + fail("testGetDCAEMSTemplateData failed due to: " + e); + } + + logger.debug("testGetDCAEMSTemplateData: exit"); + } + + /** + * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, + * HttpServletResponse) method test + */ + + @Test + public void testGetModelServiceVersionData() { + + logger.debug("testGetModelServiceVersionData: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + MockHttpServletResponse response = new MockHttpServletResponse(); + String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}"; + try { + + CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); + + BufferedReader br = new BufferedReader(new StringReader(msModelJson)); + // mock the getReader() call + when(request.getReader()).thenReturn(br); + + List microServiceModelsData = new ArrayList(); + MicroServiceModels testData = new MicroServiceModels(); + testData.setVersion("1707.4.1.2-Junit"); + microServiceModelsData.add(testData); + + // mock the getDataById() call with the same MS model name + when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody")).thenReturn(microServiceModelsData); + controller.getModelServiceVersionData(request, response); + + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("1707.4.1.2-Junit")); + + logger.debug("response: " + response.getContentAsString()); + + } catch (Exception e) { + logger.error("testGetModelServiceVersionData", e); + fail("testGetModelServiceVersionData failed due to: " + e); + } + + logger.debug("testGetModelServiceVersionData: exit"); + } + + /** + * Run the void getDCAEPriorityValuesData(HttpServletRequest, + * HttpServletResponse) method test + */ + + @Test + public void testGetDCAEPriorityValuesData() { + + logger.debug("testGetDCAEPriorityValuesData: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + try{ + controller.getDCAEPriorityValuesData(request, response); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas")); + logger.debug("response: " + response.getContentAsString()); + } catch (Exception e) { + logger.error("testGetDCAEPriorityValuesData", e); + fail("testGetDCAEPriorityValuesData failed due to: " + e); + } + + logger.debug("testGetDCAEPriorityValuesData: exit"); + } + + /** + * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, + * PolicyEntity) method test + */ + + @Test + public void testPrePopulateDCAEMSPolicyData() { + + logger.debug("testPrePopulateDCAEMSPolicyData: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + + // populate an entity object for testing + PolicyEntity entity = new PolicyEntity(); + ConfigurationDataEntity configData = new ConfigurationDataEntity(); + configData.setConfigBody(configBodyString); + entity.setConfigurationData(configData); + + JsonNode root = null; + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + PolicyRestAdapter restAdapter = null; + + try { + root = JsonLoader.fromString(jsonString); + restAdapter = (PolicyRestAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); + PolicyType policyType = new PolicyType(); + TargetType target = new TargetType(); + + // create guard attribute + AnyOfType anyOfType = new AnyOfType(); + AllOfType alltype = new AllOfType(); + MatchType matchType = new MatchType(); + // set value + AttributeValueType attributeValue1 = new AttributeValueType(); + attributeValue1.getContent().add("True"); + matchType.setAttributeValue(attributeValue1); + // set Id + AttributeDesignatorType designator = new AttributeDesignatorType(); + designator.setAttributeId("guard"); + matchType.setAttributeDesignator(designator); + alltype.getMatch().add(matchType); + + // add a dummy MatchType object since while (matchList.size()>1 ...) + MatchType matchDummy = new MatchType(); + // set value + AttributeValueType dummyValue = new AttributeValueType(); + dummyValue.getContent().add("dummy"); + matchDummy.setAttributeValue(dummyValue); + // set Id + AttributeDesignatorType designatorDummy = new AttributeDesignatorType(); + designatorDummy.setAttributeId("dummyId"); + matchDummy.setAttributeDesignator(designatorDummy); + + alltype.getMatch().add(matchDummy); + anyOfType.getAllOf().add(alltype); + + target.getAnyOf().add(anyOfType); + + // create RiskType attribute + AnyOfType anyRiskType = new AnyOfType(); + AllOfType allRiskType = new AllOfType(); + MatchType matchRiskType = new MatchType(); + // set value + AttributeValueType riskTypeValue = new AttributeValueType(); + riskTypeValue.getContent().add("test"); + matchRiskType.setAttributeValue(riskTypeValue); + // set Id + AttributeDesignatorType designatorRiskType = new AttributeDesignatorType(); + designatorRiskType.setAttributeId("RiskType"); + matchRiskType.setAttributeDesignator(designatorRiskType); + allRiskType.getMatch().add(matchRiskType); + + // add a dummy MatchType object since while (matchList.size()>1 ...) + MatchType matchDummy1 = new MatchType(); + // set value + AttributeValueType dummy1Value = new AttributeValueType(); + dummy1Value.getContent().add("dummy"); + matchDummy1.setAttributeValue(dummy1Value); + // set Id + AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType(); + designatorDummy1.setAttributeId("dummyId"); + matchDummy1.setAttributeDesignator(designatorDummy1); + + allRiskType.getMatch().add(matchDummy1); + + anyRiskType.getAllOf().add(allRiskType); + + target.getAnyOf().add(anyRiskType); + + // create RiskLevel attribute + AnyOfType anyRiskLevel = new AnyOfType(); + AllOfType allRiskLevel = new AllOfType(); + MatchType matchRiskLevel = new MatchType(); + // set value + AttributeValueType riskLevel = new AttributeValueType(); + riskLevel.getContent().add("3"); + matchRiskLevel.setAttributeValue(riskLevel); + // set Id + AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType(); + designatorRiskLevel.setAttributeId("RiskLevel"); + matchRiskLevel.setAttributeDesignator(designatorRiskLevel); + allRiskLevel.getMatch().add(matchRiskLevel); + + // add a dummy MatchType object since while (matchList.size()>1 ...) + MatchType matchDummy2 = new MatchType(); + // set value + AttributeValueType dummy2Value = new AttributeValueType(); + dummy2Value.getContent().add("dummy"); + matchDummy2.setAttributeValue(dummy2Value); + // set Id + AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType(); + designatorDummy2.setAttributeId("dummyId"); + matchDummy2.setAttributeDesignator(designatorDummy2); + + allRiskLevel.getMatch().add(matchDummy2); + + anyRiskLevel.getAllOf().add(allRiskLevel); + target.getAnyOf().add(anyRiskLevel); + + policyType.setTarget(target); + + restAdapter.setPolicyData(policyType); + + controller.prePopulateDCAEMSPolicyData(restAdapter, entity); + + logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType()); + logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel()); + logger.error("restAdapter.getGuard() : " + restAdapter.getGuard()); + + assertEquals("True", restAdapter.getGuard()); + assertEquals("3", restAdapter.getRiskLevel()); + assertEquals("test", restAdapter.getRiskType()); + + } catch (Exception e) { + logger.error("testPrePopulateDCAEMSPolicyData", e); + fail("testPrePopulateDCAEMSPolicyData failed due to: " + e); + } + + logger.debug("testPrePopulateDCAEMSPolicyData: exit"); + + } + + /** + * Run the Map convert(String, String) method test + */ + + @Test + public void testConvert(){ + logger.debug("testConvert: enter"); + + String str = "k1=v1,k2=v2,k3=v3"; + String split = ","; + Map result = CreateDcaeMicroServiceController.convert(str, split); + assertTrue(result != null && result.size() == 3); + + logger.debug("testConvert: exit"); + } + + /** + * Run the Map convertMap(Map, + * Map) method test + */ + + @Test + public void testConvertMap(){ + logger.debug("testConvertMap: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + Map attributesMap = new HashMap(); + Map attributesRefMap = new HashMap(); + Map attributesListRefMap = controller.getAttributesListRefMap(); + Map> arrayTextList = controller.getArrayTextList(); + LinkedList list = new LinkedList(); + + attributesMap.put("keyOne", "valueOne"); + attributesMap.put("keyTwo", "valueTwo"); + attributesMap.put("keyThree", "valueThree"); + + attributesRefMap.put("key4", "value4"); + attributesRefMap.put("key5", "value5"); + attributesRefMap.put("key6", "value6"); + + attributesListRefMap.put("key7", "value7"); + + list.add("l1"); + list.add("l2"); + arrayTextList.put("key8", list); + + Map result = controller.convertMap(attributesMap, attributesRefMap); + + assertTrue(result != null && result.size() == 8); + + assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]")); + + logger.debug("testConvertMap: exit"); + } + + /** + * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) + * method test + */ + + //Ignore it for now due to Stream ended unexpectedly + //@Ignore + @Test + public void testSetMSModelData() { + + logger.debug("testSetMSModelData: enter"); + + CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); + + MockHttpServletResponse response = new MockHttpServletResponse(); + + HttpServletRequest request = createMock(HttpServletRequest.class); + expect(request.getContentType()).andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p"); + expect(request.getMethod()).andReturn("post"); + expect(request.getHeader("Content-length")).andReturn("7809"); + + expect(request.getContentLength()).andReturn(7809); + + try { + // value of fileName needs to be matched to your local directory + String fileName = ""; + try { + ClassLoader classLoader = getClass().getClassLoader(); + fileName = new File(classLoader.getResource("schedulerPolicies1707.xmi").getFile()).getAbsolutePath(); + } catch (Exception e1) { + logger.error("Exception Occured while loading file"+e1); + } + expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName)); + expect(request.getCharacterEncoding()).andReturn("UTF-8"); + expect(request.getContentLength()).andReturn(1024); + replay(request); + + controller.SetMSModelData(request, response); + + } catch (Exception e) { + logger.error("testSetMSModelData" + e); + e.printStackTrace(); + } + + //assertTrue(false); + + logger.debug("testSetMSModelData: exit"); + } + + /** + * + * @ Get File Stream + * + */ + private class MockServletInputStream extends ServletInputStream { + + InputStream fis = null; + public MockServletInputStream(String fileName) { + try { + fis = new FileInputStream(fileName); + } catch (Exception genExe) { + genExe.printStackTrace(); + } + } + @Override + public int read() throws IOException { + if(fis.available() > 0) { + return fis.read(); + } + return 0; + } + + @Override + public int read(byte[] bytes, int len, int size) throws IOException { + if(fis.available() > 0) { + int length = fis.read(bytes, len, size); + return length; + } + return -1; + } + @Override + public boolean isFinished() { + return false; + } + @Override + public boolean isReady() { + return false; + } + @Override + public void setReadListener(ReadListener arg0) { + + } + } + +} \ No newline at end of file diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java new file mode 100644 index 000000000..55a2288c7 --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PDPControllerTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.controller; + +import static org.junit.Assert.assertTrue; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.model.Roles; +import org.onap.policy.xacml.api.pap.OnapPDPGroup; +import org.onap.policy.xacml.std.pap.StdPDPGroup; +import org.onap.policy.xacml.std.pap.StdPDPGroupStatus; +import org.springframework.mock.web.MockHttpServletResponse; + + + +public class PDPControllerTest extends Mockito{ + + private static Logger logger = FlexLogger.getLogger(PDPControllerTest.class); + private Set groupsData; + private Set groups; + private static List rolesdata; + + @Before + public void setUp() throws Exception{ + logger.info("setUp: Entering"); + rolesdata = new ArrayList<>(); + Roles roles = new Roles(); + roles.setLoginId("Test"); + roles.setRole("super-admin"); + Roles roles1 = new Roles(); + roles1.setLoginId("Test"); + roles1.setRole("admin"); + roles1.setScope("['com','Test']"); + rolesdata.add(roles); + rolesdata.add(roles1); + + groups = new HashSet<>(); + StdPDPGroup group = new StdPDPGroup(); + group.setId("default"); + group.setDefault(true); + group.setName("default"); + group.setDescription("The default group where new PDP's are put."); + group.setStatus(new StdPDPGroupStatus()); + groups.add(group); + groupsData = new HashSet<>(); + for (OnapPDPGroup g : this.groups) { + groupsData.add(g); + } + } + + @Test + public void testPDPGroupData(){ + HttpServletRequest request = mock(HttpServletRequest.class); + MockHttpServletResponse response = new MockHttpServletResponse(); + PolicyController controller = mock(PolicyController.class); + PDPController pdpController = new PDPController(); + pdpController.setJunit(true);; + pdpController.setPolicyController(controller); + pdpController.setGroupsData(groupsData); + when(controller.getRoles("Test")).thenReturn(rolesdata); + pdpController.getPDPGroupEntityData(request, response); + try { + assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("data")); + } catch (UnsupportedEncodingException e) { + logger.error("Exception Occured"+e); + } + } + +} diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java new file mode 100644 index 000000000..817a624b7 --- /dev/null +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.policy.controller; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.PolicyEntity; + +public class PolicyControllerTest { + + private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class); + private static CommonClassDao commonClassDao; + + @Before + public void setUp() throws Exception{ + logger.info("setUp: Entering"); + commonClassDao = mock(CommonClassDao.class); + List data = new ArrayList<>(); + String policyData = ""; + try { + ClassLoader classLoader = getClass().getClassLoader(); + policyData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")); + } catch (Exception e1) { + e1.printStackTrace(); + } + PolicyEntity entity = new PolicyEntity(); + entity.setPolicyName("Config_SampleTest.1.xml"); + entity.setPolicyData(policyData); + entity.setScope("com"); + data.add(entity); + + when(commonClassDao.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(data); + } + + @Test + public void dummy(){ + System.out.println("Dummy"); + } +} 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 deleted file mode 100644 index 9fd1801ae..000000000 --- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/admin/PolicyManagerServletTest.java +++ /dev/null @@ -1,581 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -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; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -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; -import org.openecomp.policy.rest.jpa.UserInfo; - -public class PolicyManagerServletTest extends Mockito{ - - private static Logger logger = FlexLogger.getLogger(PolicyManagerServletTest.class); - private List headers = new ArrayList(); - - private static List rolesdata; - private static List basePolicyData; - private static List policyEditorScopes; - private static List policyVersion; - private static CommonClassDao commonClassDao; - - @Before - public void setUp() throws Exception{ - logger.info("setUp: Entering"); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId("Test"); - userinfo.setUserName("Test"); - //Roles Data - rolesdata = new ArrayList<>(); - Roles roles = new Roles(); - roles.setLoginId("Test"); - roles.setRole("super-admin"); - Roles roles1 = new Roles(); - roles1.setLoginId("Test"); - roles1.setRole("admin"); - roles1.setScope("['com','Test']"); - rolesdata.add(roles); - rolesdata.add(roles1); - - //PolicyEntity Data - basePolicyData = new ArrayList<>(); - String policyContent = ""; - try { - ClassLoader classLoader = getClass().getClassLoader(); - policyContent = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")); - } catch (Exception e1) { - logger.error("Exception Occured"+e1); - } - PolicyEntity entity = new PolicyEntity(); - entity.setPolicyName("Config_SampleTest.1.xml"); - entity.setPolicyData(policyContent); - entity.setScope("com"); - 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<>(); - PolicyEditorScopes scopes = new PolicyEditorScopes(); - scopes.setScopeName("com"); - scopes.setUserCreatedBy(userinfo); - scopes.setUserModifiedBy(userinfo); - PolicyEditorScopes scopes1 = new PolicyEditorScopes(); - scopes1.setScopeName("com\\Test"); - scopes1.setUserCreatedBy(userinfo); - scopes1.setUserModifiedBy(userinfo); - policyEditorScopes.add(scopes); - policyEditorScopes.add(scopes1); - - //PolicyVersion data - policyVersion = new ArrayList<>(); - PolicyVersion policy = new PolicyVersion(); - policy.setPolicyName("com\\Config_SampleTest1206"); - policy.setActiveVersion(1); - policy.setHigherVersion(1); - policy.setCreatedBy("Test"); - policy.setModifiedBy("Test"); - policyVersion.add(policy); - } - - @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(); - } - } - - @SuppressWarnings("static-access") - @Test - public void testDescribePolicy(){ - PolicyManagerServlet servlet = new PolicyManagerServlet(); - HttpServletRequest request = mock(HttpServletRequest.class); - HttpServletResponse response = mock(HttpServletResponse.class); - PolicyController controller = mock(PolicyController.class); - - 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(basePolicyData); - servlet.setPolicyController(controller); - servlet.doPost(request, response); - } catch (Exception e1) { - logger.error("Exception Occured"+e1); - fail(); - } - } - - - @SuppressWarnings("static-access") - @Test - public void testPolicyScopeList(){ - PolicyManagerServlet servlet = new PolicyManagerServlet(); - HttpServletRequest request = mock(HttpServletRequest.class); - HttpServletResponse response = mock(HttpServletResponse.class); - PolicyController controller = mock(PolicyController.class); - List list = new ArrayList<>(); - list.add("{params: { mode: 'LIST', path: '/', onlyFolders: false}}"); - list.add("{params: { mode: 'LIST', path: '/com', 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 PolicyEditorScopes")).thenReturn(policyEditorScopes); - when(controller.getDataByQuery("from PolicyEditorScopes where SCOPENAME like 'com%'")).thenReturn(policyEditorScopes); - when(controller.getDataByQuery("from PolicyVersion where POLICY_NAME like 'com%'")).thenReturn(policyVersion); - servlet.setPolicyController(controller); - servlet.setTestUserId("Test"); - servlet.doPost(request, response); - } catch (Exception e1) { - logger.error("Exception Occured"+e1); - fail(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editBasePolicyTest(){ - PolicyManagerServlet servlet = new PolicyManagerServlet(); - HttpServletRequest request = mock(HttpServletRequest.class); - HttpServletResponse response = mock(HttpServletResponse.class); - PolicyController controller = mock(PolicyController.class); - List 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editBRMSParamPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editBRMSRawPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editClosedLoopFaultPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editClosedLoopPMPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editMicroServicePolicyTest(){ - GroupPolicyScopeList groupData = new GroupPolicyScopeList(); - groupData.setGroupName("Test"); - groupData.setGroupList("resource=SampleResource,service=SampleService,type=SampleType,closedLoopControlName=SampleClosedLoop"); - List groupListData = new ArrayList<>(); - groupListData.add(groupData); - commonClassDao = mock(CommonClassDao.class); - CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editFirewallPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editActionPolicyTest(){ - List 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 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(); - } - } - } - - @SuppressWarnings("static-access") - @Test - public void editDecisionPolicyTest(){ - List 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 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 deleted file mode 100644 index 07bd54939..000000000 --- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/AdminTabControllerTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.policy.controller; - -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; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.rest.dao.CommonClassDao; -import org.openecomp.policy.rest.jpa.GlobalRoleSettings; -import org.springframework.mock.web.MockHttpServletResponse; - -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"); - List globalRoles = new ArrayList<>(); - globalRoles.add(globalRole); - when(commonClassDao.getData(GlobalRoleSettings.class)).thenReturn(globalRoles); - } - - @Test - public void testGetAdminRole(){ - AdminTabController admin = new AdminTabController(); - 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 deleted file mode 100644 index b4619b852..000000000 --- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/CreateDcaeMicroServiceControllerTest.java +++ /dev/null @@ -1,646 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.controller; - - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import javax.servlet.ReadListener; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.rest.adapter.PolicyRestAdapter; -import org.openecomp.policy.rest.dao.CommonClassDao; -import org.openecomp.policy.rest.jpa.ConfigurationDataEntity; -import org.openecomp.policy.rest.jpa.MicroServiceModels; -import org.openecomp.policy.rest.jpa.PolicyEntity; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.fge.jackson.JsonLoader; - -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; - -/** - * The class CreateDcaeMicroServiceControllerTest contains tests - * for the class {@link CreateDcaeMicroServiceController}* - * - * All JUnits are designed to run in the local development environment - * where they have write privileges and can execute time-sensitive - * tasks. - * - * - * - */ - -public class CreateDcaeMicroServiceControllerTest { - - private static Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceControllerTest.class); - private static CommonClassDao commonClassDao; - private String jsonString = null; - private String configBodyString = null; - private HttpServletRequest request = null; - - @Before - public void setUp() throws Exception { - - logger.info("setUp: Entering"); - commonClassDao = mock(CommonClassDao.class); - List microServiceModelsData = new ArrayList(); - MicroServiceModels testData = new MicroServiceModels(); - testData.setVersion("OpenEcomp-Junit"); - microServiceModelsData.add(testData); - - // mock the getDataById() call - when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "test")).thenReturn(microServiceModelsData); - - jsonString = "{\"policyData\": {\"error\": \"\", \"inprocess\": false,\"model\": {\"name\": \"testingdata\", " - + " \"subScopename\": \"\",\"path\": [],\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\", " - + " \"version\": \"\",\"createdBy\": \"someone\", \"modifiedBy\": \"someone\", \"content\": \"\",\"recursive\": false}," - + " \"tempModel\": {\"name\": \"testingdata\",\"subScopename\": \"\" }," - + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\",\"policyName\": \"may1501\", " - + " \"policyDescription\": \"testing input\", \"ecompName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\",\"riskLevel\": \"2\"," - + " \"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\",\"version\": \"1707.41.02\",\"ruleGridData\": [ [\"fileId\"]],\"ttlDate\": null}}, " - + " \"policyJSON\": {\"pmTableName\": \"test\", \"dmdTopic\": \"1\",\"fileId\": \"56\"} }"; - - configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\",\"templateVersion\":\"1607\",\"version\":\"HD\"," - + "\"priority\":\"2\",\"content\":{\"lastPolled\":\"1\",\"boolen-test\":\"true\",\"created\":\"test\",\"retiredDate\":\"test\",\"scope\":\"SNIRO_PLACEMENT_VDHV\"," - + "\"name\":\"test\",\"lastModified\":\"test\",\"state\":\"CREATED\",\"type\":\"CONFIG\",\"intent\":\"test\",\"target\":\"SNIRO\"}}"; - - request = mock(HttpServletRequest.class); - BufferedReader br = new BufferedReader(new StringReader(jsonString)); - // mock the getReader() call - when(request.getReader()).thenReturn(br); - - logger.info("setUp: exit"); - } - - - /** - * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, - * JsonNode) method test - */ - - @Test - public void testSetDataToPolicyRestAdapter() { - - logger.debug("testSetDataToPolicyRestAdapter: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); - - JsonNode root = null; - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - PolicyRestAdapter policyData = null; - try { - root = JsonLoader.fromString(jsonString); - policyData = (PolicyRestAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); - } catch (Exception e) { - logger.error("testSetDataToPolicyRestAdapter", e); - } - - PolicyRestAdapter result = controller.setDataToPolicyRestAdapter(policyData, root); - assertTrue(result != null && result.getJsonBody() != null && !result.getJsonBody().isEmpty()); - - logger.debug("result.getJsonBody() : " + result.getJsonBody()); - logger.debug("testSetDataToPolicyRestAdapter: exit"); - } - - /** - * Run the void stringBetweenDots(String, String) method test - */ - - @Test - public void testStringBetweenDots() { - - logger.debug("testStringBetweenDots: enter"); - - //expect: uniqueKeys should contain a string value - CreateDcaeMicroServiceController controllerA = new CreateDcaeMicroServiceController(); - String str = "testing\\.byCorrectWay\\.OfDATA"; - assertEquals(1, controllerA.stringBetweenDots(str)); - - //expect: uniqueKeys should not contain a string value - str = "testing\byWrongtWay.\\OfDATA"; - CreateDcaeMicroServiceController controllerB = new CreateDcaeMicroServiceController(); - assertEquals(0, controllerB.stringBetweenDots(str)); - - logger.debug("testStringBetweenDots: exit"); - } - - /** - * Run the Map load(String) method test - */ - - @Test - public void testLoad() { - - logger.debug("testLoad: enter"); - - boolean isLocalTesting = true; - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - String fileName = null; - Map result = null; - try { - ClassLoader classLoader = getClass().getClassLoader(); - fileName = new File(classLoader.getResource("policy_tosca_tca_v1707.yml").getFile()).getAbsolutePath(); - } catch (Exception e1) { - logger.error("Exception Occured while loading file"+e1); - } - if(isLocalTesting){ - try { - result = controller.load(fileName); - } catch (IOException e) { - logger.error("testLoad", e); - result = null; - } - - assertTrue(result != null && !result.isEmpty()); - logger.debug("result : " + result); - } - - logger.debug("testLoad: exit"); - } - - /** - * Run the void parseTosca(String) method test - */ - - @Test - public void testParseTosca() { - - logger.debug("testParseTosca: enter"); - boolean isLocalTesting = true; - String fileName = null; - try { - ClassLoader classLoader = getClass().getClassLoader(); - fileName = new File(classLoader.getResource("policy_tosca_tca_v1707.yml").getFile()).getAbsolutePath(); - } catch (Exception e1) { - logger.error("Exception Occured while loading file"+e1); - } - - CreateDcaeMicroServiceController contoller = new CreateDcaeMicroServiceController(); - if(isLocalTesting){ - try { - contoller.parseTosca(fileName); - }catch (Exception e) { - fail("parseTosca caused error: " + e); - } - } - logger.debug("testParseTosca: exit"); - } - - /** - * Run the ModelAndView getDCAEMSTemplateData(HttpServletRequest, - * HttpServletResponse) method test - */ - - @Test - public void testGetDCAEMSTemplateData() { - - logger.debug("testGetDCAEMSTemplateData: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - MockHttpServletResponse response = new MockHttpServletResponse(); - String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}"; - try { - - CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); - - BufferedReader br = new BufferedReader(new StringReader(msModelJson)); - // mock the getReader() call - when(request.getReader()).thenReturn(br); - - List microServiceModelsData = new ArrayList(); - MicroServiceModels testData = new MicroServiceModels(); - testData.setVersion("1707.4.1.2-Junit"); - microServiceModelsData.add(testData); - // mock the getDataById() call with the same MS model name - when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody")).thenReturn(microServiceModelsData); - - controller.getDCAEMSTemplateData(request, response); - - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("dcaeModelData")); - - logger.debug("response: " + response.getContentAsString()); - - } catch (Exception e) { - logger.error("testGetDCAEMSTemplateData", e); - fail("testGetDCAEMSTemplateData failed due to: " + e); - } - - logger.debug("testGetDCAEMSTemplateData: exit"); - } - - /** - * Run the ModelAndView getModelServiceVersionData(HttpServletRequest, - * HttpServletResponse) method test - */ - - @Test - public void testGetModelServiceVersionData() { - - logger.debug("testGetModelServiceVersionData: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - MockHttpServletResponse response = new MockHttpServletResponse(); - String msModelJson = "{\"policyData\":\"DkatPolicyBody\"}"; - try { - - CreateDcaeMicroServiceController.setCommonClassDao(commonClassDao); - - BufferedReader br = new BufferedReader(new StringReader(msModelJson)); - // mock the getReader() call - when(request.getReader()).thenReturn(br); - - List microServiceModelsData = new ArrayList(); - MicroServiceModels testData = new MicroServiceModels(); - testData.setVersion("1707.4.1.2-Junit"); - microServiceModelsData.add(testData); - - // mock the getDataById() call with the same MS model name - when(commonClassDao.getDataById(MicroServiceModels.class, "modelName", "DkatPolicyBody")).thenReturn(microServiceModelsData); - controller.getModelServiceVersionData(request, response); - - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("1707.4.1.2-Junit")); - - logger.debug("response: " + response.getContentAsString()); - - } catch (Exception e) { - logger.error("testGetModelServiceVersionData", e); - fail("testGetModelServiceVersionData failed due to: " + e); - } - - logger.debug("testGetModelServiceVersionData: exit"); - } - - /** - * Run the void getDCAEPriorityValuesData(HttpServletRequest, - * HttpServletResponse) method test - */ - - @Test - public void testGetDCAEPriorityValuesData() { - - logger.debug("testGetDCAEPriorityValuesData: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - - MockHttpServletRequest request = new MockHttpServletRequest(); - MockHttpServletResponse response = new MockHttpServletResponse(); - try{ - controller.getDCAEPriorityValuesData(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("priorityDatas")); - logger.debug("response: " + response.getContentAsString()); - } catch (Exception e) { - logger.error("testGetDCAEPriorityValuesData", e); - fail("testGetDCAEPriorityValuesData failed due to: " + e); - } - - logger.debug("testGetDCAEPriorityValuesData: exit"); - } - - /** - * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, - * PolicyEntity) method test - */ - - @Test - public void testPrePopulateDCAEMSPolicyData() { - - logger.debug("testPrePopulateDCAEMSPolicyData: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - - // populate an entity object for testing - PolicyEntity entity = new PolicyEntity(); - ConfigurationDataEntity configData = new ConfigurationDataEntity(); - configData.setConfigBody(configBodyString); - entity.setConfigurationData(configData); - - JsonNode root = null; - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - PolicyRestAdapter restAdapter = null; - - try { - root = JsonLoader.fromString(jsonString); - restAdapter = (PolicyRestAdapter)mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class); - PolicyType policyType = new PolicyType(); - TargetType target = new TargetType(); - - // create guard attribute - AnyOfType anyOfType = new AnyOfType(); - AllOfType alltype = new AllOfType(); - MatchType matchType = new MatchType(); - // set value - AttributeValueType attributeValue1 = new AttributeValueType(); - attributeValue1.getContent().add("True"); - matchType.setAttributeValue(attributeValue1); - // set Id - AttributeDesignatorType designator = new AttributeDesignatorType(); - designator.setAttributeId("guard"); - matchType.setAttributeDesignator(designator); - alltype.getMatch().add(matchType); - - // add a dummy MatchType object since while (matchList.size()>1 ...) - MatchType matchDummy = new MatchType(); - // set value - AttributeValueType dummyValue = new AttributeValueType(); - dummyValue.getContent().add("dummy"); - matchDummy.setAttributeValue(dummyValue); - // set Id - AttributeDesignatorType designatorDummy = new AttributeDesignatorType(); - designatorDummy.setAttributeId("dummyId"); - matchDummy.setAttributeDesignator(designatorDummy); - - alltype.getMatch().add(matchDummy); - anyOfType.getAllOf().add(alltype); - - target.getAnyOf().add(anyOfType); - - // create RiskType attribute - AnyOfType anyRiskType = new AnyOfType(); - AllOfType allRiskType = new AllOfType(); - MatchType matchRiskType = new MatchType(); - // set value - AttributeValueType riskTypeValue = new AttributeValueType(); - riskTypeValue.getContent().add("test"); - matchRiskType.setAttributeValue(riskTypeValue); - // set Id - AttributeDesignatorType designatorRiskType = new AttributeDesignatorType(); - designatorRiskType.setAttributeId("RiskType"); - matchRiskType.setAttributeDesignator(designatorRiskType); - allRiskType.getMatch().add(matchRiskType); - - // add a dummy MatchType object since while (matchList.size()>1 ...) - MatchType matchDummy1 = new MatchType(); - // set value - AttributeValueType dummy1Value = new AttributeValueType(); - dummy1Value.getContent().add("dummy"); - matchDummy1.setAttributeValue(dummy1Value); - // set Id - AttributeDesignatorType designatorDummy1 = new AttributeDesignatorType(); - designatorDummy1.setAttributeId("dummyId"); - matchDummy1.setAttributeDesignator(designatorDummy1); - - allRiskType.getMatch().add(matchDummy1); - - anyRiskType.getAllOf().add(allRiskType); - - target.getAnyOf().add(anyRiskType); - - // create RiskLevel attribute - AnyOfType anyRiskLevel = new AnyOfType(); - AllOfType allRiskLevel = new AllOfType(); - MatchType matchRiskLevel = new MatchType(); - // set value - AttributeValueType riskLevel = new AttributeValueType(); - riskLevel.getContent().add("3"); - matchRiskLevel.setAttributeValue(riskLevel); - // set Id - AttributeDesignatorType designatorRiskLevel = new AttributeDesignatorType(); - designatorRiskLevel.setAttributeId("RiskLevel"); - matchRiskLevel.setAttributeDesignator(designatorRiskLevel); - allRiskLevel.getMatch().add(matchRiskLevel); - - // add a dummy MatchType object since while (matchList.size()>1 ...) - MatchType matchDummy2 = new MatchType(); - // set value - AttributeValueType dummy2Value = new AttributeValueType(); - dummy2Value.getContent().add("dummy"); - matchDummy2.setAttributeValue(dummy2Value); - // set Id - AttributeDesignatorType designatorDummy2 = new AttributeDesignatorType(); - designatorDummy2.setAttributeId("dummyId"); - matchDummy2.setAttributeDesignator(designatorDummy2); - - allRiskLevel.getMatch().add(matchDummy2); - - anyRiskLevel.getAllOf().add(allRiskLevel); - target.getAnyOf().add(anyRiskLevel); - - policyType.setTarget(target); - - restAdapter.setPolicyData(policyType); - - controller.prePopulateDCAEMSPolicyData(restAdapter, entity); - - logger.error("restAdapter.getRiskType() : " + restAdapter.getRiskType()); - logger.error("restAdapter.getRiskLevel() : " + restAdapter.getRiskLevel()); - logger.error("restAdapter.getGuard() : " + restAdapter.getGuard()); - - assertEquals("True", restAdapter.getGuard()); - assertEquals("3", restAdapter.getRiskLevel()); - assertEquals("test", restAdapter.getRiskType()); - - } catch (Exception e) { - logger.error("testPrePopulateDCAEMSPolicyData", e); - fail("testPrePopulateDCAEMSPolicyData failed due to: " + e); - } - - logger.debug("testPrePopulateDCAEMSPolicyData: exit"); - - } - - /** - * Run the Map convert(String, String) method test - */ - - @Test - public void testConvert(){ - logger.debug("testConvert: enter"); - - String str = "k1=v1,k2=v2,k3=v3"; - String split = ","; - Map result = CreateDcaeMicroServiceController.convert(str, split); - assertTrue(result != null && result.size() == 3); - - logger.debug("testConvert: exit"); - } - - /** - * Run the Map convertMap(Map, - * Map) method test - */ - - @Test - public void testConvertMap(){ - logger.debug("testConvertMap: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - Map attributesMap = new HashMap(); - Map attributesRefMap = new HashMap(); - Map attributesListRefMap = controller.getAttributesListRefMap(); - Map> arrayTextList = controller.getArrayTextList(); - LinkedList list = new LinkedList(); - - attributesMap.put("keyOne", "valueOne"); - attributesMap.put("keyTwo", "valueTwo"); - attributesMap.put("keyThree", "valueThree"); - - attributesRefMap.put("key4", "value4"); - attributesRefMap.put("key5", "value5"); - attributesRefMap.put("key6", "value6"); - - attributesListRefMap.put("key7", "value7"); - - list.add("l1"); - list.add("l2"); - arrayTextList.put("key8", list); - - Map result = controller.convertMap(attributesMap, attributesRefMap); - - assertTrue(result != null && result.size() == 8); - - assertTrue(arrayTextList.get("key8").toString().contains("[l1, l2]")); - - logger.debug("testConvertMap: exit"); - } - - /** - * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) - * method test - */ - - //Ignore it for now due to Stream ended unexpectedly - //@Ignore - @Test - public void testSetMSModelData() { - - logger.debug("testSetMSModelData: enter"); - - CreateDcaeMicroServiceController controller = new CreateDcaeMicroServiceController(); - - MockHttpServletResponse response = new MockHttpServletResponse(); - - HttpServletRequest request = createMock(HttpServletRequest.class); - expect(request.getContentType()).andReturn("multipart/form-data; boundary=----WebKitFormBoundaryWcRUaIbC8kXgjr3p"); - expect(request.getMethod()).andReturn("post"); - expect(request.getHeader("Content-length")).andReturn("7809"); - - expect(request.getContentLength()).andReturn(7809); - - try { - // value of fileName needs to be matched to your local directory - String fileName = ""; - try { - ClassLoader classLoader = getClass().getClassLoader(); - fileName = new File(classLoader.getResource("schedulerPolicies1707.xmi").getFile()).getAbsolutePath(); - } catch (Exception e1) { - logger.error("Exception Occured while loading file"+e1); - } - expect(request.getInputStream()).andReturn(new MockServletInputStream(fileName)); - expect(request.getCharacterEncoding()).andReturn("UTF-8"); - expect(request.getContentLength()).andReturn(1024); - replay(request); - - controller.SetMSModelData(request, response); - - } catch (Exception e) { - logger.error("testSetMSModelData" + e); - e.printStackTrace(); - } - - //assertTrue(false); - - logger.debug("testSetMSModelData: exit"); - } - - /** - * - * @ Get File Stream - * - */ - private class MockServletInputStream extends ServletInputStream { - - InputStream fis = null; - public MockServletInputStream(String fileName) { - try { - fis = new FileInputStream(fileName); - } catch (Exception genExe) { - genExe.printStackTrace(); - } - } - @Override - public int read() throws IOException { - if(fis.available() > 0) { - return fis.read(); - } - return 0; - } - - @Override - public int read(byte[] bytes, int len, int size) throws IOException { - if(fis.available() > 0) { - int length = fis.read(bytes, len, size); - return length; - } - return -1; - } - @Override - public boolean isFinished() { - return false; - } - @Override - public boolean isReady() { - return false; - } - @Override - public void setReadListener(ReadListener arg0) { - - } - } - -} \ No newline at end of file diff --git a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PDPControllerTest.java b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PDPControllerTest.java deleted file mode 100644 index a27ad4b57..000000000 --- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PDPControllerTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.policy.controller; - -import static org.junit.Assert.assertTrue; - -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -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.model.Roles; -import org.openecomp.policy.xacml.api.pap.EcompPDPGroup; -import org.openecomp.policy.xacml.std.pap.StdPDPGroup; -import org.openecomp.policy.xacml.std.pap.StdPDPGroupStatus; -import org.springframework.mock.web.MockHttpServletResponse; - - - -public class PDPControllerTest extends Mockito{ - - private static Logger logger = FlexLogger.getLogger(PDPControllerTest.class); - private Set groupsData; - private Set groups; - private static List rolesdata; - - @Before - public void setUp() throws Exception{ - logger.info("setUp: Entering"); - rolesdata = new ArrayList<>(); - Roles roles = new Roles(); - roles.setLoginId("Test"); - roles.setRole("super-admin"); - Roles roles1 = new Roles(); - roles1.setLoginId("Test"); - roles1.setRole("admin"); - roles1.setScope("['com','Test']"); - rolesdata.add(roles); - rolesdata.add(roles1); - - groups = new HashSet<>(); - StdPDPGroup group = new StdPDPGroup(); - group.setId("default"); - group.setDefault(true); - group.setName("default"); - group.setDescription("The default group where new PDP's are put."); - group.setStatus(new StdPDPGroupStatus()); - groups.add(group); - groupsData = new HashSet<>(); - for (EcompPDPGroup g : this.groups) { - groupsData.add(g); - } - } - - @Test - public void testPDPGroupData(){ - HttpServletRequest request = mock(HttpServletRequest.class); - MockHttpServletResponse response = new MockHttpServletResponse(); - PolicyController controller = mock(PolicyController.class); - PDPController pdpController = new PDPController(); - pdpController.setJunit(true);; - pdpController.setPolicyController(controller); - pdpController.setGroupsData(groupsData); - when(controller.getRoles("Test")).thenReturn(rolesdata); - pdpController.getPDPGroupEntityData(request, response); - try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("data")); - } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); - } - } - -} diff --git a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PolicyControllerTest.java deleted file mode 100644 index 73f8d755a..000000000 --- a/POLICY-SDK-APP/src/test/java/org/openecomp/policy/controller/PolicyControllerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP Policy Engine - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.policy.controller; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.policy.rest.dao.CommonClassDao; -import org.openecomp.policy.rest.jpa.PolicyEntity; - -public class PolicyControllerTest { - - private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class); - private static CommonClassDao commonClassDao; - - @Before - public void setUp() throws Exception{ - logger.info("setUp: Entering"); - commonClassDao = mock(CommonClassDao.class); - List data = new ArrayList<>(); - String policyData = ""; - try { - ClassLoader classLoader = getClass().getClassLoader(); - policyData = IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")); - } catch (Exception e1) { - e1.printStackTrace(); - } - PolicyEntity entity = new PolicyEntity(); - entity.setPolicyName("Config_SampleTest.1.xml"); - entity.setPolicyData(policyData); - entity.setScope("com"); - data.add(entity); - - when(commonClassDao.getDataByQuery("FROM PolicyEntity where policyName = 'Config_SampleTest1206.1.xml' and scope ='com'")).thenReturn(data); - } - - @Test - public void dummy(){ - System.out.println("Dummy"); - } -} diff --git a/POLICY-SDK-APP/src/test/resources/Action_TestActionPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Action_TestActionPolicy.1.xml index 77c9367aa..82f02e0ff 100644 --- a/POLICY-SDK-APP/src/test/resources/Action_TestActionPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Action_TestActionPolicy.1.xml @@ -4,7 +4,7 @@ - + 12 diff --git a/POLICY-SDK-APP/src/test/resources/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml index ddf1864e4..d66704920 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml @@ -4,33 +4,33 @@ - + com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.xml - + DROOLS - + - + BRMS_PARAM_RULE - + SampleRiskType - + 1 - + False - + 08-06-2017 @@ -66,7 +66,7 @@ 1 - + DROOLS diff --git a/POLICY-SDK-APP/src/test/resources/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml index aa8abc4c9..e9b38cc13 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_BRMS_Raw_TestBRMSRawPolicy.1.xml @@ -4,33 +4,33 @@ - + com.Config_BRMS_Raw_TestBRMSRawPolicy.1.xml - + DROOLS - + - + BRMS_RAW_RULE - + High - + 2 - + True - + 08-06-2017 @@ -66,7 +66,7 @@ 1 - + DROOLS @@ -75,7 +75,7 @@ { "artifactId": "testing", - "groupId" : "org.openecomp" + "groupId" : "org.onap" } diff --git a/POLICY-SDK-APP/src/test/resources/Config_FW_TestFireWallPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Config_FW_TestFireWallPolicy.1.xml index f334cae46..71e3221cb 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_FW_TestFireWallPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_FW_TestFireWallPolicy.1.xml @@ -4,29 +4,29 @@ - + com.Config_FW_TestFireWallPolicy.1.xml - + TestFireWallPolicy - + SampleRiskType - + 1 - + True - + 08-06-2017 @@ -62,7 +62,7 @@ 1 - + diff --git a/POLICY-SDK-APP/src/test/resources/Config_Fault_TestClosedLoopPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Config_Fault_TestClosedLoopPolicy.1.xml index 82be3420e..faeed916c 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_Fault_TestClosedLoopPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_Fault_TestClosedLoopPolicy.1.xml @@ -4,29 +4,29 @@ - + com.Config_Fault_TestClosedLoopPolicy.1.xml - + DCAE - + - + SampleRiskType - + 1 - + True - + 07-06-2017 @@ -62,7 +62,7 @@ 1 - + DCAE diff --git a/POLICY-SDK-APP/src/test/resources/Config_MS_vFirewall.1.xml b/POLICY-SDK-APP/src/test/resources/Config_MS_vFirewall.1.xml index 4fd0b7b5c..ba3d9c215 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_MS_vFirewall.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_MS_vFirewall.1.xml @@ -4,45 +4,45 @@ - + com.Config_MS_vFirewall.1.xml - + DCAE - + - + SampleConfigName - + TcaMetrics-v1.0.0.5 - + /services/cdap-tca-hi-lo/instances/demo/configuration/metricsPerFunctionalRole/vFirewall - + SampleServiceLocation - + SampleRiskType - + 1 - + False - + 07-06-2017 @@ -78,7 +78,7 @@ 1 - + DCAE diff --git a/POLICY-SDK-APP/src/test/resources/Config_PM_TestClosedLoopPMPolicy.1.xml b/POLICY-SDK-APP/src/test/resources/Config_PM_TestClosedLoopPMPolicy.1.xml index ca56cf4f7..370ff365f 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_PM_TestClosedLoopPMPolicy.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_PM_TestClosedLoopPMPolicy.1.xml @@ -4,33 +4,33 @@ - + com.Config_PM_TestClosedLoopPMPolicy.1.xml - + Test - + - + SampleRiskType - + 1 - + True - + 08-06-2017 - + Registration Failure(Trinity) @@ -66,7 +66,7 @@ 1 - + Test diff --git a/POLICY-SDK-APP/src/test/resources/Config_SampleTest1206.1.xml b/POLICY-SDK-APP/src/test/resources/Config_SampleTest1206.1.xml index 5390548d9..dcfd0c5eb 100644 --- a/POLICY-SDK-APP/src/test/resources/Config_SampleTest1206.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Config_SampleTest1206.1.xml @@ -4,33 +4,33 @@ - + com.Config_SampleTest1206.1.xml - + success - + - + PROD - + 1 - + True - + 08-06-2017 - + SampleTest1206 @@ -66,7 +66,7 @@ 1 - + success diff --git a/POLICY-SDK-APP/src/test/resources/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml b/POLICY-SDK-APP/src/test/resources/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml index 74a0e6842..5e8dcac36 100644 --- a/POLICY-SDK-APP/src/test/resources/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml +++ b/POLICY-SDK-APP/src/test/resources/Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml @@ -4,17 +4,17 @@ - + com.Decision_TestDecisionPolicyWithRuleAlgorithms.1.xml - + Test - + - + test diff --git a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt index 955afbd0f..6ff244ea4 100644 --- a/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt +++ b/POLICY-SDK-APP/src/test/resources/com.Config_BRMS_Param_BRMSParamvFWDemoPolicy.1.txt @@ -23,7 +23,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.policy.controlloop; +package org.onap.policy.controlloop; import java.util.List; import java.util.LinkedList; @@ -31,59 +31,59 @@ import java.util.Map; import java.util.HashMap; import java.util.UUID; -import org.openecomp.policy.controlloop.VirtualControlLoopEvent; -import org.openecomp.policy.controlloop.ControlLoopEventStatus; -import org.openecomp.policy.controlloop.VirtualControlLoopNotification; -import org.openecomp.policy.controlloop.ControlLoopNotificationType; -import org.openecomp.policy.controlloop.ControlLoopOperation; -import org.openecomp.policy.controlloop.ControlLoopOperationWrapper; -import org.openecomp.policy.template.demo.ControlLoopException; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.ControlLoopEventStatus; +import org.onap.policy.controlloop.VirtualControlLoopNotification; +import org.onap.policy.controlloop.ControlLoopNotificationType; +import org.onap.policy.controlloop.ControlLoopOperation; +import org.onap.policy.controlloop.ControlLoopOperationWrapper; +import org.onap.policy.template.demo.ControlLoopException; -import org.openecomp.policy.aai.AAINQF199.AAINQF199CloudRegion; -import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperties; -import org.openecomp.policy.aai.AAINQF199.AAINQF199ExtraProperty; -import org.openecomp.policy.aai.AAINQF199.AAINQF199GenericVNF; -import org.openecomp.policy.aai.AAINQF199.AAINQF199InstanceFilters; -import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; -import org.openecomp.policy.aai.AAINQF199.AAINQF199InventoryResponseItems; -import org.openecomp.policy.aai.AAINQF199.AAINQF199Manager; -import org.openecomp.policy.aai.AAINQF199.AAINQF199NamedQuery; -import org.openecomp.policy.aai.AAINQF199.AAINQF199QueryParameters; -import org.openecomp.policy.aai.AAINQF199.AAINQF199Request; -import org.openecomp.policy.aai.AAINQF199.AAINQF199RequestWrapper; -import org.openecomp.policy.aai.AAINQF199.AAINQF199Response; -import org.openecomp.policy.aai.AAINQF199.AAINQF199ResponseWrapper; -import org.openecomp.policy.aai.AAINQF199.AAINQF199ServiceInstance; -import org.openecomp.policy.aai.AAINQF199.AAINQF199Tenant; -import org.openecomp.policy.aai.AAINQF199.AAINQF199VfModule; -import org.openecomp.policy.aai.AAINQF199.AAINQF199VServer; -import org.openecomp.policy.aai.util.Serialization; +import org.onap.policy.aai.AAINQF199.AAINQF199CloudRegion; +import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperties; +import org.onap.policy.aai.AAINQF199.AAINQF199ExtraProperty; +import org.onap.policy.aai.AAINQF199.AAINQF199GenericVNF; +import org.onap.policy.aai.AAINQF199.AAINQF199InstanceFilters; +import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItem; +import org.onap.policy.aai.AAINQF199.AAINQF199InventoryResponseItems; +import org.onap.policy.aai.AAINQF199.AAINQF199Manager; +import org.onap.policy.aai.AAINQF199.AAINQF199NamedQuery; +import org.onap.policy.aai.AAINQF199.AAINQF199QueryParameters; +import org.onap.policy.aai.AAINQF199.AAINQF199Request; +import org.onap.policy.aai.AAINQF199.AAINQF199RequestWrapper; +import org.onap.policy.aai.AAINQF199.AAINQF199Response; +import org.onap.policy.aai.AAINQF199.AAINQF199ResponseWrapper; +import org.onap.policy.aai.AAINQF199.AAINQF199ServiceInstance; +import org.onap.policy.aai.AAINQF199.AAINQF199Tenant; +import org.onap.policy.aai.AAINQF199.AAINQF199VfModule; +import org.onap.policy.aai.AAINQF199.AAINQF199VServer; +import org.onap.policy.aai.util.Serialization; -import org.openecomp.policy.appc.CommonHeader; -import org.openecomp.policy.appc.Request; -import org.openecomp.policy.appc.Response; -import org.openecomp.policy.appc.ResponseCode; -import org.openecomp.policy.appc.ResponseStatus; -import org.openecomp.policy.appc.ResponseValue; +import org.onap.policy.appc.CommonHeader; +import org.onap.policy.appc.Request; +import org.onap.policy.appc.Response; +import org.onap.policy.appc.ResponseCode; +import org.onap.policy.appc.ResponseStatus; +import org.onap.policy.appc.ResponseValue; -import org.openecomp.policy.template.demo.EventManager; -import org.openecomp.policy.vnf.trafficgenerator.PGRequest; -import org.openecomp.policy.vnf.trafficgenerator.PGStream; -import org.openecomp.policy.vnf.trafficgenerator.PGStreams; +import org.onap.policy.template.demo.EventManager; +import org.onap.policy.vnf.trafficgenerator.PGRequest; +import org.onap.policy.vnf.trafficgenerator.PGStream; +import org.onap.policy.vnf.trafficgenerator.PGStreams; -import org.openecomp.policy.mso.MSOManager; -import org.openecomp.policy.mso.MSORequest; -import org.openecomp.policy.mso.MSORequestStatus; -import org.openecomp.policy.mso.MSORequestDetails; -import org.openecomp.policy.mso.MSOModelInfo; -import org.openecomp.policy.mso.MSOCloudConfiguration; -import org.openecomp.policy.mso.MSORequestInfo; -import org.openecomp.policy.mso.MSORequestParameters; -import org.openecomp.policy.mso.MSORelatedInstanceListElement; -import org.openecomp.policy.mso.MSORelatedInstance; -import org.openecomp.policy.mso.MSOResponse; +import org.onap.policy.mso.MSOManager; +import org.onap.policy.mso.MSORequest; +import org.onap.policy.mso.MSORequestStatus; +import org.onap.policy.mso.MSORequestDetails; +import org.onap.policy.mso.MSOModelInfo; +import org.onap.policy.mso.MSOCloudConfiguration; +import org.onap.policy.mso.MSORequestInfo; +import org.onap.policy.mso.MSORequestParameters; +import org.onap.policy.mso.MSORelatedInstanceListElement; +import org.onap.policy.mso.MSORelatedInstance; +import org.onap.policy.mso.MSOResponse; -import org.openecomp.policy.drools.system.PolicyEngine; +import org.onap.policy.drools.system.PolicyEngine; // // These parameters are required to build the runtime policy @@ -106,7 +106,7 @@ end /* * * Called once and only once to insert the parameters into working memory for this Closed Loop policy. -* (Comment SETUP rule out for the first ECOMP opensource release since policy BRMS_GW already puts a Params fact in there) +* (Comment SETUP rule out for the first ONAP opensource release since policy BRMS_GW already puts a Params fact in there) * * *rule "BRMSParamvFWDemoPolicy.SETUP" diff --git a/POLICY-SDK-APP/src/test/resources/com.Config_Fault_TestClosedLoopPolicy.1.json b/POLICY-SDK-APP/src/test/resources/com.Config_Fault_TestClosedLoopPolicy.1.json index f7e25ca47..dbd3649c0 100644 --- a/POLICY-SDK-APP/src/test/resources/com.Config_Fault_TestClosedLoopPolicy.1.json +++ b/POLICY-SDK-APP/src/test/resources/com.Config_Fault_TestClosedLoopPolicy.1.json @@ -1 +1 @@ -{"trinity":false,"vUSP":true,"mcr":false,"gama":false,"vDNS":false,"vnfType":"SampleVNF","vServices":null,"closedLoopPolicyStatus":"Active","triggerSignatures":{"signatures":"((NOT(NOT(1.0.2.3)AND(1.0.2.3)), Time = 11)AND((NOT(1.0.2.3)AND(1.0.2.3)), Time = 12))","timeWindow":11,"trapMaxAge":12},"actions":"SampleVSCL","timeInterval":11,"timeOutvPRO":11,"timeOutRuby":11,"retrys":1,"agingWindow":1,"geoLink":"TEST","emailAddress":"aa@test.con","verificationSignatures":{"signatures":"(NOT(1.0.2.3)AND(1.0.2.3))","timeWindow":12},"conditions":"SEND","triggerSignaturesUsedForUI":{"signatures":"NOT@!SampleVarbind@!AND@!SampleVarbind#!?!NOT@!SampleVarbind@!OR@!SampleVarbind#!NOT@!A1@!AND@!SampleVarbind#!NOT@!A1@!AND@!A2#!?!","connectSignatures":"NOT@!Trap1@!11@!AND@!Trap1@!12#!?!"},"verificationSignaturesUsedForUI":{"signatures":"NOT@!SampleVarbind@!AND@!SampleVarbind#!?!","connectSignatures":null},"triggerTimeWindowUsedForUI":11,"verfificationTimeWindowUsedForUI":12,"pepName":null,"pepAction":null,"templateVersion":null,"trapMaxAgeUsedForUI":12,"ecompname":null} +{"trinity":false,"vUSP":true,"mcr":false,"gama":false,"vDNS":false,"vnfType":"SampleVNF","vServices":null,"closedLoopPolicyStatus":"Active","triggerSignatures":{"signatures":"((NOT(NOT(1.0.2.3)AND(1.0.2.3)), Time = 11)AND((NOT(1.0.2.3)AND(1.0.2.3)), Time = 12))","timeWindow":11,"trapMaxAge":12},"actions":"SampleVSCL","timeInterval":11,"timeOutvPRO":11,"timeOutRuby":11,"retrys":1,"agingWindow":1,"geoLink":"TEST","emailAddress":"aa@test.con","verificationSignatures":{"signatures":"(NOT(1.0.2.3)AND(1.0.2.3))","timeWindow":12},"conditions":"SEND","triggerSignaturesUsedForUI":{"signatures":"NOT@!SampleVarbind@!AND@!SampleVarbind#!?!NOT@!SampleVarbind@!OR@!SampleVarbind#!NOT@!A1@!AND@!SampleVarbind#!NOT@!A1@!AND@!A2#!?!","connectSignatures":"NOT@!Trap1@!11@!AND@!Trap1@!12#!?!"},"verificationSignaturesUsedForUI":{"signatures":"NOT@!SampleVarbind@!AND@!SampleVarbind#!?!","connectSignatures":null},"triggerTimeWindowUsedForUI":11,"verfificationTimeWindowUsedForUI":12,"pepName":null,"pepAction":null,"templateVersion":null,"trapMaxAgeUsedForUI":12,"onapname":null} diff --git a/POLICY-SDK-APP/src/test/resources/logback.xml b/POLICY-SDK-APP/src/test/resources/logback.xml index b119a4e3b..3e5f1b6a6 100644 --- a/POLICY-SDK-APP/src/test/resources/logback.xml +++ b/POLICY-SDK-APP/src/test/resources/logback.xml @@ -1,6 +1,6 @@ + ::= "MSO" | "DCAE" | "ASDC " | "AAI" |"Policy" | "SDNC" | "AC" --> diff --git a/POLICY-SDK-APP/src/test/resources/schedulerPolicies1707.xmi b/POLICY-SDK-APP/src/test/resources/schedulerPolicies1707.xmi index 22afa23a2..2288ae718 100644 --- a/POLICY-SDK-APP/src/test/resources/schedulerPolicies1707.xmi +++ b/POLICY-SDK-APP/src/test/resources/schedulerPolicies1707.xmi @@ -2,61 +2,61 @@ Content-Disposition: form-data; name="file"; filename="schedulerPolicies1707.xmi" - + -
-
+
+
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
@@ -64,48 +64,48 @@ Content-Disposition: form-data; name="file"; filename="schedulerPolicies1707.xmi - +
- +
- +
- +
- +
- +
- +
- +
- +
-- cgit 1.2.3-korg