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%2FDictionaryControllerTest.java;h=52b79b88fee7acc206470076c20040bcee842062;hp=89be75f52f480fc626e05a7e8dc8ad48060adc80;hb=1e61676b77dd09659027b8984f050df7e8538526;hpb=f18fbfc026de9cf02126f57844c37abfee607394 diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java index 89be75f52..52b79b88f 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DictionaryControllerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-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. @@ -18,7 +18,6 @@ * ============LICENSE_END========================================================= */ - package org.onap.policy.pap.xacml.rest.controller; import static org.junit.Assert.assertTrue; @@ -70,12 +69,12 @@ public class DictionaryControllerTest { commonClassDao = Mockito.mock(CommonClassDao.class); MicroServiceModels testData = new MicroServiceModels(); - testData.setVersion("1707.4.1.2-Junit"); + testData.setVersion("1707.4.1.2-Junit"); - //--- mock the getDataByColumn() call - List microList = new ArrayList(); + // --- mock the getDataByColumn() call + List microList = new ArrayList(); microList.add("123"); - List listId = new ArrayList(); + List listId = new ArrayList(); when(commonClassDao.getDataByColumn(Attribute.class, "xacmlId")).thenReturn(microList); List object = new ArrayList<>(); object.add(new Category()); @@ -83,9 +82,9 @@ public class DictionaryControllerTest { PolicyEditorScopes editorScope = new PolicyEditorScopes(); doNothing().when(commonClassDao).save(editorScope); doNothing().when(commonClassDao).update(editorScope); - + when(commonClassDao.getData(Attribute.class)).thenReturn(listId); - + request = mock(HttpServletRequest.class); controller = new DictionaryController(commonClassDao); new DictionaryUtils(commonClassDao); @@ -98,12 +97,13 @@ public class DictionaryControllerTest { public void testGetAttributeDictionaryEntityDatabyAttributeName() { logger.info("testGetAttributeDictionaryEntityDatabyAttributeName: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getAttributeDictionaryEntityDatabyAttributeName(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -116,12 +116,13 @@ public class DictionaryControllerTest { public void testGetAttributeDictionaryEntityData() { logger.info("testGetAttributeDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getAttributeDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -134,16 +135,22 @@ public class DictionaryControllerTest { public void testSaveAttributeDictionary() { logger.info("testSaveAttributeDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); - + try { - jsonString = "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":\"Qwerty\"},\"userid\":\"demo\"}"; + jsonString = + "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":" + + "\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":" + + "\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":" + + "\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":" + + "\"Qwerty\"},\"userid\":\"demo\"}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -156,16 +163,17 @@ public class DictionaryControllerTest { public void testRemoveAttributeDictionary() { logger.info("testRemoveAttributeDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"xacmlId\":\"Test\"}}"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); + BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("attributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -178,12 +186,13 @@ public class DictionaryControllerTest { public void testGetOnapNameDictionaryByNameEntityData() { logger.info("testGetOnapNameDictionaryByNameEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getOnapNameDictionaryByNameEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -196,12 +205,13 @@ public class DictionaryControllerTest { public void testGetOnapNameDictionaryEntityData() { logger.info("testGetOnapNameDictionaryEntityData: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); controller.getOnapNameDictionaryEntityData(response); try { - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (UnsupportedEncodingException e) { fail("Exception: " + e); @@ -215,16 +225,18 @@ public class DictionaryControllerTest { logger.info("testSaveOnapDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); - + try { - jsonString = "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}"; + jsonString = + "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveOnapDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); @@ -237,16 +249,17 @@ public class DictionaryControllerTest { public void testRemoveOnapDictionary() { logger.info("testRemoveOnapDictionary: Entering"); - MockHttpServletResponse response = new MockHttpServletResponse(); + MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"onapName\":\"Test\"}}"; - BufferedReader br = new BufferedReader(new StringReader(jsonString)); + BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.removeOnapDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); - assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); + assertTrue(response.getContentAsString() != null + && response.getContentAsString().contains("onapNameDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e);