2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.xacml.rest.controller;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.io.BufferedReader;
30 import java.io.StringReader;
31 import java.util.ArrayList;
32 import java.util.List;
34 import javax.servlet.http.HttpServletRequest;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mockito;
39 import org.onap.policy.common.logging.flexlogger.FlexLogger;
40 import org.onap.policy.common.logging.flexlogger.Logger;
41 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
42 import org.onap.policy.rest.dao.CommonClassDao;
43 import org.onap.policy.rest.jpa.ClosedLoopD2Services;
44 import org.onap.policy.rest.jpa.ClosedLoopSite;
45 import org.onap.policy.rest.jpa.PepOptions;
46 import org.onap.policy.rest.jpa.UserInfo;
47 import org.onap.policy.rest.jpa.VNFType;
48 import org.onap.policy.rest.jpa.VSCLAction;
49 import org.onap.policy.rest.jpa.VarbindDictionary;
50 import org.springframework.mock.web.MockHttpServletResponse;
52 public class ClosedLoopDictionaryControllerTest {
54 private static Logger logger = FlexLogger.getLogger(ClosedLoopDictionaryControllerTest.class);
55 private static CommonClassDao commonClassDao;
56 private String jsonString = null;
57 private HttpServletRequest request = null;
58 private ClosedLoopDictionaryController controller = null;
59 private MockHttpServletResponse response = null;
60 private UserInfo userInfo;
61 private List<String> data;
64 public void setUp() throws Exception {
65 logger.info("setUp: Entering");
66 commonClassDao = Mockito.mock(CommonClassDao.class);
68 data = new ArrayList<>();
71 userInfo = new UserInfo();
72 userInfo.setUserLoginId("Test");
73 userInfo.setUserName("Test");
75 doNothing().when(commonClassDao).delete(new VSCLAction());
76 doNothing().when(commonClassDao).save(new VSCLAction());
78 controller = new ClosedLoopDictionaryController();
79 controller.setCommonClassDao(commonClassDao);
81 request = Mockito.mock(HttpServletRequest.class);
82 response = new MockHttpServletResponse();
83 new DictionaryUtils(commonClassDao);
84 DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
85 mock(DictionaryUtils.class);
86 logger.info("setUp: exit");
90 public void testGetVSCLActionDictionaryByNameEntityData() {
91 when(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction")).thenReturn(data);
92 controller.getVSCLActionDictionaryByNameEntityData(response);
94 assertTrue(response.getContentAsString() != null
95 && response.getContentAsString().contains("vsclActionDictionaryDatas"));
96 } catch (Exception e) {
98 logger.error(e.getMessage(), e);
103 public void testGetVSCLActionDictionaryEntityData() {
104 when(commonClassDao.getData(VSCLAction.class)).thenReturn(new ArrayList<>());
105 controller.getVSCLActionDictionaryEntityData(response);
107 assertTrue(response.getContentAsString() != null
108 && response.getContentAsString().contains("vsclActionDictionaryDatas"));
109 } catch (Exception e) {
111 logger.error(e.getMessage(), e);
116 public void testGetVNFTypeDictionaryByNameEntityData() {
117 when(commonClassDao.getDataByColumn(VNFType.class, "vnftype")).thenReturn(data);
118 controller.getVNFTypeDictionaryByNameEntityData(response);
120 assertTrue(response.getContentAsString() != null
121 && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
122 } catch (Exception e) {
124 logger.error(e.getMessage(), e);
129 public void testGetVNFTypeDictionaryEntityData() {
130 when(commonClassDao.getData(VNFType.class)).thenReturn(new ArrayList<>());
131 controller.getVNFTypeDictionaryEntityData(response);
133 assertTrue(response.getContentAsString() != null
134 && response.getContentAsString().contains("vnfTypeDictionaryDatas"));
135 } catch (Exception e) {
137 logger.error(e.getMessage(), e);
142 public void testGetPEPOptionsDictionaryByNameEntityData() {
143 when(commonClassDao.getDataByColumn(PepOptions.class, "pepName")).thenReturn(data);
144 controller.getPEPOptionsDictionaryByNameEntityData(response);
146 assertTrue(response.getContentAsString() != null
147 && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
148 } catch (Exception e) {
150 logger.error(e.getMessage(), e);
155 public void testGetPEPOptionsDictionaryEntityData() {
156 when(commonClassDao.getData(PepOptions.class)).thenReturn(new ArrayList<>());
157 controller.getPEPOptionsDictionaryEntityData(response);
159 assertTrue(response.getContentAsString() != null
160 && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
161 } catch (Exception e) {
163 logger.error(e.getMessage(), e);
168 public void testGetVarbindDictionaryByNameEntityData() {
169 when(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName")).thenReturn(data);
170 controller.getVarbindDictionaryByNameEntityData(response);
172 assertTrue(response.getContentAsString() != null
173 && response.getContentAsString().contains("varbindDictionaryDatas"));
174 } catch (Exception e) {
176 logger.error(e.getMessage(), e);
181 public void testGetVarbindDictionaryEntityData() {
182 when(commonClassDao.getData(VarbindDictionary.class)).thenReturn(new ArrayList<>());
183 controller.getVarbindDictionaryEntityData(response);
185 assertTrue(response.getContentAsString() != null
186 && response.getContentAsString().contains("varbindDictionaryDatas"));
187 } catch (Exception e) {
189 logger.error(e.getMessage(), e);
194 public void testGetClosedLoopServiceDictionaryByNameEntityData() {
195 when(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName")).thenReturn(data);
196 controller.getClosedLoopServiceDictionaryByNameEntityData(response);
198 assertTrue(response.getContentAsString() != null
199 && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
200 } catch (Exception e) {
202 logger.error(e.getMessage(), e);
207 public void testGetClosedLoopServiceDictionaryEntityData() {
208 when(commonClassDao.getData(ClosedLoopD2Services.class)).thenReturn(new ArrayList<>());
209 controller.getClosedLoopServiceDictionaryEntityData(response);
211 assertTrue(response.getContentAsString() != null
212 && response.getContentAsString().contains("closedLoopServiceDictionaryDatas"));
213 } catch (Exception e) {
215 logger.error(e.getMessage(), e);
220 public void testGetClosedLoopSiteDictionaryByNameEntityData() {
221 when(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName")).thenReturn(data);
222 controller.getClosedLoopSiteDictionaryByNameEntityData(response);
224 assertTrue(response.getContentAsString() != null
225 && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
226 } catch (Exception e) {
228 logger.error(e.getMessage(), e);
233 public void testGetClosedLoopSiteDictionaryEntityData() {
234 when(commonClassDao.getData(ClosedLoopSite.class)).thenReturn(new ArrayList<>());
235 controller.getClosedLoopSiteDictionaryEntityData(response);
237 assertTrue(response.getContentAsString() != null
238 && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
239 } catch (Exception e) {
241 logger.error(e.getMessage(), e);
246 public void testSaveVSCLAction() {
248 "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"description\":\"test\",\"vsclaction\":\"Test\"}}";
249 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
250 when(request.getReader()).thenReturn(br);
251 controller.saveVSCLAction(request, response);
252 assertTrue(response.getContentAsString() != null
253 && response.getContentAsString().contains("vsclActionDictionaryDatas"));
254 } catch (Exception e) {
255 logger.error("Exception" + e);
260 public void testUpdateVSCLAction() {
262 "{\"userid\":\"demo\",\"vsclActionDictionaryData\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
263 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
264 when(request.getReader()).thenReturn(br);
265 controller.saveVSCLAction(request, response);
266 assertTrue(response.getContentAsString() != null
267 && response.getContentAsString().contains("vsclActionDictionaryDatas"));
268 } catch (Exception e) {
269 logger.error("Exception" + e);
274 public void testRemoveVSCLAction() {
275 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vsclaction\":\"Test\"}}";
276 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
277 when(request.getReader()).thenReturn(br);
278 controller.removeVSCLAction(request, response);
279 assertTrue(response.getContentAsString() != null
280 && response.getContentAsString().contains("vsclActionDictionaryDatas"));
281 } catch (Exception e) {
282 logger.error("Exception" + e);
287 public void testSaveVnfType() {
288 jsonString = "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"description\":\"test\",\"vnftype\":\"Test\"}}";
289 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
290 when(request.getReader()).thenReturn(br);
291 controller.saveVnfType(request, response);
292 assertTrue(response.getContentAsString() != null
293 && response.getContentAsString().contains("vnfTypeDictionaryData"));
294 } catch (Exception e) {
295 logger.error("Exception" + e);
300 public void testUpdateVnfType() {
302 "{\"userid\":\"demo\",\"vnfTypeDictionaryData\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
303 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
304 when(request.getReader()).thenReturn(br);
305 controller.saveVnfType(request, response);
306 assertTrue(response.getContentAsString() != null
307 && response.getContentAsString().contains("vnfTypeDictionaryData"));
308 } catch (Exception e) {
309 logger.error("Exception" + e);
314 public void testRemoveVnfType() {
315 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"vnftype\":\"Test\"}}";
316 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
317 when(request.getReader()).thenReturn(br);
318 controller.removeVnfType(request, response);
319 assertTrue(response.getContentAsString() != null
320 && response.getContentAsString().contains("vnfTypeDictionaryData"));
321 } catch (Exception e) {
322 logger.error("Exception" + e);
327 public void testSavePEPOptions() {
329 "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
330 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
331 when(request.getReader()).thenReturn(br);
332 controller.savePEPOptions(request, response);
333 assertTrue(response.getContentAsString() != null
334 && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
335 } catch (Exception e) {
336 logger.error("Exception" + e);
341 public void testUpdatePEPOptions() {
343 "{\"pepOptionsDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\",\"id\":1},\"userid\":\"demo\"}";
344 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
345 when(request.getReader()).thenReturn(br);
346 controller.savePEPOptions(request, response);
347 assertTrue(response.getContentAsString() != null
348 && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
349 } catch (Exception e) {
350 logger.error("Exception" + e);
355 public void testRemovePEPOptions() {
357 "{\"data\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\",\"pepName\":\"Test\"},\"userid\":\"demo\"}";
358 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
359 when(request.getReader()).thenReturn(br);
360 controller.removePEPOptions(request, response);
361 assertTrue(response.getContentAsString() != null
362 && response.getContentAsString().contains("pepOptionsDictionaryDatas"));
363 } catch (Exception e) {
364 logger.error("Exception" + e);
369 public void testSaveServiceType() {
371 "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}";
372 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
373 when(request.getReader()).thenReturn(br);
374 controller.saveServiceType(request, response);
375 assertTrue(response.getContentAsString() != null
376 && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
377 } catch (Exception e) {
378 logger.error("Exception" + e);
383 public void testUpdateServiceType() {
385 "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
386 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
387 when(request.getReader()).thenReturn(br);
388 controller.saveServiceType(request, response);
389 assertTrue(response.getContentAsString() != null
390 && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
391 } catch (Exception e) {
392 logger.error("Exception" + e);
397 public void testRemoveServiceType() {
398 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"serviceName\":\"Test\"}}";
399 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
400 when(request.getReader()).thenReturn(br);
401 controller.removeServiceType(request, response);
402 assertTrue(response.getContentAsString() != null
403 && response.getContentAsString().contains("closedLoopServiceDictionaryData"));
404 } catch (Exception e) {
405 logger.error("Exception" + e);
410 public void testSaveSiteType() {
412 "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"description\":\"test\",\"siteName\":\"Test\"}}";
413 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
414 when(request.getReader()).thenReturn(br);
415 controller.saveSiteType(request, response);
416 assertTrue(response.getContentAsString() != null
417 && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
418 } catch (Exception e) {
419 logger.error("Exception" + e);
424 public void testUpdateSiteType() {
426 "{\"userid\":\"demo\",\"closedLoopSiteDictionaryData\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
427 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
428 when(request.getReader()).thenReturn(br);
429 controller.saveSiteType(request, response);
430 assertTrue(response.getContentAsString() != null
431 && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
432 } catch (Exception e) {
433 logger.error("Exception" + e);
438 public void testRemoveSiteType() {
439 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"siteName\":\"Test\"}}";
440 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
441 when(request.getReader()).thenReturn(br);
442 controller.removeSiteType(request, response);
443 assertTrue(response.getContentAsString() != null
444 && response.getContentAsString().contains("closedLoopSiteDictionaryDatas"));
445 } catch (Exception e) {
446 logger.error("Exception" + e);
451 public void testSaveVarbind() {
453 "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}";
454 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
455 when(request.getReader()).thenReturn(br);
456 controller.saveVarbind(request, response);
457 assertTrue(response.getContentAsString() != null
458 && response.getContentAsString().contains("varbindDictionaryDatas"));
459 } catch (Exception e) {
460 logger.error("Exception" + e);
465 public void testUpdateVarbind() {
467 "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
468 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
469 when(request.getReader()).thenReturn(br);
470 controller.saveVarbind(request, response);
471 assertTrue(response.getContentAsString() != null
472 && response.getContentAsString().contains("varbindDictionaryDatas"));
473 } catch (Exception e) {
474 logger.error("Exception" + e);
479 public void testRemoveVarbind() {
480 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}";
481 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
482 when(request.getReader()).thenReturn(br);
483 controller.removeVarbind(request, response);
484 assertTrue(response.getContentAsString() != null
485 && response.getContentAsString().contains("varbindDictionaryDatas"));
486 } catch (Exception e) {
487 logger.error("Exception" + e);