X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FDecisionPolicyDictionaryControllerTest.java;h=7910aed11d3fda0a4a13e2502fb1ced38848410d;hb=4068da123ee33b532b4b52f15545c76a978f977e;hp=5290471819c59a8c6d5023ad26460455486c4001;hpb=cc4274f251d7c634cfa2d1dc5bccdd4de9fb1c2b;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java index 529047181..7910aed11 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -35,30 +35,31 @@ 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.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.springframework.mock.web.MockHttpServletResponse; public class DecisionPolicyDictionaryControllerTest { - private static Logger logger = FlexLogger.getLogger(DecisionPolicyDictionaryControllerTest.class); - private static CommonClassDao commonClassDao; - private String jsonString = null; - private HttpServletRequest request = null; - private DecisionPolicyDictionaryController controller = null; - - @Before - public void setUp() throws Exception { - logger.info("setUp: Entering"); + private static Logger logger = FlexLogger.getLogger(DecisionPolicyDictionaryControllerTest.class); + private static CommonClassDao commonClassDao; + private String jsonString = null; + private HttpServletRequest request = null; + private DecisionPolicyDictionaryController controller = null; + + @Before + public void setUp() throws Exception { + logger.info("setUp: Entering"); commonClassDao = Mockito.mock(CommonClassDao.class); - HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - jsonString = "{\"attributeDictionaryDatas\": {\"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\"} }"; + jsonString = "{\"attributeDictionaryDatas\": {\"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\"} }"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); @@ -66,208 +67,210 @@ public class DecisionPolicyDictionaryControllerTest { when(request.getReader()).thenReturn(br); controller = new DecisionPolicyDictionaryController(commonClassDao); - + new DictionaryUtils(commonClassDao); + DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); + mock(DictionaryUtils.class); logger.info("setUp: exit"); - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testGetSettingsDictionaryByNameEntityData() { - logger.info("testGetSettingsDictionaryByNameEntityData: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - - controller.getSettingsDictionaryByNameEntityData(request, response); - - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testGetSettingsDictionaryByNameEntityData: exit"); - - } - - @Test - public void testGetSettingsDictionaryEntityData() { - logger.info("testGetSettingsDictionaryEntityData: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - - controller.getSettingsDictionaryEntityData(response); - - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testGetSettingsDictionaryEntityData: exit"); - - } - - @Test - public void testSaveSettingsDictionary() { - logger.info("testSaveSettingsDictionary: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - request = mock(HttpServletRequest.class); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testGetSettingsDictionaryByNameEntityData() { + logger.info("testGetSettingsDictionaryByNameEntityData: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + + controller.getSettingsDictionaryByNameEntityData(request, response); + + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + } catch (UnsupportedEncodingException e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testGetSettingsDictionaryByNameEntityData: exit"); + + } + + @Test + public void testGetSettingsDictionaryEntityData() { + logger.info("testGetSettingsDictionaryEntityData: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + + controller.getSettingsDictionaryEntityData(response); + + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + } catch (UnsupportedEncodingException e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testGetSettingsDictionaryEntityData: exit"); + + } + + @Test + public void testSaveSettingsDictionary() { + logger.info("testSaveSettingsDictionary: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + request = mock(HttpServletRequest.class); - try { - // mock the getReader() call - jsonString = "{\"settingsDictionaryData\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}, \"userid\":\"test\"}"; - - BufferedReader br = new BufferedReader(new StringReader(jsonString)); - when(request.getReader()).thenReturn(br); - controller.saveSettingsDictionary(request, response); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); - - } catch (Exception e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testSaveSettingsDictionary: exit"); - - } - - @Test - public void testRemoveSettingsDictionary() { - logger.info("testRemoveSettingsDictionary: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - request = mock(HttpServletRequest.class); - - try { - // mock the getReader() call - jsonString = "{\"data\": {\"modelName\": \"test\", \"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\"} }"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); - when(request.getReader()).thenReturn(br); - controller.removeSettingsDictionary(request, response); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); - - } catch (Exception e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testRemoveSettingsDictionary: exit"); - - } - - @Test - public void testGetRainyDayDictionaryByNameEntityData() { - logger.info("testGetRainyDayDictionaryByNameEntityData: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - - controller.getRainyDayDictionaryByNameEntityData(request, response); - - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testGetRainyDayDictionaryByNameEntityData: exit"); - - } - - @Test - public void testGetRainyDayDictionaryEntityData() { - logger.info("testGetRainyDayDictionaryEntityData: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - - controller.getRainyDayDictionaryEntityData(request, response); - - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testGetRainyDayDictionaryEntityData: exit"); - - } - - @Test - public void testSaveRainyDayDictionary() { - logger.info("testSaveRainyDayDictionary: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - request = mock(HttpServletRequest.class); + try { + // mock the getReader() call + jsonString = "{\"settingsDictionaryData\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}, \"userid\":\"test\"}"; + + BufferedReader br = new BufferedReader(new StringReader(jsonString)); + when(request.getReader()).thenReturn(br); + controller.saveSettingsDictionary(request, response); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + + } catch (Exception e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testSaveSettingsDictionary: exit"); + + } + + @Test + public void testRemoveSettingsDictionary() { + logger.info("testRemoveSettingsDictionary: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + request = mock(HttpServletRequest.class); + + try { + // mock the getReader() call + jsonString = "{\"data\": {\"modelName\": \"test\", \"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\"} }"; + BufferedReader br = new BufferedReader(new StringReader(jsonString)); + when(request.getReader()).thenReturn(br); + controller.removeSettingsDictionary(request, response); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + + } catch (Exception e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testRemoveSettingsDictionary: exit"); + + } + + @Test + public void testGetRainyDayDictionaryByNameEntityData() { + logger.info("testGetRainyDayDictionaryByNameEntityData: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + + controller.getRainyDayDictionaryByNameEntityData(request, response); + + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + } catch (UnsupportedEncodingException e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testGetRainyDayDictionaryByNameEntityData: exit"); + + } + + @Test + public void testGetRainyDayDictionaryEntityData() { + logger.info("testGetRainyDayDictionaryEntityData: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + + controller.getRainyDayDictionaryEntityData(response); + + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + } catch (UnsupportedEncodingException e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testGetRainyDayDictionaryEntityData: exit"); + + } + + @Test + public void testSaveRainyDayDictionary() { + logger.info("testSaveRainyDayDictionary: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + request = mock(HttpServletRequest.class); - try { - // mock the getReader() call - jsonString = "{\"rainyDayDictionaryData\":{\"bbid\":\"BB2\",\"workstep\":\"1\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:233\",\"treatment\":\"test1\"},{\"$$hashKey\":\"object:239\",\"treatment\":\"test2\"}]},\"userid\":\"mm117s\"}"; - - BufferedReader br = new BufferedReader(new StringReader(jsonString)); - when(request.getReader()).thenReturn(br); - controller.saveRainyDayDictionary(request, response); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); - - } catch (Exception e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testSaveRainyDayDictionary: exit"); - - } - - @Test - public void testRemoveRainyDayDictionary() { - logger.info("testRemoveRainyDayDictionary: Entering"); - - MockHttpServletResponse response = new MockHttpServletResponse(); - request = mock(HttpServletRequest.class); - - try { - // mock the getReader() call - jsonString = "{\"data\": {\"modelName\": \"test\", \"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\"} }"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); - when(request.getReader()).thenReturn(br); - controller.removeRainyDayDictionary(request, response); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); - - } catch (Exception e) { - logger.error("Exception Occured"+e); - fail("Exception: " + e); - } - - logger.info("testRemoveRainyDayDictionary: exit"); - - } + try { + // mock the getReader() call + jsonString = "{\"rainyDayDictionaryData\":{\"bbid\":\"BB2\",\"workstep\":\"1\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:233\",\"treatment\":\"test1\"},{\"$$hashKey\":\"object:239\",\"treatment\":\"test2\"}]},\"userid\":\"mm117s\"}"; + + BufferedReader br = new BufferedReader(new StringReader(jsonString)); + when(request.getReader()).thenReturn(br); + controller.saveRainyDayDictionary(request, response); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + + } catch (Exception e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testSaveRainyDayDictionary: exit"); + + } + + @Test + public void testRemoveRainyDayDictionary() { + logger.info("testRemoveRainyDayDictionary: Entering"); + + MockHttpServletResponse response = new MockHttpServletResponse(); + request = mock(HttpServletRequest.class); + + try { + // mock the getReader() call + jsonString = "{\"data\": {\"modelName\": \"test\", \"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\"} }"; + BufferedReader br = new BufferedReader(new StringReader(jsonString)); + when(request.getReader()).thenReturn(br); + controller.removeRainyDayDictionary(request, response); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + + } catch (Exception e) { + logger.error("Exception Occured"+e); + fail("Exception: " + e); + } + + logger.info("testRemoveRainyDayDictionary: exit"); + + } } \ No newline at end of file