diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-10-22 07:53:44 -0400 |
---|---|---|
committer | Pamela Dragosh <pdragosh@research.att.com> | 2019-10-23 13:33:56 -0400 |
commit | 1e61676b77dd09659027b8984f050df7e8538526 (patch) | |
tree | 115053dba12b4b27a0f92de0e7648a672a66893a /ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java | |
parent | f18fbfc026de9cf02126f57844c37abfee607394 (diff) |
Consolidate PolicyRestAdapter setup
Put common code into PolicyEngineUtils that the controllers use to
populate the PolicyRestController.
Also some more sonar cleanup and formatting of XML files.
Shortened 120 line characters. Removed some trailing spaces
from comments.
Fixed up one JUnit.
Licenses.
Issue-ID: POLICY-2133
Change-Id: Id7d8ac3ab60331535f048ec0f26aeb17a099414e
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java')
-rw-r--r-- | ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyControllerTest.java | 111 |
1 files changed, 62 insertions, 49 deletions
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); } } } |