From 51eb4945ce94e88c5f315ffe9469a9daa3512cd9 Mon Sep 17 00:00:00 2001 From: rb7147 Date: Mon, 5 Mar 2018 22:59:30 -0500 Subject: Added Junits for POLICY-SDK-APP Issue-ID: POLICY-600 Change-Id: Ib96b7ccede0fa09e71f02ff073c89682e9aa7089 Signed-off-by: rb7147 --- .../policy/admin/PolicyManagerServletTest.java | 92 +++++++++++++++++++++- 1 file changed, 88 insertions(+), 4 deletions(-) (limited to 'POLICY-SDK-APP/src/test/java/org') 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 index be0a92e55..06a2bb98e 100644 --- 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 @@ -31,7 +31,6 @@ import java.util.List; import javax.servlet.ServletConfig; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.io.IOUtils; @@ -53,6 +52,7 @@ import org.onap.policy.rest.jpa.PolicyVersion; import org.onap.policy.rest.jpa.UserInfo; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.util.SystemProperties; +import org.springframework.mock.web.MockHttpServletResponse; public class PolicyManagerServletTest extends Mockito{ @@ -64,15 +64,16 @@ public class PolicyManagerServletTest extends Mockito{ private static List policyEditorScopes; private static List policyVersion; private static CommonClassDao commonClassDao; + private ConfigurationDataEntity configurationEntity; private HttpServletRequest request; - private HttpServletResponse response; + private MockHttpServletResponse response; @Before public void setUp() throws Exception{ logger.info("setUp: Entering"); request = mock(HttpServletRequest.class); - response = mock(HttpServletResponse.class); + response = new MockHttpServletResponse(); PolicyController.setjUnit(true); UserInfo userinfo = new UserInfo(); @@ -103,7 +104,7 @@ public class PolicyManagerServletTest extends Mockito{ entity.setPolicyName("Config_SampleTest.1.xml"); entity.setPolicyData(policyContent); entity.setScope("com"); - ConfigurationDataEntity configurationEntity = new ConfigurationDataEntity(); + configurationEntity = new ConfigurationDataEntity(); configurationEntity.setConfigBody("Sample Test"); configurationEntity.setConfigType("OTHER"); configurationEntity.setConfigurationName("com.Config_SampleTest1206.1.txt"); @@ -139,6 +140,7 @@ public class PolicyManagerServletTest extends Mockito{ user.setOrgUserId("Test"); Mockito.when(mockSession.getAttribute(SystemProperties.getProperty("user_attribute_name"))).thenReturn(user); Mockito.when(request.getSession(false)).thenReturn(mockSession); + commonClassDao = mock(CommonClassDao.class); } @@ -608,4 +610,86 @@ public class PolicyManagerServletTest extends Mockito{ } } } + + @Test + public void testAddScope(){ + PolicyManagerServlet servlet = new PolicyManagerServlet(); + PolicyController controller = mock(PolicyController.class); + List readers = new ArrayList<>(); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'ADDFOLDER', path: '/', name: 'Test'}}"))); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'ADDFOLDER', path: '/', name: 'Test*&'}}"))); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'ADDFOLDER', path: '/Test', subScopename: 'Test1'}}"))); + for(int i=0; i readers = new ArrayList<>(); + when(controller.getEntityItem(ConfigurationDataEntity.class, "configurationName", "com.Config_SampleTest1206.1.txt")).thenReturn(configurationEntity); + when(controller.getDataByQuery("FROM PolicyEntity where policyName = :oldPolicySplit_1 and scope = :oldPolicySplit_0", null)).thenReturn(basePolicyData); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'COPY', path: 'com.Config_test.1.xml', newPath: 'com.Config_testClone.1.xml'}}"))); + for(int i=0; i readers = new ArrayList<>(); + when(controller.getEntityItem(ConfigurationDataEntity.class, "configurationName", "com.Config_SampleTest1206.1.txt")).thenReturn(configurationEntity); + when(controller.getDataByQuery("FROM PolicyEntity where policyName = :oldPolicySplit_1 and scope = :oldPolicySplit_0", null)).thenReturn(basePolicyData); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'RENAME', path: 'com.Config_test.1.xml', newPath: 'com.Config_testClone.1.xml'}}"))); + for(int i=0; i readers = new ArrayList<>(); + readers.add(new BufferedReader(new StringReader("{params: { mode: 'RENAME', path: 'com', newPath: 'Test'}}"))); + for(int i=0; i