X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FBRMSDictionaryControllerTest.java;h=e68860e4d142ef713bfeb82b8cda78e8b63769b4;hp=d34e505bae763b3450f536a9421abd68be80270e;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=f18fbfc026de9cf02126f57844c37abfee607394 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..e68860e4d 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; @@ -61,14 +62,14 @@ public class BRMSDictionaryControllerTest { userInfo.setUserLoginId("testUserId"); userInfo.setUserName("John"); when(commonClassDao.getEntityItem(UserInfo.class, "userLoginId", "testing")).thenReturn(userInfo); - List brms = new ArrayList(); + List brms = new ArrayList(); brms.add("BRMS-Model"); 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"); } } -