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%2FDescriptiveDictionaryControllerTest.java;h=f12299334783cb371398904e3ae08168f82c688b;hp=0950b1cfdaef282cc9358f45ae702e95f8a50515;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=f18fbfc026de9cf02126f57844c37abfee607394 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 data; + private List 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 testDescriptiveScope(){ - List objectData = new ArrayList<>(); + public List testDescriptiveScope() { + List 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 +}