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%2FSafePolicyControllerTest.java;h=8292704b8b785df5fde26cf26b4f8ff6bd46bc95;hp=ae1840ebb37b6a09d617701cccf82c889e4d7f13;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=f18fbfc026de9cf02126f57844c37abfee607394 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 data; + private List 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); } } }