diff options
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java')
-rw-r--r-- | ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java | 170 |
1 files changed, 92 insertions, 78 deletions
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 7910aed11..1334f96a0 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 @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2019 Samsung + * ================================================================================ * 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. @@ -22,13 +24,10 @@ package org.onap.policy.pap.xacml.rest.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 javax.servlet.http.HttpServletRequest; - import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -40,7 +39,8 @@ 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 Logger logger = + FlexLogger.getLogger(DecisionPolicyDictionaryControllerTest.class); private static CommonClassDao commonClassDao; private String jsonString = null; private HttpServletRequest request = null; @@ -51,21 +51,26 @@ public class DecisionPolicyDictionaryControllerTest { logger.info("setUp: Entering"); commonClassDao = Mockito.mock(CommonClassDao.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)); - - //--- mock the getReader() call - when(request.getReader()).thenReturn(br); - + + // --- mock the getReader() call + when(request.getReader()).thenReturn(br); + controller = new DecisionPolicyDictionaryController(commonClassDao); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); @@ -74,22 +79,22 @@ public class DecisionPolicyDictionaryControllerTest { } @After - public void tearDown() throws Exception { - } + public void tearDown() throws Exception {} @Test public void testGetSettingsDictionaryByNameEntityData() { logger.info("testGetSettingsDictionaryByNameEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getSettingsDictionaryByNameEntityData(request, response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("settingsDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); + logger.error("Exception Occured" + e); fail("Exception: " + e); } @@ -101,15 +106,16 @@ public class DecisionPolicyDictionaryControllerTest { public void testGetSettingsDictionaryEntityData() { logger.info("testGetSettingsDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getSettingsDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("settingsDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+e); + logger.error("Exception Occured" + e); fail("Exception: " + e); } @@ -121,21 +127,24 @@ public class DecisionPolicyDictionaryControllerTest { public void testSaveSettingsDictionary() { logger.info("testSaveSettingsDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + 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\"}"; + 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")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("settingsDictionaryDatas")); } catch (Exception e) { - logger.error("Exception Occured"+e); + logger.error("Exception Occured" + e); fail("Exception: " + e); } @@ -147,130 +156,135 @@ public class DecisionPolicyDictionaryControllerTest { public void testRemoveSettingsDictionary() { logger.info("testRemoveSettingsDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + 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\"} }"; + 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")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("settingsDictionaryDatas")); } catch (Exception e) { - logger.error("Exception Occured"+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(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getRainyDayDictionaryByNameEntityData(request, response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("rainyDayDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+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(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getRainyDayDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("rainyDayDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { - logger.error("Exception Occured"+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(); + 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\"}"; + 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")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("rainyDayDictionaryDatas")); } catch (Exception e) { - logger.error("Exception Occured"+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(); + 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\"} }"; + 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")); - + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("rainyDayDictionaryDatas")); } catch (Exception e) { - logger.error("Exception Occured"+e); + logger.error("Exception Occured" + e); fail("Exception: " + e); } - logger.info("testRemoveRainyDayDictionary: exit"); - } - -}
\ No newline at end of file +} |