summaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2018-03-05 22:59:30 -0500
committerPamela Dragosh <pdragosh@research.att.com>2018-03-06 13:38:12 +0000
commit51eb4945ce94e88c5f315ffe9469a9daa3512cd9 (patch)
tree6b82c2a8148e8809a7b2f0a6fbbcf7626ccd73ea /POLICY-SDK-APP/src
parent0ca791ec99d07b563cc28949d205c29b663437c1 (diff)
Added Junits for POLICY-SDK-APP
Issue-ID: POLICY-600 Change-Id: Ib96b7ccede0fa09e71f02ff073c89682e9aa7089 Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'POLICY-SDK-APP/src')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java6
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java92
2 files changed, 93 insertions, 5 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
index 9498529af..4d549fea2 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
@@ -1123,7 +1123,11 @@ public class PolicyManagerServlet extends HttpServlet {
SimpleBindings peParams = new SimpleBindings();
peParams.put("oldPolicySplit_1", oldPolicySplit[1]);
peParams.put("oldPolicySplit_0", oldPolicySplit[0]);
- queryData = controller.getDataByQuery(policyEntityquery, peParams);
+ if(PolicyController.isjUnit()){
+ queryData = controller.getDataByQuery(policyEntityquery, null);
+ }else{
+ queryData = controller.getDataByQuery(policyEntityquery, peParams);
+ }
if(!queryData.isEmpty()){
entity = (PolicyEntity) queryData.get(0);
}
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<Object> policyEditorScopes;
private static List<Object> 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<BufferedReader> 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.size(); i++){
+ try {
+ when(request.getReader()).thenReturn(readers.get(i));
+ PolicyManagerServlet.setPolicyController(controller);
+ servlet.doPost(request, response);
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("success"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void testClone(){
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ PolicyController controller = mock(PolicyController.class);
+ List<BufferedReader> 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.size(); i++){
+ try {
+ when(request.getReader()).thenReturn(readers.get(i));
+ PolicyManagerServlet.setPolicyController(controller);
+ servlet.doPost(request, response);
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("success"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void testRename(){
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ PolicyController controller = mock(PolicyController.class);
+ List<BufferedReader> 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.size(); i++){
+ try {
+ when(request.getReader()).thenReturn(readers.get(i));
+ PolicyManagerServlet.setPolicyController(controller);
+ servlet.doPost(request, response);
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("success"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
+
+ @Test
+ public void testRenameScope(){
+ PolicyManagerServlet servlet = new PolicyManagerServlet();
+ PolicyController controller = mock(PolicyController.class);
+ List<BufferedReader> readers = new ArrayList<>();
+ readers.add(new BufferedReader(new StringReader("{params: { mode: 'RENAME', path: 'com', newPath: 'Test'}}")));
+ for(int i=0; i<readers.size(); i++){
+ try {
+ when(request.getReader()).thenReturn(readers.get(i));
+ PolicyManagerServlet.setPolicyController(controller);
+ servlet.doPost(request, response);
+ assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("success"));
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ fail();
+ }
+ }
+ }
}