X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FDescriptiveDictionaryControllerTest.java;fp=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FDescriptiveDictionaryControllerTest.java;h=0950b1cfdaef282cc9358f45ae702e95f8a50515;hb=4068da123ee33b532b4b52f15545c76a978f977e;hp=5310ddc931850ad0074d2c64d9ecc2b43e791886;hpb=f0fec2a861ea0a92b27b40882ea38f9422cde0c6;p=policy%2Fengine.git 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 5310ddc93..0950b1cfd 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 @@ -45,124 +45,124 @@ import org.onap.policy.rest.jpa.UserInfo; import org.springframework.mock.web.MockHttpServletResponse; public class DescriptiveDictionaryControllerTest { - - private static Logger logger = FlexLogger.getLogger(DescriptiveDictionaryControllerTest.class); - private static CommonClassDao commonClassDao; - private String jsonString = null; - private HttpServletRequest request = null; - private DescriptiveDictionaryController controller = null; - private MockHttpServletResponse response = null; - private UserInfo userInfo; - private List data; - - @Before - public void setUp() throws Exception { - logger.info("setUp: Entering"); - commonClassDao = Mockito.mock(CommonClassDao.class); - - data = new ArrayList<>(); - data.add("Test"); - - userInfo = new UserInfo(); - userInfo.setUserLoginId("Test"); - userInfo.setUserName("Test"); - - doNothing().when(commonClassDao).delete(new DescriptiveScope()); - doNothing().when(commonClassDao).save(new DescriptiveScope()); - - controller = new DescriptiveDictionaryController(); - controller.setCommonClassDao(commonClassDao); - - request = Mockito.mock(HttpServletRequest.class); - response = new MockHttpServletResponse(); - new DictionaryUtils(commonClassDao); + + private static Logger logger = FlexLogger.getLogger(DescriptiveDictionaryControllerTest.class); + private static CommonClassDao commonClassDao; + private String jsonString = null; + private HttpServletRequest request = null; + private DescriptiveDictionaryController controller = null; + private MockHttpServletResponse response = null; + private UserInfo userInfo; + private List data; + + @Before + public void setUp() throws Exception { + logger.info("setUp: Entering"); + commonClassDao = Mockito.mock(CommonClassDao.class); + + data = new ArrayList<>(); + data.add("Test"); + + userInfo = new UserInfo(); + userInfo.setUserLoginId("Test"); + userInfo.setUserName("Test"); + + doNothing().when(commonClassDao).delete(new DescriptiveScope()); + doNothing().when(commonClassDao).save(new DescriptiveScope()); + + controller = new DescriptiveDictionaryController(); + controller.setCommonClassDao(commonClassDao); + + request = Mockito.mock(HttpServletRequest.class); + response = new MockHttpServletResponse(); + new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); mock(DictionaryUtils.class); - logger.info("setUp: exit"); - } - - public List testDescriptiveScope(){ - List objectData = new ArrayList<>(); - - DescriptiveScope data = new DescriptiveScope(); - data.setId(1); - assertTrue(1 == data.getId()); - data.setScopeName("Test"); - assertTrue("Test".equals(data.getScopeName())); - data.setDescription("Test"); - assertTrue("Test".equals(data.getDescription())); - data.setSearch("Test"); - assertTrue("Test".equals(data.getSearch())); - data.setCreatedDate(new Date()); - assertTrue(data.getCreatedDate()!= null); - data.setModifiedDate(new Date()); - assertTrue(data.getModifiedDate()!= null); - data.setUserCreatedBy(userInfo); - assertTrue(data.getUserCreatedBy()!= null); - data.setUserModifiedBy(userInfo); - assertTrue(data.getUserModifiedBy()!= null); - objectData.add(data); - - return objectData; - } - - @Test - public void testGetDescriptiveDictionaryByNameEntityData(){ - when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data); - controller.getDescriptiveDictionaryByNameEntityData(response); - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - } catch (Exception e) { - fail(); - logger.error(e.getMessage(),e); - } - } - - @Test - public void testGetDescriptiveDictionaryEntityData(){ - when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope()); - controller.getDescriptiveDictionaryEntityData(response); - try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - } catch (Exception e) { - fail(); - 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))){ - when(request.getReader()).thenReturn(br); - controller.saveDescriptiveDictionary(request, response); - 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))){ - when(request.getReader()).thenReturn(br); - controller.saveDescriptiveDictionary(request, response); - 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))){ - when(request.getReader()).thenReturn(br); - controller.removeDescriptiveDictionary(request, response); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); - }catch(Exception e){ - logger.error("Exception"+ e); - } - } + logger.info("setUp: exit"); + } + + public List testDescriptiveScope(){ + List objectData = new ArrayList<>(); + + DescriptiveScope data = new DescriptiveScope(); + data.setId(1); + assertTrue(1 == data.getId()); + data.setScopeName("Test"); + assertTrue("Test".equals(data.getScopeName())); + data.setDescription("Test"); + assertTrue("Test".equals(data.getDescription())); + data.setSearch("Test"); + assertTrue("Test".equals(data.getSearch())); + data.setCreatedDate(new Date()); + assertTrue(data.getCreatedDate()!= null); + data.setModifiedDate(new Date()); + assertTrue(data.getModifiedDate()!= null); + data.setUserCreatedBy(userInfo); + assertTrue(data.getUserCreatedBy()!= null); + data.setUserModifiedBy(userInfo); + assertTrue(data.getUserModifiedBy()!= null); + objectData.add(data); + + return objectData; + } + + @Test + public void testGetDescriptiveDictionaryByNameEntityData(){ + when(commonClassDao.getDataByColumn(DescriptiveScope.class, "descriptiveScopeName")).thenReturn(data); + controller.getDescriptiveDictionaryByNameEntityData(response); + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + } catch (Exception e) { + fail(); + logger.error(e.getMessage(),e); + } + } + + @Test + public void testGetDescriptiveDictionaryEntityData(){ + when(commonClassDao.getData(DescriptiveScope.class)).thenReturn(testDescriptiveScope()); + controller.getDescriptiveDictionaryEntityData(response); + try { + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + } catch (Exception e) { + fail(); + 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))){ + when(request.getReader()).thenReturn(br); + controller.saveDescriptiveDictionary(request, response); + 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))){ + when(request.getReader()).thenReturn(br); + controller.saveDescriptiveDictionary(request, response); + 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))){ + when(request.getReader()).thenReturn(br); + controller.removeDescriptiveDictionary(request, response); + assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); + }catch(Exception e){ + logger.error("Exception"+ e); + } + } } \ No newline at end of file