diff options
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller')
13 files changed, 891 insertions, 613 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java index efb13b5a0..eccf13ba7 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -57,8 +58,8 @@ public class ActionPolicyDictionaryControllerTest { public void setUp() throws Exception { logger.info("setUp: Entering"); commonClassDao = Mockito.mock(CommonClassDao.class); - List<String> data = new ArrayList<>(); - List<Object> objectData = new ArrayList<>(); + List<String> data = new ArrayList<>(); + List<Object> objectData = new ArrayList<>(); data.add("Test"); UserInfo userInfo = new UserInfo(); @@ -71,9 +72,9 @@ public class ActionPolicyDictionaryControllerTest { actionData.setBody("Test"); assertTrue("Test".equals(actionData.getBody())); actionData.setCreatedDate(new Date()); - assertTrue(actionData.getCreatedDate()!= null); + assertTrue(actionData.getCreatedDate() != null); actionData.setModifiedDate(new Date()); - assertTrue(actionData.getModifiedDate()!= null); + assertTrue(actionData.getModifiedDate() != null); actionData.setHeader("Test"); assertTrue("Test".equals(actionData.getHeader())); actionData.setMethod("POST"); @@ -83,9 +84,9 @@ public class ActionPolicyDictionaryControllerTest { actionData.setUrl("http://test.com"); assertTrue("http://test.com".equals(actionData.getUrl())); actionData.setUserCreatedBy(userInfo); - assertTrue(actionData.getUserCreatedBy()!= null); + assertTrue(actionData.getUserCreatedBy() != null); actionData.setUserModifiedBy(userInfo); - assertTrue(actionData.getUserModifiedBy()!= null); + assertTrue(actionData.getUserModifiedBy() != null); objectData.add(actionData); when(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName")).thenReturn(data); @@ -95,7 +96,7 @@ public class ActionPolicyDictionaryControllerTest { controller = new ActionPolicyDictionaryController(); controller.setCommonClassDao(commonClassDao); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); @@ -103,60 +104,78 @@ public class ActionPolicyDictionaryControllerTest { } @Test - public void testGetActionEntitybyName(){ + public void testGetActionEntitybyName() { controller.getActionEntitybyName(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("actionPolicyDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetActionPolicyDictionaryEntityData(){ + public void testGetActionPolicyDictionaryEntityData() { controller.getActionPolicyDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("actionPolicyDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testSaveActionPolicyDictionary(){ - jsonString = "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveActionPolicyDictionary() { + jsonString = + "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":" + + "\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\"," + + "\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"}," + + "\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveActionPolicyDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("actionPolicyDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateActionPolicyDictionary(){ - jsonString = "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateActionPolicyDictionary() { + jsonString = + "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":" + + "\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":" + + "\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http://test.com\"}," + + "\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveActionPolicyDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("actionPolicyDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveActionPolicyDictionary(){ - jsonString = "{\"data\":{\"$$hashKey\":\"uiGrid-003S\",\"attributeName\":\"Test\",\"body\":\"{}\",\"createdDate\":1518195117000,\"description\":\"test\",\"header\":\"test=12\",\"id\":1,\"method\":\"GET\",\"modifiedDate\":1518195489000,\"type\":\"REST\",\"url\":\"http://test.com\",\"userCreatedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"},\"userModifiedBy\":{\"userLoginId\":\"demo\",\"userName\":\"Demo\"}}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testRemoveActionPolicyDictionary() { + jsonString = + "{\"data\":{\"$$hashKey\":\"uiGrid-003S\",\"attributeName\":\"Test\",\"body\":\"{}\",\"createdDate\":" + + "1518195117000,\"description\":\"test\",\"header\":\"test=12\",\"id\":1,\"method\":\"GET\"," + + "\"modifiedDate\":1518195489000,\"type\":\"REST\",\"url\":\"http://test.com\",\"userCreatedBy\":" + + "{\"userLoginId\":\"demo\",\"userName\":\"Demo\"},\"userModifiedBy\":{\"userLoginId\":\"demo\"," + + "\"userName\":\"Demo\"}}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeActionPolicyDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("actionPolicyDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java index d34e505ba..7d260907b 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -40,7 +41,7 @@ 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.onap.policy.rest.jpa.BRMSParamTemplate; +import org.onap.policy.rest.jpa.BrmsParamTemplate; import org.onap.policy.rest.jpa.UserInfo; import org.springframework.mock.web.MockHttpServletResponse; @@ -61,14 +62,14 @@ public class BRMSDictionaryControllerTest { userInfo.setUserLoginId("testUserId"); userInfo.setUserName("John"); when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo); - List<String> brms = new ArrayList<String>(); + List<String> brms = new ArrayList<String>(); brms.add("BRMS-Model"); - when(commonClassDao.getDataByColumn(BRMSParamTemplate.class, "name")).thenReturn(brms); - doNothing().when(commonClassDao).delete(new BRMSParamTemplate()); - doNothing().when(commonClassDao).save(new BRMSParamTemplate()); + when(commonClassDao.getDataByColumn(BrmsParamTemplate.class, "name")).thenReturn(brms); + doNothing().when(commonClassDao).delete(new BrmsParamTemplate()); + doNothing().when(commonClassDao).save(new BrmsParamTemplate()); controller = new BRMSDictionaryController(); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); @@ -76,12 +77,13 @@ public class BRMSDictionaryControllerTest { } @Test - public void testGetBRMSParamDictionaryByNameEntityData(){ + public void testGetBRMSParamDictionaryByNameEntityData() { logger.info("testGetBRMSParamDictionaryByNameEntityData: Entering"); BRMSDictionaryController.setCommonClassDao(commonClassDao); controller.getBRMSParamDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsParamDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -94,7 +96,8 @@ public class BRMSDictionaryControllerTest { logger.info("testGetBRMSParamDictionaryEntityData: Entering"); controller.getBRMSParamDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsParamDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -105,14 +108,16 @@ public class BRMSDictionaryControllerTest { @Test public void testSaveBRMSParamDictionary() { logger.info("testSaveBRMSParamDictionary: Entering"); - jsonString = "{\"brmsParamDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + jsonString = + "{\"brmsParamDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveBRMSParamDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryData")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsParamDictionaryData")); logger.info("response.getContentAsString(): " + response.getContentAsString()); - }catch(Exception e){ - logger.error("Exception"+ e); + } catch (Exception e) { + logger.error("Exception" + e); } logger.info("testSaveBRMSParamDictionary: exit"); } @@ -121,11 +126,12 @@ public class BRMSDictionaryControllerTest { public void testRemoveBRMSParamDictionary() { logger.info("testRemoveBRMSParamDictionary: Entering"); jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeBRMSParamDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsParamDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } @@ -133,12 +139,13 @@ public class BRMSDictionaryControllerTest { } @Test - public void testGetBRMSDependencyDictionaryByNameEntityData(){ + public void testGetBRMSDependencyDictionaryByNameEntityData() { logger.info("testGetBRMSDependencyDictionaryByNameEntityData: Entering"); BRMSDictionaryController.setCommonClassDao(commonClassDao); controller.getBRMSDependencyDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -147,12 +154,13 @@ public class BRMSDictionaryControllerTest { } @Test - public void testGetBRMSDependencyDictionaryEntityData(){ + public void testGetBRMSDependencyDictionaryEntityData() { logger.info("testGetBRMSDependencyDictionaryEntityData: Entering"); BRMSDictionaryController.setCommonClassDao(commonClassDao); controller.getBRMSDependencyDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -164,13 +172,16 @@ public class BRMSDictionaryControllerTest { @Test public void testSaveBRMSDependencyDictionary() { logger.info("testSaveBRMSDependencyDictionary: Entering"); - jsonString = "{\"brmsDependencyDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ - when(request.getReader()).thenReturn(br); - controller.saveBRMSDependencyDictionary(request, response); - logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryData")); - } catch (Exception e) { + jsonString = + "{\"brmsDependencyDictionaryData\": " + + "{\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { + when(request.getReader()).thenReturn(br); + controller.saveBRMSDependencyDictionary(request, response); + logger.info("response.getContentAsString(): " + response.getContentAsString()); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsDependencyDictionaryData")); + } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveBRMSDependencyDictionary: exit"); @@ -179,14 +190,15 @@ public class BRMSDictionaryControllerTest { @Test public void testRemoveBRMSDependencyDictionary() { logger.info("testRemoveBRMSDependencyDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeBRMSDependencyDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsDependencyDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } @@ -194,13 +206,14 @@ public class BRMSDictionaryControllerTest { } @Test - public void testGetBRMSControllerDictionaryByNameEntityData(){ + public void testGetBRMSControllerDictionaryByNameEntityData() { logger.info("testGetBRMSControllerDictionaryByNameEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); BRMSDictionaryController.setCommonClassDao(commonClassDao); controller.getBRMSControllerDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsControllerDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -209,13 +222,14 @@ public class BRMSDictionaryControllerTest { } @Test - public void testGetBRMSControllerDictionaryEntityData(){ + public void testGetBRMSControllerDictionaryEntityData() { logger.info("testGetBRMSControllerDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); BRMSDictionaryController.setCommonClassDao(commonClassDao); controller.getBRMSControllerDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsControllerDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -227,14 +241,17 @@ public class BRMSDictionaryControllerTest { public void testSaveBRMSControllerDictionary() { logger.info("testSaveBRMSControllerDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); - jsonString = "{\"brmsControllerDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + jsonString = + "{\"brmsControllerDictionaryData\": " + + "{\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveBRMSControllerDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryData")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsControllerDictionaryData")); } catch (Exception e) { fail("Exception: " + e); } @@ -244,14 +261,15 @@ public class BRMSDictionaryControllerTest { @Test public void testRemoveBRMSControllerDictionary() { logger.info("testRemoveBRMSControllerDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); jsonString = "{\"data\": {\"ruleName\": \"test\",\"rule\": \"test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeBRMSControllerDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("brmsControllerDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("brmsControllerDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -259,4 +277,3 @@ public class BRMSDictionaryControllerTest { logger.info("testRemoveBRMSControllerDictionary: exit"); } } - diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java index f530b4c62..8f0d52b21 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -41,10 +42,10 @@ import org.onap.policy.pap.xacml.rest.util.DictionaryUtils; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ClosedLoopD2Services; import org.onap.policy.rest.jpa.ClosedLoopSite; -import org.onap.policy.rest.jpa.PEPOptions; +import org.onap.policy.rest.jpa.PepOptions; import org.onap.policy.rest.jpa.UserInfo; -import org.onap.policy.rest.jpa.VNFType; -import org.onap.policy.rest.jpa.VSCLAction; +import org.onap.policy.rest.jpa.VnfType; +import org.onap.policy.rest.jpa.VsclAction; import org.onap.policy.rest.jpa.VarbindDictionary; import org.springframework.mock.web.MockHttpServletResponse; @@ -57,7 +58,7 @@ public class ClosedLoopDictionaryControllerTest { private ClosedLoopDictionaryController controller = null; private MockHttpServletResponse response = null; private UserInfo userInfo; - private List<String> data; + private List<String> data; @Before public void setUp() throws Exception { @@ -71,14 +72,14 @@ public class ClosedLoopDictionaryControllerTest { userInfo.setUserLoginId("Test"); userInfo.setUserName("Test"); - doNothing().when(commonClassDao).delete(new VSCLAction()); - doNothing().when(commonClassDao).save(new VSCLAction()); + doNothing().when(commonClassDao).delete(new VsclAction()); + doNothing().when(commonClassDao).save(new VsclAction()); controller = new ClosedLoopDictionaryController(); controller.setCommonClassDao(commonClassDao); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); @@ -86,362 +87,404 @@ public class ClosedLoopDictionaryControllerTest { } @Test - public void testGetVSCLActionDictionaryByNameEntityData(){ - when(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")).thenReturn(data); + public void testGetVSCLActionDictionaryByNameEntityData() { + when(commonClassDao.getDataByColumn(VsclAction.class, "vsclaction")).thenReturn(data); controller.getVSCLActionDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vsclActionDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetVSCLActionDictionaryEntityData(){ - when(commonClassDao.getData(VSCLAction.class)).thenReturn(new ArrayList<>()); + public void testGetVSCLActionDictionaryEntityData() { + when(commonClassDao.getData(VsclAction.class)).thenReturn(new ArrayList<>()); controller.getVSCLActionDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vsclActionDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetVNFTypeDictionaryByNameEntityData(){ - when(commonClassDao.getDataByColumn(VNFType.class, "vnftype")).thenReturn(data); + public void testGetVNFTypeDictionaryByNameEntityData() { + when(commonClassDao.getDataByColumn(VnfType.class, "vnftype")).thenReturn(data); controller.getVNFTypeDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vnfTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetVNFTypeDictionaryEntityData(){ - when(commonClassDao.getData(VNFType.class)).thenReturn(new ArrayList<>()); + public void testGetVNFTypeDictionaryEntityData() { + when(commonClassDao.getData(VnfType.class)).thenReturn(new ArrayList<>()); controller.getVNFTypeDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vnfTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPEPOptionsDictionaryByNameEntityData(){ - when(commonClassDao.getDataByColumn(PEPOptions.class, "pepName")).thenReturn(data); + public void testGetPEPOptionsDictionaryByNameEntityData() { + when(commonClassDao.getDataByColumn(PepOptions.class, "pepName")).thenReturn(data); controller.getPEPOptionsDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("pepOptionsDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPEPOptionsDictionaryEntityData(){ - when(commonClassDao.getData(PEPOptions.class)).thenReturn(new ArrayList<>()); + public void testGetPEPOptionsDictionaryEntityData() { + when(commonClassDao.getData(PepOptions.class)).thenReturn(new ArrayList<>()); controller.getPEPOptionsDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("pepOptionsDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetVarbindDictionaryByNameEntityData(){ + public void testGetVarbindDictionaryByNameEntityData() { when(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")).thenReturn(data); controller.getVarbindDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("varbindDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetVarbindDictionaryEntityData(){ + public void testGetVarbindDictionaryEntityData() { when(commonClassDao.getData(VarbindDictionary.class)).thenReturn(new ArrayList<>()); controller.getVarbindDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("varbindDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetClosedLoopServiceDictionaryByNameEntityData(){ + public void testGetClosedLoopServiceDictionaryByNameEntityData() { when(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")).thenReturn(data); controller.getClosedLoopServiceDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopServiceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetClosedLoopServiceDictionaryEntityData(){ + public void testGetClosedLoopServiceDictionaryEntityData() { when(commonClassDao.getData(ClosedLoopD2Services.class)).thenReturn(new ArrayList<>()); controller.getClosedLoopServiceDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopServiceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetClosedLoopSiteDictionaryByNameEntityData(){ + public void testGetClosedLoopSiteDictionaryByNameEntityData() { when(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")).thenReturn(data); controller.getClosedLoopSiteDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetClosedLoopSiteDictionaryEntityData(){ + public void testGetClosedLoopSiteDictionaryEntityData() { when(commonClassDao.getData(ClosedLoopSite.class)).thenReturn(new ArrayList<>()); controller.getClosedLoopSiteDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testSaveVSCLAction(){ - jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveVSCLAction() { + jsonString = + "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVSCLAction(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vsclActionDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateVSCLAction(){ - jsonString = "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateVSCLAction() { + jsonString = + "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVSCLAction(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vsclActionDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveVSCLAction(){ + public void testRemoveVSCLAction() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeVSCLAction(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vsclActionDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vsclActionDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSaveVnfType(){ + public void testSaveVnfType() { jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"description\":\"test\",\"vnftype\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVnfType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vnfTypeDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateVnfType(){ - jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateVnfType() { + jsonString = + "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVnfType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vnfTypeDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveVnfType(){ + public void testRemoveVnfType() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeVnfType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("vnfTypeDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("vnfTypeDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSavePEPOptions(){ - jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSavePEPOptions() { + jsonString = + "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePEPOptions(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("pepOptionsDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePEPOptions(){ - jsonString = "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdatePEPOptions() { + jsonString = + "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePEPOptions(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("pepOptionsDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePEPOptions(){ - jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testRemovePEPOptions() { + jsonString = + "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePEPOptions(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("pepOptionsDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("pepOptionsDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSaveServiceType(){ - jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveServiceType() { + jsonString = + "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveServiceType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopServiceDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateServiceType(){ - jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateServiceType() { + jsonString = + "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveServiceType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopServiceDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveServiceType(){ + public void testRemoveServiceType() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeServiceType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopServiceDictionaryData")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSaveSiteType(){ - jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveSiteType() { + jsonString = + "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveSiteType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateSiteType(){ - jsonString = "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateSiteType() { + jsonString = + "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveSiteType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveSiteType(){ + public void testRemoveSiteType() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeSiteType(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("closedLoopSiteDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSaveVarbind(){ - jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveVarbind() { + jsonString = + "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVarbind(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("varbindDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateVarbind(){ - jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateVarbind() { + jsonString = + "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVarbind(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("varbindDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveVarbind(){ + public void testRemoveVarbind() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeVarbind(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("varbindDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } } 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 1334f96a0..30d6d52bc 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-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (C) 2019 Samsung * ================================================================================ @@ -19,16 +19,19 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + 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; import org.mockito.Mockito; @@ -39,8 +42,7 @@ 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; @@ -52,19 +54,18 @@ public class DecisionPolicyDictionaryControllerTest { 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)); @@ -78,9 +79,6 @@ public class DecisionPolicyDictionaryControllerTest { logger.info("setUp: exit"); } - @After - public void tearDown() throws Exception {} - @Test public void testGetSettingsDictionaryByNameEntityData() { logger.info("testGetSettingsDictionaryByNameEntityData: Entering"); @@ -235,10 +233,9 @@ public class DecisionPolicyDictionaryControllerTest { 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); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java index 0950b1cfd..f12299334 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -53,7 +54,7 @@ public class DescriptiveDictionaryControllerTest { private DescriptiveDictionaryController controller = null; private MockHttpServletResponse response = null; private UserInfo userInfo; - private List<String> data; + private List<String> data; @Before public void setUp() throws Exception { @@ -74,15 +75,15 @@ public class DescriptiveDictionaryControllerTest { controller.setCommonClassDao(commonClassDao); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); logger.info("setUp: exit"); } - public List<Object> testDescriptiveScope(){ - List<Object> objectData = new ArrayList<>(); + public List<Object> testDescriptiveScope() { + List<Object> objectData = new ArrayList<>(); DescriptiveScope data = new DescriptiveScope(); data.setId(1); @@ -94,75 +95,89 @@ public class DescriptiveDictionaryControllerTest { data.setSearch("Test"); assertTrue("Test".equals(data.getSearch())); data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); + assertTrue(data.getCreatedDate() != null); data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); + assertTrue(data.getModifiedDate() != null); data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); + assertTrue(data.getUserCreatedBy() != null); data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); + assertTrue(data.getUserModifiedBy() != null); objectData.add(data); return objectData; } @Test - public void testGetDescriptiveDictionaryByNameEntityData(){ + public void testGetDescriptiveDictionaryByNameEntityData() { when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data); controller.getDescriptiveDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetDescriptiveDictionaryEntityData(){ + public void testGetDescriptiveDictionaryEntityData() { when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope()); controller.getDescriptiveDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testSaveDescriptiveDictionary(){ - jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveDescriptiveDictionary() { + jsonString = + "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":" + + "\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\"," + + "\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveDescriptiveDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateDescriptiveDictionary(){ - jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdateDescriptiveDictionary() { + jsonString = + "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":" + + "\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\"," + + "\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveDescriptiveDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveDescriptiveDictionary(){ - jsonString = "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testRemoveDescriptiveDictionary() { + jsonString = + "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\"," + + "\"option\":\"test\"}],\"description\":\"test\",\"descriptiveScopeName\":\"Test\",\"id\":1," + + "\"search\":\"Test\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeDescriptiveDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } -}
\ No newline at end of file +} diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java index 89be75f52..52b79b88f 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -18,7 +18,6 @@ * ============LICENSE_END========================================================= */ - package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -70,12 +69,12 @@ public class DictionaryControllerTest { commonClassDao = Mockito.mock(CommonClassDao.class); MicroServiceModels testData = new MicroServiceModels(); - testData.setVersion("1707.4.1.2-Junit"); + testData.setVersion("1707.4.1.2-Junit"); - //--- mock the getDataByColumn() call - List<String> microList = new ArrayList<String>(); + // --- mock the getDataByColumn() call + List<String> microList = new ArrayList<String>(); microList.add("123"); - List<Object> listId = new ArrayList<Object>(); + List<Object> listId = new ArrayList<Object>(); when(commonClassDao.getDataByColumn(Attribute.class, "xacmlId")).thenReturn(microList); List<Object> object = new ArrayList<>(); object.add(new Category()); @@ -83,9 +82,9 @@ public class DictionaryControllerTest { PolicyEditorScopes editorScope = new PolicyEditorScopes(); doNothing().when(commonClassDao).save(editorScope); doNothing().when(commonClassDao).update(editorScope); - + when(commonClassDao.getData(Attribute.class)).thenReturn(listId); - + request = mock(HttpServletRequest.class); controller = new DictionaryController(commonClassDao); new DictionaryUtils(commonClassDao); @@ -98,12 +97,13 @@ public class DictionaryControllerTest { public void testGetAttributeDictionaryEntityDatabyAttributeName() { logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getAttributeDictionaryEntityDatabyAttributeName(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -116,12 +116,13 @@ public class DictionaryControllerTest { public void testGetAttributeDictionaryEntityData() { logger.info("testGetAttributeDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getAttributeDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -134,16 +135,22 @@ public class DictionaryControllerTest { public void testSaveAttributeDictionary() { logger.info("testSaveAttributeDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); - + try { - jsonString = "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":\"Qwerty\"},\"userid\":\"demo\"}"; + jsonString = + "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":" + + "\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":" + + "\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":" + + "\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":" + + "\"Qwerty\"},\"userid\":\"demo\"}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -156,16 +163,17 @@ public class DictionaryControllerTest { public void testRemoveAttributeDictionary() { logger.info("testRemoveAttributeDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"xacmlId\":\"Test\"}}"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); + BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -178,12 +186,13 @@ public class DictionaryControllerTest { public void testGetOnapNameDictionaryByNameEntityData() { logger.info("testGetOnapNameDictionaryByNameEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getOnapNameDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -196,12 +205,13 @@ public class DictionaryControllerTest { public void testGetOnapNameDictionaryEntityData() { logger.info("testGetOnapNameDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getOnapNameDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -215,16 +225,18 @@ public class DictionaryControllerTest { logger.info("testSaveOnapDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); - + try { - jsonString = "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveOnapDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -237,16 +249,17 @@ public class DictionaryControllerTest { public void testRemoveOnapDictionary() { logger.info("testRemoveOnapDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"onapName\":\"Test\"}}"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); + BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeOnapDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java index 7ab1b170e..ee4dff803 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -42,7 +43,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.springframework.mock.web.MockHttpServletResponse; -public class DictionaryImportControllerTest extends Mockito{ +public class DictionaryImportControllerTest extends Mockito { private static Logger logger = FlexLogger.getLogger(DictionaryImportController.class); @@ -59,20 +60,20 @@ public class DictionaryImportControllerTest extends Mockito{ controller = new DictionaryImportController(); new DictionaryImportController(commonClassDao); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); } @Test - public void testIsValidDictionaryName(){ + public void testIsValidDictionaryName() { DictionaryImportController cotroller = new DictionaryImportController(); - //test invalid name + // test invalid name assertTrue(!cotroller.isValidDictionaryName("wrong-name")); - //test valid name + // test valid name assertTrue(cotroller.isValidDictionaryName("ActionList")); } @Test - public void testImportDictionaryData() throws ServletException, IOException{ + public void testImportDictionaryData() throws ServletException, IOException { List<String> fileNames = new ArrayList<>(); fileNames.add("Attribute.csv"); fileNames.add("ActionPolicyDictionary.csv"); @@ -95,13 +96,13 @@ public class DictionaryImportControllerTest extends Mockito{ fileNames.add("SearchCriteria.csv"); fileNames.add("VNFType.csv"); fileNames.add("VSCLAction.csv"); - fileNames.add("PEPOptions.csv"); + fileNames.add("PepOptions.csv"); fileNames.add("Settings.csv"); fileNames.add("Zone.csv"); fileNames.add("ActionList.csv"); - for(int i =0; i < fileNames.size(); i++){ - File file = new File("src/test/resources/dictionaryImport/"+fileNames.get(i)); - try(FileInputStream targetStream = new FileInputStream(file)){ + for (int i = 0; i < fileNames.size(); i++) { + File file = new File("src/test/resources/dictionaryImport/" + fileNames.get(i)); + try (FileInputStream targetStream = new FileInputStream(file)) { PushPolicyControllerTest pushController = new PushPolicyControllerTest(); when(request.getInputStream()).thenReturn(pushController.getInputStream(getBytes(targetStream))); when(request.getParameter("userId")).thenReturn("demo"); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java index 45d8466b6..3359a7aed 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -46,8 +47,8 @@ import org.onap.policy.rest.adapter.Term; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionList; import org.onap.policy.rest.jpa.AddressGroup; -import org.onap.policy.rest.jpa.FWTag; -import org.onap.policy.rest.jpa.FWTagPicker; +import org.onap.policy.rest.jpa.FwTag; +import org.onap.policy.rest.jpa.FwTagPicker; import org.onap.policy.rest.jpa.FirewallDictionaryList; import org.onap.policy.rest.jpa.GroupServiceList; import org.onap.policy.rest.jpa.PortList; @@ -117,7 +118,8 @@ public class FirewallDictionaryControllerTest { @Test public void testGetProtocolListDictionaryEntityDataByName() { - test_WithGetDataByColumn(ProtocolList.class, "protocolListDictionaryDatas", "protocolName", + test_WithGetDataByColumn(ProtocolList.class, + "protocolListDictionaryDatas", "protocolName", () -> controller.getProtocolListDictionaryEntityDataByName(response)); } @@ -195,7 +197,8 @@ public class FirewallDictionaryControllerTest { @Test public void testGetZoneDictionaryEntityData() { - test_WithGetData(Zone.class, "zoneDictionaryDatas", () -> controller.getZoneDictionaryEntityData(response)); + test_WithGetData(Zone.class, "zoneDictionaryDatas", () -> + controller.getZoneDictionaryEntityData(response)); } @Test @@ -212,7 +215,8 @@ public class FirewallDictionaryControllerTest { @Test public void testGetFWDictListDictionaryEntityDataByName() { - test_WithGetDataByColumn(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName", + test_WithGetDataByColumn(FirewallDictionaryList.class, + "fwDictListDictionaryDatas", "parentItemName", () -> controller.getFWDictListDictionaryEntityDataByName(response)); } @@ -224,37 +228,41 @@ public class FirewallDictionaryControllerTest { @Test public void testGetTagPickerNameEntityDataByName() { - test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + test_WithGetDataByColumn(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.getTagPickerNameEntityDataByName(response)); } @Test public void testGetTagPickerDictionaryEntityData() { - test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas", + test_WithGetData(FwTagPicker.class, "fwTagPickerDictionaryDatas", () -> controller.getTagPickerDictionaryEntityData(response)); } @Test public void testGetTagNameEntityDataByName() { - test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + test_WithGetDataByColumn(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.getTagNameEntityDataByName(response)); } @Test public void testGetTagDictionaryEntityData() { - test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response)); + test_WithGetData(FwTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response)); } @Test public void testSavePrefixListDictionary() { - jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"description\":\"test\",\"prefixListName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"prefixListDictionaryData\":" + + "{\"description\":\"test\",\"prefixListName\":\"Test\"}}"; testSave(PrefixList.class, "prefixListDictionaryDatas", "prefixListName", () -> controller.savePrefixListDictionary(request, response)); } @Test public void testUpdatePrefixListDictionary() { - jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":" + + "\"test\",\"prefixListName\":\"Test\"}}"; testUpdate(PrefixList.class, "prefixListDictionaryDatas", "prefixListName", () -> controller.savePrefixListDictionary(request, response)); } @@ -268,20 +276,25 @@ public class FirewallDictionaryControllerTest { @Test public void testValidatePrefixListDictionary() { - jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}"; + jsonString = + "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":" + + "\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}"; testValidate(PrefixList.class, "result", () -> controller.validatePrefixListDictionary(request, response)); } @Test public void testSavePortListDictionary() { - jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}"; testSave(PortList.class, "portListDictionaryDatas", "portName", () -> controller.savePortListDictionary(request, response)); } @Test public void testUpdatePortListDictionary() { - jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":" + + "\"test\",\"portName\":\"Test\"}}"; testUpdate(PortList.class, "portListDictionaryDatas", "portName", () -> controller.savePortListDictionary(request, response)); } @@ -295,14 +308,18 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveProtocolListDictionary() { - jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":" + + "\"Test\"}}"; testSave(ProtocolList.class, "protocolListDictionaryDatas", "protocolName", () -> controller.saveProtocolListDictionary(request, response)); } @Test public void testUpdateProtocolListDictionary() { - jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":" + + "\"test\",\"protocolName\":\"Test\"}}"; testUpdate(ProtocolList.class, "protocolListDictionaryDatas", "protocolName", () -> controller.saveProtocolListDictionary(request, response)); } @@ -316,14 +333,20 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveAddressGroupDictionary() { - jsonString = "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":" + + "\"Test\"},\"userid\":\"demo\"}"; testSave(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test", () -> controller.saveAddressGroupDictionary(request, response)); } @Test public void testUpdateAddressGroupDictionary() { - jsonString = "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":" + + "\"demo\"}"; testUpdate(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test", () -> controller.saveAddressGroupDictionary(request, response)); } @@ -337,14 +360,18 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveActionListDictionary() { - jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":" + + "\"Test\"}}"; testSave(ActionList.class, "actionListDictionaryDatas", "actionName", () -> controller.saveActionListDictionary(request, response)); } @Test public void testUpdateActionListDictionary() { - jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":" + + "\"Test\"}}"; testUpdate(ActionList.class, "actionListDictionaryDatas", "actionName", () -> controller.saveActionListDictionary(request, response)); } @@ -358,14 +385,18 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveServiceGroupDictionary() { - jsonString = "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}"; testSave(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test", () -> controller.saveServiceGroupDictionary(request, response)); } @Test public void testUpdateServiceGroupDictionary() { - jsonString = "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}"; testUpdate(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test", () -> controller.saveServiceGroupDictionary(request, response)); } @@ -379,14 +410,18 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveSecurityZoneDictionary() { - jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":" + + "\"Test\"}}"; testSave(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName", () -> controller.saveSecurityZoneDictionary(request, response)); } @Test public void testUpdateSecurityZoneDictionary() { - jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":" + + "\"Test\"}}"; testUpdate(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName", () -> controller.saveSecurityZoneDictionary(request, response)); } @@ -400,21 +435,33 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveServiceListDictionary() { - jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + jsonString = + "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":" + + "\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; testSave(ServiceList.class, "serviceListDictionaryDatas", "serviceName", () -> controller.saveServiceListDictionary(request, response)); } @Test public void testUpdateServiceListDictionary() { - jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + jsonString = + "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":" + + "\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; testUpdate(ServiceList.class, "serviceListDictionaryDatas", "serviceName", () -> controller.saveServiceListDictionary(request, response)); } @Test public void testRemoveServiceListDictionary() { - jsonString = "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + jsonString = + "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":" + + "\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":" + + "\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":" + + "\"Test\"}]},\"userid\":\"demo\"}"; testRemove(ServiceList.class, "serviceListDictionaryDatas", () -> controller.removeServiceListDictionary(request, response)); } @@ -422,12 +469,14 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveZoneDictionary() { jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}"; - testSave(Zone.class, "zoneDictionaryDatas", "zoneName", () -> controller.saveZoneDictionary(request, response)); + testSave(Zone.class, "zoneDictionaryDatas", "zoneName", () + -> controller.saveZoneDictionary(request, response)); } @Test public void testUpdateZoneDictionary() { - jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}"; testUpdate(Zone.class, "zoneDictionaryDatas", "zoneName", () -> controller.saveZoneDictionary(request, response)); } @@ -440,14 +489,34 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveTermListDictionary() { - jsonString = "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + jsonString = + "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":" + + "\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":" + + "[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":" + + "[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":" + + "[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":" + + "\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":" + + "\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":" + + "\"Test\"}]},\"userid\":\"demo\"}"; testSave(TermList.class, "termListDictionaryDatas", "termName", () -> controller.saveTermListDictionary(request, response)); } @Test public void testUpdateTermListDictionary() { - jsonString = "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + jsonString = + "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":" + + "\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":" + + "[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":" + + "[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":" + + "[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":" + + "\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":" + + "\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":" + + "\"Test\"}]},\"userid\":\"demo\"}"; testUpdate(TermList.class, "termListDictionaryDatas", "termName", () -> controller.saveTermListDictionary(request, response)); } @@ -461,14 +530,22 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveFWDictionaryList() { - jsonString = "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":" + + "\"demo\"}"; testSave(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName", () -> controller.saveFWDictionaryList(request, response)); } @Test public void testUpdateFWDictionaryList() { - jsonString = "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}"; + jsonString = + "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":" + + "\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":" + + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":" + + "\"demo\"}"; testUpdate(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName", () -> controller.saveFWDictionaryList(request, response)); } @@ -482,43 +559,53 @@ public class FirewallDictionaryControllerTest { @Test public void testSaveFirewallTagPickerDictionary() { - jsonString = "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; - testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + jsonString = + "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":" + + "\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":" + + "\"Test\"}]},\"userid\":\"demo\"}"; + testSave(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.saveFirewallTagPickerDictionary(request, response)); } @Test public void testUpdateFirewallTagPickerDictionary() { - jsonString = "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; - testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", + jsonString = + "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":" + + "\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":" + + "\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}"; + testUpdate(FwTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName", () -> controller.saveFirewallTagPickerDictionary(request, response)); } @Test public void testRemoveFirewallTagPickerDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}"; - testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas", + testRemove(FwTagPicker.class, "fwTagPickerDictionaryDatas", () -> controller.removeFirewallTagPickerDictionary(request, response)); } @Test public void testSaveFirewallTagDictionary() { - jsonString = "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; - testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + jsonString = + "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":" + + "\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; + testSave(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.saveFirewallTagDictionary(request, response)); } @Test public void testUpdateFirewallTagDictionary() { - jsonString = "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; - testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName", + jsonString = + "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":" + + "[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}"; + testUpdate(FwTag.class, "fwTagDictionaryDatas", "fwTagName", () -> controller.saveFirewallTagDictionary(request, response)); } @Test public void testRemoveFirewallTagDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}"; - testRemove(FWTag.class, "fwTagDictionaryDatas", + testRemove(FwTag.class, "fwTagDictionaryDatas", () -> controller.removeFirewallTagDictionary(request, response)); } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java index e561a65b2..115e30249 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryControllerTest.java @@ -20,7 +20,6 @@ * ============LICENSE_END========================================================= */ - package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -28,12 +27,15 @@ import static org.junit.Assert.fail; import static org.mockito.Mockito.doNothing; 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.mockito.Mockito; @@ -41,7 +43,7 @@ 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.onap.policy.rest.jpa.DCAEuuid; +import org.onap.policy.rest.jpa.DcaeUuid; import org.onap.policy.rest.jpa.MicroServiceLocation; import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.UserInfo; @@ -75,7 +77,7 @@ public class MicroServiceDictionaryControllerTest { List<String> listIds = new ArrayList<String>(); listIds.add("Jack"); - when(commonClassDao.getDataByColumn(DCAEuuid.class, "name")).thenReturn(listIds); + when(commonClassDao.getDataByColumn(DcaeUuid.class, "name")).thenReturn(listIds); List<String> microList = new ArrayList<String>(); microList.add("MC-Model"); @@ -83,7 +85,7 @@ public class MicroServiceDictionaryControllerTest { List<Object> listId = new ArrayList<Object>(); listId.add("smith"); - when(commonClassDao.getData(DCAEuuid.class)).thenReturn(listId); + when(commonClassDao.getData(DcaeUuid.class)).thenReturn(listId); MicroServiceModels microServiceModels = new MicroServiceModels(); doNothing().when(commonClassDao).delete(microServiceModels); @@ -141,7 +143,6 @@ public class MicroServiceDictionaryControllerTest { logger.info("testSaveMicroServiceHeaderDefaultValues: exit"); } - @Test public void testGetMicroServiceHeaderDefaultsEntityDataByName() { logger.info("testGetMicroServiceHeaderDefaultsEntityDataByName: Entering"); @@ -215,7 +216,6 @@ public class MicroServiceDictionaryControllerTest { logger.info("testRemoveMicroServiceHeaderDefaults: exit"); } - @Test public void testGetDCAEUUIDDictionaryByNameEntityData() { diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java index 5e0b7ce28..f109dbdda 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryControllerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (C) 2019 Samsung * ================================================================================ @@ -19,19 +19,23 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; + +import com.mockrunner.mock.web.MockHttpServletRequest; 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 javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -39,14 +43,10 @@ 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.onap.policy.rest.jpa.DCAEuuid; -import org.onap.policy.rest.jpa.MicroServiceLocation; -import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.OptimizationModels; import org.onap.policy.rest.jpa.UserInfo; import org.springframework.mock.web.MockHttpServletResponse; - public class OptimizationDictionaryControllerTest { private static Logger logger = FlexLogger.getLogger(OptimizationDictionaryControllerTest.class); @@ -63,8 +63,7 @@ public class OptimizationDictionaryControllerTest { UserInfo userInfo = new UserInfo(); userInfo.setUserLoginId("testUserId"); userInfo.setUserName("John"); - when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")) - .thenReturn(userInfo); + when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo); OptimizationModels optimziationModels = new OptimizationModels(); @@ -76,19 +75,17 @@ public class OptimizationDictionaryControllerTest { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); - jsonString = - "{\"optimizationModelsDictionaryData\": {\"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\"," - + "\"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\"}}"; + jsonString = "{\"optimizationModelsDictionaryData\": {\"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\"," + + "\"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\"}}"; br = new BufferedReader(new StringReader(jsonString)); // --- mock the getReader() call @@ -115,7 +112,7 @@ public class OptimizationDictionaryControllerTest { controller.getOptimizationModelsDictionaryEntityData(response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -137,7 +134,7 @@ public class OptimizationDictionaryControllerTest { controller.saveOptimizationModelsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -156,28 +153,58 @@ public class OptimizationDictionaryControllerTest { 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\"," - + "\"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\"}}"; + "{\"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\"," + + "\"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\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeOptimizationModelsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null - && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); + && response.getContentAsString().contains("optimizationModelsDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testRemoveOptimizationModelsDictionary: exit"); } + + @Test + public void testGet() { + OptimizationDictionaryController controller = new OptimizationDictionaryController(commonClassDao); + MockHttpServletResponse response = new MockHttpServletResponse(); + controller.getOptimizationModelsDictionaryByNameEntityData(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + } + + @Test + public void testSave() { + OptimizationDictionaryController controller = new OptimizationDictionaryController(commonClassDao); + MockHttpServletRequest req = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + req.setBodyContent("{\n\"modelType\": \"type.yml\", \"dataOrderInfo\": \"info\", \"userid\": \"id\", " + + "\"optimizationModelsDictionaryData\": {\"description\": \"desc\", \"modelName\": \"name\", \"version\": \"1.0\"}, " + + "\"classMap\": \"{\\\"dep\\\":\\\"{\\\"dependency\\\":\\\"depval\\\"}\\\"}\" }\n"); + assertThatThrownBy(() -> controller.saveOptimizationModelsDictionary(req, response)) + .isInstanceOf(NullPointerException.class); + + req.setBodyContent("{\n\"modelType\": \"type.xml\", \"dataOrderInfo\": \"info\", \"userid\": \"id\", " + + "\"optimizationModelsDictionaryData\": {\"description\": \"desc\", \"modelName\": \"name\", \"version\": \"1.0\"}, " + + "\"classMap\": \"{\\\"dep\\\": {\\\"dependency\\\":\\\"depval\\\"} }\" }\n"); + assertThatCode(() -> controller.saveOptimizationModelsDictionary(req, response)).doesNotThrowAnyException(); + + req.setupAddParameter("apiflag", "api"); + assertThatThrownBy(() -> controller.saveOptimizationModelsDictionary(req, response)) + .isInstanceOf(NullPointerException.class); + } + } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java index 9bf2ae590..f8273493b 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -55,7 +56,7 @@ public class PolicyScopeDictionaryControllerTest { private PolicyScopeDictionaryController controller = null; private MockHttpServletResponse response = null; private UserInfo userInfo; - private List<String> data; + private List<String> data; @Before public void setUp() throws Exception { @@ -76,7 +77,7 @@ public class PolicyScopeDictionaryControllerTest { controller.setCommonClassDao(commonClassDao); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); @@ -84,302 +85,339 @@ public class PolicyScopeDictionaryControllerTest { } @Test - public void testGetGroupPolicyScopeEntityDataByName(){ + public void testGetGroupPolicyScopeEntityDataByName() { when(commonClassDao.getDataByColumn(GroupPolicyScopeList.class, "name")).thenReturn(data); controller.getGroupPolicyScopeEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("groupPolicyScopeListDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetGroupPolicyScopeEntityData(){ + public void testGetGroupPolicyScopeEntityData() { when(commonClassDao.getData(GroupPolicyScopeList.class)).thenReturn(new ArrayList<>()); controller.getGroupPolicyScopeEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("groupPolicyScopeListDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSClosedLoopEntityDataByName(){ + public void testGetPSClosedLoopEntityDataByName() { when(commonClassDao.getDataByColumn(PolicyScopeClosedLoop.class, "name")).thenReturn(data); controller.getPSClosedLoopEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSClosedLoopEntityData(){ + public void testGetPSClosedLoopEntityData() { when(commonClassDao.getData(PolicyScopeClosedLoop.class)).thenReturn(new ArrayList<>()); controller.getPSClosedLoopEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSServiceEntityDataByName(){ + public void testGetPSServiceEntityDataByName() { when(commonClassDao.getDataByColumn(PolicyScopeService.class, "name")).thenReturn(data); controller.getPSServiceEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psServiceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSServiceEntityData(){ + public void testGetPSServiceEntityData() { when(commonClassDao.getData(PolicyScopeService.class)).thenReturn(new ArrayList<>()); controller.getPSServiceEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psServiceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSTypeEntityDataByName(){ + public void testGetPSTypeEntityDataByName() { when(commonClassDao.getDataByColumn(PolicyScopeType.class, "name")).thenReturn(data); controller.getPSTypeEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSTypeEntityData(){ + public void testGetPSTypeEntityData() { when(commonClassDao.getData(PolicyScopeType.class)).thenReturn(new ArrayList<>()); controller.getPSTypeEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSResourceEntityDataByName(){ + public void testGetPSResourceEntityDataByName() { when(commonClassDao.getDataByColumn(PolicyScopeResource.class, "name")).thenReturn(data); controller.getPSResourceEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psResourceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetPSResourceEntityData(){ + public void testGetPSResourceEntityData() { when(commonClassDao.getData(PolicyScopeResource.class)).thenReturn(new ArrayList<>()); controller.getPSResourceEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psResourceDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testSavePSGroupScopeDictionary(){ - jsonString = "{\"groupPolicyScopeListData\":{\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSavePSGroupScopeDictionary() { + jsonString = + "{\"groupPolicyScopeListData\":{\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSGroupScopeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("groupPolicyScopeListDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePSGroupScopeDictionary(){ - jsonString = "{\"groupPolicyScopeListData\":{\"id\":1,\"description\":\"test\",\"groupName\":\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdatePSGroupScopeDictionary() { + jsonString = + "{\"groupPolicyScopeListData\":{\"id\":1,\"description\":\"test\",\"groupName\":" + + "\"Test\"},\"groupPolicyScopeListData1\":{\"closedloop\":\"SampleClosedLoop\",\"resource\":" + + "\"SampleResource\",\"service\":\"SampleService\",\"type\":\"SampleType\"},\"userid\":\"demo\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSGroupScopeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("groupPolicyScopeListDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePSGroupScopeDictionary(){ + public void testRemovePSGroupScopeDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePSGroupScopeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("groupPolicyScopeListDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("groupPolicyScopeListDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSavePSClosedLoopDictionary(){ - jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSavePSClosedLoopDictionary() { + jsonString = + "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":" + + "\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSClosedLoopDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePSClosedLoopDictionary(){ - jsonString = "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdatePSClosedLoopDictionary() { + jsonString = + "{\"userid\":\"demo\",\"psClosedLoopDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSClosedLoopDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePSClosedLoopDictionary(){ + public void testRemovePSClosedLoopDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePSClosedLoopDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psClosedLoopDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSavePSServiceDictionary(){ - jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSavePSServiceDictionary() { + jsonString = + "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":" + + "\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSServiceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psServiceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePSServiceDictionary(){ + public void testUpdatePSServiceDictionary() { jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSServiceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psServiceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePSServiceDictionary(){ + public void testRemovePSServiceDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePSServiceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psServiceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSavePSTypeDictionary(){ + public void testSavePSTypeDictionary() { jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePSTypeDictionary(){ - jsonString = "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdatePSTypeDictionary() { + jsonString = + "{\"userid\":\"demo\",\"psTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePSTypeDictionary(){ + public void testRemovePSTypeDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePSTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSavePSResourceDictionary(){ + public void testSavePSResourceDictionary() { jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSResourceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psResourceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdatePSResourceDictionary(){ - jsonString = "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testUpdatePSResourceDictionary() { + jsonString = + "{\"userid\":\"demo\",\"psResourceDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":" + + "\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSResourceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psResourceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemovePSResourceDictionary(){ + public void testRemovePSResourceDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removePSResourceDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("psResourceDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("psResourceDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java index 007d02120..f9711b9ed 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyControllerTest.java @@ -22,7 +22,9 @@ package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; + import com.att.research.xacml.api.pap.PAPException; + import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; @@ -32,12 +34,14 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; + import javax.servlet.ReadListener; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.hibernate.SessionFactory; import org.junit.After; import org.junit.Before; @@ -52,7 +56,6 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyVersion; import org.springframework.mock.web.MockServletConfig; - public class PushPolicyControllerTest { private static Logger logger = FlexLogger.getLogger(PushPolicyControllerTest.class); @@ -68,7 +71,7 @@ public class PushPolicyControllerTest { @BeforeClass public static void beforeClassSetup() throws ServletException { - sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("pushcontrollertest"); + sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("pushcontrollertest"); } @Before @@ -82,7 +85,8 @@ public class PushPolicyControllerTest { servletConfig = Mockito.mock(MockServletConfig.class); System.setProperty("com.sun.management.jmxremote.port", "9993"); Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); - Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("src/test/resources/xacml.pap.properties"); + Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")) + .thenReturn("src/test/resources/xacml.pap.properties"); commonClassDao = Mockito.mock(CommonClassDao.class); controller = new PushPolicyController(); @@ -91,35 +95,39 @@ public class PushPolicyControllerTest { } @Test - public void testPushPolicy() throws ServletException, PAPException{ + public void testPushPolicy() throws ServletException, PAPException { PolicyVersion versionData = new PolicyVersion(); - versionData.setPolicyName("com"+File.separator+"Config_Test"); + versionData.setPolicyName("com" + File.separator + "Config_Test"); versionData.setActiveVersion(1); versionData.setHigherVersion(1); List<Object> data = new ArrayList<>(); data.add(versionData); - when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(data); + when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com" + File.separator + "Config_Test")) + .thenReturn(data); pap = new XACMLPapServlet(); pap.init(servletConfig); callPushPolicy(); - when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com"+File.separator+"Config_Test")).thenReturn(null); + when(commonClassDao.getDataById(PolicyVersion.class, "policyName", "com" + File.separator + "Config_Test")) + .thenReturn(null); callPushPolicy(); } - public void callPushPolicy(){ - jsonString = "{\"policyScope\":\"com\",\"filePrefix\":\"Config_\",\"policyName\":\"Test\",\"pdpGroup\":\"default\"}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void callPushPolicy() { + jsonString = + "{\"policyScope\":\"com\",\"filePrefix\":\"Config_\",\"policyName\":\"Test\",\"pdpGroup\":\"default\"}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { char[] charBuffer = new char[8 * 1024]; StringBuilder builder = new StringBuilder(); int numCharsRead; while ((numCharsRead = br.read(charBuffer, 0, charBuffer.length)) != -1) { builder.append(charBuffer, 0, numCharsRead); } - when(request.getInputStream()).thenReturn(getInputStream(builder.toString().getBytes(StandardCharsets.UTF_8))); + when(request.getInputStream()) + .thenReturn(getInputStream(builder.toString().getBytes(StandardCharsets.UTF_8))); controller.pushPolicy(request, response); assertTrue(response != null); - }catch(Exception e){ - logger.error("Exception"+ e); + } catch (Exception e) { + logger.error("Exception" + e); } } @@ -148,9 +156,9 @@ public class PushPolicyControllerTest { return servletInputStream; } - @After - public void destroy(){ - if(pap!=null) - pap.destroy(); - } + @After + public void destroy() { + if (pap != null) + pap.destroy(); + } } diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java index ae1840ebb..8292704b8 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -17,6 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -53,7 +54,7 @@ public class SafePolicyControllerTest { private SafePolicyController controller = null; private MockHttpServletResponse response = null; private UserInfo userInfo; - private List<String> data; + private List<String> data; @Before public void setUp() throws Exception { @@ -76,127 +77,139 @@ public class SafePolicyControllerTest { DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); + response = new MockHttpServletResponse(); logger.info("setUp: exit"); } @Test - public void testGetRiskTypeDictionaryByNameEntityData(){ + public void testGetRiskTypeDictionaryByNameEntityData() { when(commonClassDao.getDataByColumn(RiskType.class, "name")).thenReturn(data); controller.getRiskTypeDictionaryByNameEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("riskTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetRiskTypeDictionaryEntityData(){ + public void testGetRiskTypeDictionaryEntityData() { when(commonClassDao.getData(RiskType.class)).thenReturn(new ArrayList<>()); controller.getRiskTypeDictionaryEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("riskTypeDictionaryDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetSafePolicyWarningEntityDataByName(){ + public void testGetSafePolicyWarningEntityDataByName() { when(commonClassDao.getDataByColumn(SafePolicyWarning.class, "name")).thenReturn(data); controller.getSafePolicyWarningEntityDataByName(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("safePolicyWarningDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testGetSafePolicyWarningeEntityData(){ + public void testGetSafePolicyWarningeEntityData() { when(commonClassDao.getData(SafePolicyWarning.class)).thenReturn(new ArrayList<>()); controller.getSafePolicyWarningeEntityData(response); try { - assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("safePolicyWarningDatas")); } catch (Exception e) { fail(); - logger.error(e.getMessage(),e); + logger.error(e.getMessage(), e); } } @Test - public void testSaveRiskTypeDictionary(){ - jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveRiskTypeDictionary() { + jsonString = + "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveRiskTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("riskTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateRiskTypeDictionary(){ + public void testUpdateRiskTypeDictionary() { jsonString = "{\"userid\":\"demo\",\"riskTypeDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveRiskTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("riskTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveRiskTypeDictionary(){ + public void testRemoveRiskTypeDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeRiskTypeDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("riskTypeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("riskTypeDictionaryDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testSaveSafePolicyWarningDictionary(){ - jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + public void testSaveSafePolicyWarningDictionary() { + jsonString = + "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveSafePolicyWarningDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("safePolicyWarningDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testUpdateSafePolicyWarningDictionary(){ + public void testUpdateSafePolicyWarningDictionary() { jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveSafePolicyWarningDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("safePolicyWarningDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } @Test - public void testRemoveSafePolicyWarningDictionary(){ + public void testRemoveSafePolicyWarningDictionary() { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; - try(BufferedReader br = new BufferedReader(new StringReader(jsonString))){ + try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.removeSafePolicyWarningDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("safePolicyWarningDatas")); + } catch (Exception e) { + logger.error("Exception" + e); } } } |