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.Matchers.any;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.never;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 import java.io.BufferedReader;
33 import java.io.IOException;
34 import java.io.StringReader;
35 import java.util.ArrayList;
36 import java.util.List;
38 import javax.servlet.http.HttpServletRequest;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.Mockito;
43 import org.onap.policy.common.logging.flexlogger.FlexLogger;
44 import org.onap.policy.common.logging.flexlogger.Logger;
45 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
46 import org.onap.policy.rest.adapter.Term;
47 import org.onap.policy.rest.dao.CommonClassDao;
48 import org.onap.policy.rest.jpa.ActionList;
49 import org.onap.policy.rest.jpa.AddressGroup;
50 import org.onap.policy.rest.jpa.FWTag;
51 import org.onap.policy.rest.jpa.FWTagPicker;
52 import org.onap.policy.rest.jpa.FirewallDictionaryList;
53 import org.onap.policy.rest.jpa.GroupServiceList;
54 import org.onap.policy.rest.jpa.PortList;
55 import org.onap.policy.rest.jpa.PrefixList;
56 import org.onap.policy.rest.jpa.ProtocolList;
57 import org.onap.policy.rest.jpa.SecurityZone;
58 import org.onap.policy.rest.jpa.ServiceList;
59 import org.onap.policy.rest.jpa.TermList;
60 import org.onap.policy.rest.jpa.UserInfo;
61 import org.onap.policy.rest.jpa.Zone;
62 import org.springframework.mock.web.MockHttpServletResponse;
64 public class FirewallDictionaryControllerTest {
66 private static Logger logger = FlexLogger.getLogger(FirewallDictionaryControllerTest.class);
67 private static CommonClassDao commonClassDao;
68 private String jsonString = null;
69 private HttpServletRequest request = null;
70 private FirewallDictionaryController controller = null;
71 private MockHttpServletResponse response = null;
72 private UserInfo userInfo;
73 private List<String> data;
76 public void setUp() throws Exception {
77 logger.info("setUp: Entering");
78 commonClassDao = Mockito.mock(CommonClassDao.class);
80 data = new ArrayList<>();
83 userInfo = new UserInfo();
84 userInfo.setUserLoginId("Test");
85 userInfo.setUserName("Test");
87 doNothing().when(commonClassDao).delete(any(Term.class));
88 doNothing().when(commonClassDao).save(any(Term.class));
90 controller = new FirewallDictionaryController();
91 FirewallDictionaryController.setCommonClassDao(commonClassDao);
93 request = Mockito.mock(HttpServletRequest.class);
94 response = new MockHttpServletResponse();
95 new DictionaryUtils(commonClassDao);
96 DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
97 mock(DictionaryUtils.class);
98 logger.info("setUp: exit");
102 public void testGetPrefixListDictionaryEntityDataByName() {
103 test_WithGetDataByColumn(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
104 () -> controller.getPrefixListDictionaryEntityDataByName(response));
108 public void testGetPrefixListDictionaryEntityData() {
109 test_WithGetData(PrefixList.class, "prefixListDictionaryDatas",
110 () -> controller.getPrefixListDictionaryEntityData(response));
114 public void testGetPortListDictionaryEntityData() {
115 test_WithGetData(PortList.class, "portListDictionaryDatas",
116 () -> controller.getPortListDictionaryEntityData(response));
120 public void testGetProtocolListDictionaryEntityDataByName() {
121 test_WithGetDataByColumn(ProtocolList.class,
122 "protocolListDictionaryDatas", "protocolName",
123 () -> controller.getProtocolListDictionaryEntityDataByName(response));
127 public void testGetProtocolListDictionaryEntityData() {
128 test_WithGetData(ProtocolList.class, "protocolListDictionaryDatas",
129 () -> controller.getProtocolListDictionaryEntityData(response));
133 public void testGetAddressGroupDictionaryEntityDataByName() {
134 test_WithGetDataByColumn(AddressGroup.class, "addressGroupDictionaryDatas", "name",
135 () -> controller.getAddressGroupDictionaryEntityDataByName(response));
139 public void testGetAddressGroupDictionaryEntityData() {
140 test_WithGetData(AddressGroup.class, "addressGroupDictionaryDatas",
141 () -> controller.getAddressGroupDictionaryEntityData(response));
145 public void testGetActionListDictionaryEntityDataByName() {
146 test_WithGetDataByColumn(ActionList.class, "actionListDictionaryDatas", "actionName",
147 () -> controller.getActionListDictionaryEntityDataByName(response));
151 public void testGetActionListDictionaryEntityData() {
152 test_WithGetData(ActionList.class, "actionListDictionaryDatas",
153 () -> controller.getActionListDictionaryEntityData(response));
157 public void testGetServiceGroupDictionaryEntityDataByName() {
158 test_WithGetDataByColumn(GroupServiceList.class, "serviceGroupDictionaryDatas", "name",
159 () -> controller.getServiceGroupDictionaryEntityDataByName(response));
163 public void testGetServiceGroupDictionaryEntityData() {
164 test_WithGetData(GroupServiceList.class, "serviceGroupDictionaryDatas",
165 () -> controller.getServiceGroupDictionaryEntityData(response));
169 public void testGetSecurityZoneDictionaryEntityDataByName() {
170 test_WithGetDataByColumn(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
171 () -> controller.getSecurityZoneDictionaryEntityDataByName(response));
175 public void testGetSecurityZoneDictionaryEntityData() {
176 test_WithGetData(SecurityZone.class, "securityZoneDictionaryDatas",
177 () -> controller.getSecurityZoneDictionaryEntityData(response));
181 public void testGetServiceListDictionaryEntityDataByName() {
182 test_WithGetDataByColumn(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
183 () -> controller.getServiceListDictionaryEntityDataByName(response));
187 public void testGetServiceListDictionaryEntityData() {
188 test_WithGetData(ServiceList.class, "serviceListDictionaryDatas",
189 () -> controller.getServiceListDictionaryEntityData(response));
193 public void testGetZoneDictionaryEntityDataByName() {
194 test_WithGetDataByColumn(Zone.class, "zoneDictionaryDatas", "zoneName",
195 () -> controller.getZoneDictionaryEntityDataByName(response));
199 public void testGetZoneDictionaryEntityData() {
200 test_WithGetData(Zone.class, "zoneDictionaryDatas", () ->
201 controller.getZoneDictionaryEntityData(response));
205 public void testGetTermListDictionaryEntityDataByName() {
206 test_WithGetDataByColumn(TermList.class, "termListDictionaryDatas", "termName",
207 () -> controller.getTermListDictionaryEntityDataByName(response));
211 public void testGetTermListDictionaryEntityData() {
212 test_WithGetData(TermList.class, "termListDictionaryDatas",
213 () -> controller.getTermListDictionaryEntityData(response));
217 public void testGetFWDictListDictionaryEntityDataByName() {
218 test_WithGetDataByColumn(FirewallDictionaryList.class,
219 "fwDictListDictionaryDatas", "parentItemName",
220 () -> controller.getFWDictListDictionaryEntityDataByName(response));
224 public void testGetFWDictionaryListEntityData() {
225 test_WithGetData(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
226 () -> controller.getFWDictionaryListEntityData(response));
230 public void testGetTagPickerNameEntityDataByName() {
231 test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
232 () -> controller.getTagPickerNameEntityDataByName(response));
236 public void testGetTagPickerDictionaryEntityData() {
237 test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas",
238 () -> controller.getTagPickerDictionaryEntityData(response));
242 public void testGetTagNameEntityDataByName() {
243 test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
244 () -> controller.getTagNameEntityDataByName(response));
248 public void testGetTagDictionaryEntityData() {
249 test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response));
253 public void testSavePrefixListDictionary() {
255 "{\"userid\":\"demo\",\"prefixListDictionaryData\":"
256 + "{\"description\":\"test\",\"prefixListName\":\"Test\"}}";
257 testSave(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
258 () -> controller.savePrefixListDictionary(request, response));
262 public void testUpdatePrefixListDictionary() {
264 "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":"
265 + "\"test\",\"prefixListName\":\"Test\"}}";
266 testUpdate(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
267 () -> controller.savePrefixListDictionary(request, response));
271 public void testRemovePrefixListDictionary() {
272 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
273 testRemove(PrefixList.class, "prefixListDictionaryDatas",
274 () -> controller.removePrefixListDictionary(request, response));
278 public void testValidatePrefixListDictionary() {
280 "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":"
281 + "\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}";
282 testValidate(PrefixList.class, "result", () -> controller.validatePrefixListDictionary(request, response));
286 public void testSavePortListDictionary() {
288 "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}";
289 testSave(PortList.class, "portListDictionaryDatas", "portName",
290 () -> controller.savePortListDictionary(request, response));
294 public void testUpdatePortListDictionary() {
296 "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":"
297 + "\"test\",\"portName\":\"Test\"}}";
298 testUpdate(PortList.class, "portListDictionaryDatas", "portName",
299 () -> controller.savePortListDictionary(request, response));
303 public void testRemovePortListDictionary() {
304 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
305 testRemove(PortList.class, "portListDictionaryDatas",
306 () -> controller.removePortListDictionary(request, response));
310 public void testSaveProtocolListDictionary() {
312 "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":"
314 testSave(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
315 () -> controller.saveProtocolListDictionary(request, response));
319 public void testUpdateProtocolListDictionary() {
321 "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":"
322 + "\"test\",\"protocolName\":\"Test\"}}";
323 testUpdate(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
324 () -> controller.saveProtocolListDictionary(request, response));
328 public void testRemoveProtocolListDictionary() {
329 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
330 testRemove(ProtocolList.class, "protocolListDictionaryDatas",
331 () -> controller.removeProtocolListDictionary(request, response));
335 public void testSaveAddressGroupDictionary() {
337 "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":"
338 + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":"
339 + "\"Test\"},\"userid\":\"demo\"}";
340 testSave(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
341 () -> controller.saveAddressGroupDictionary(request, response));
345 public void testUpdateAddressGroupDictionary() {
347 "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":"
348 + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":"
350 testUpdate(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
351 () -> controller.saveAddressGroupDictionary(request, response));
355 public void testRemoveAddressGroupDictionary() {
356 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
357 testRemove(AddressGroup.class, "addressGroupDictionaryDatas",
358 () -> controller.removeAddressGroupDictionary(request, response));
362 public void testSaveActionListDictionary() {
364 "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":"
366 testSave(ActionList.class, "actionListDictionaryDatas", "actionName",
367 () -> controller.saveActionListDictionary(request, response));
371 public void testUpdateActionListDictionary() {
373 "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":"
375 testUpdate(ActionList.class, "actionListDictionaryDatas", "actionName",
376 () -> controller.saveActionListDictionary(request, response));
380 public void testRemoveActionListDictionary() {
381 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
382 testRemove(ActionList.class, "actionListDictionaryDatas",
383 () -> controller.removeActionListDictionary(request, response));
387 public void testSaveServiceGroupDictionary() {
389 "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":"
390 + "\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
391 testSave(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
392 () -> controller.saveServiceGroupDictionary(request, response));
396 public void testUpdateServiceGroupDictionary() {
398 "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":"
399 + "\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
400 testUpdate(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
401 () -> controller.saveServiceGroupDictionary(request, response));
405 public void testRemoveServiceGroupDictionary() {
406 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
407 testRemove(GroupServiceList.class, "serviceGroupDictionaryDatas",
408 () -> controller.removeServiceGroupDictionary(request, response));
412 public void testSaveSecurityZoneDictionary() {
414 "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":"
416 testSave(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
417 () -> controller.saveSecurityZoneDictionary(request, response));
421 public void testUpdateSecurityZoneDictionary() {
423 "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":"
425 testUpdate(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
426 () -> controller.saveSecurityZoneDictionary(request, response));
430 public void testRemoveSecurityZoneDictionary() {
431 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
432 testRemove(SecurityZone.class, "securityZoneDictionaryDatas",
433 () -> controller.removeSecurityZoneDictionary(request, response));
437 public void testSaveServiceListDictionary() {
439 "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":"
440 + "\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":"
441 + "\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":"
442 + "\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
443 testSave(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
444 () -> controller.saveServiceListDictionary(request, response));
448 public void testUpdateServiceListDictionary() {
450 "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":"
451 + "\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":"
452 + "\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":"
453 + "\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
454 testUpdate(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
455 () -> controller.saveServiceListDictionary(request, response));
459 public void testRemoveServiceListDictionary() {
461 "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":"
462 + "\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":"
463 + "\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":"
464 + "\"Test\"}]},\"userid\":\"demo\"}";
465 testRemove(ServiceList.class, "serviceListDictionaryDatas",
466 () -> controller.removeServiceListDictionary(request, response));
470 public void testSaveZoneDictionary() {
471 jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
472 testSave(Zone.class, "zoneDictionaryDatas", "zoneName", ()
473 -> controller.saveZoneDictionary(request, response));
477 public void testUpdateZoneDictionary() {
479 "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
480 testUpdate(Zone.class, "zoneDictionaryDatas", "zoneName",
481 () -> controller.saveZoneDictionary(request, response));
485 public void testRemoveZoneDictionary() {
486 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
487 testRemove(Zone.class, "zoneDictionaryDatas", () -> controller.removeZoneDictionary(request, response));
491 public void testSaveTermListDictionary() {
493 "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":"
494 + "\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":"
495 + "\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":"
496 + "[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":"
497 + "[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":"
498 + "[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":"
499 + "\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":"
500 + "\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":"
501 + "\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":"
502 + "\"Test\"}]},\"userid\":\"demo\"}";
503 testSave(TermList.class, "termListDictionaryDatas", "termName",
504 () -> controller.saveTermListDictionary(request, response));
508 public void testUpdateTermListDictionary() {
510 "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":"
511 + "\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":"
512 + "\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":"
513 + "[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":"
514 + "[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":"
515 + "[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":"
516 + "\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":"
517 + "\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":"
518 + "\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":"
519 + "\"Test\"}]},\"userid\":\"demo\"}";
520 testUpdate(TermList.class, "termListDictionaryDatas", "termName",
521 () -> controller.saveTermListDictionary(request, response));
525 public void testRemoveTermListDictionary() {
526 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"termDescription\":\"test\",\"termName\":\"Test\"}}";
527 testRemove(TermList.class, "termListDictionaryDatas",
528 () -> controller.removeTermListDictionary(request, response));
532 public void testSaveFWDictionaryList() {
534 "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":"
535 + "\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":"
536 + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":"
538 testSave(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
539 () -> controller.saveFWDictionaryList(request, response));
543 public void testUpdateFWDictionaryList() {
545 "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":"
546 + "\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":"
547 + "\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":"
549 testUpdate(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
550 () -> controller.saveFWDictionaryList(request, response));
554 public void testRemoveFWDictionaryList() {
555 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"parentItemName\":\"Test\"}}";
556 testRemove(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
557 () -> controller.removeFWDictionaryList(request, response));
561 public void testSaveFirewallTagPickerDictionary() {
563 "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":"
564 + "\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":"
565 + "\"Test\"}]},\"userid\":\"demo\"}";
566 testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
567 () -> controller.saveFirewallTagPickerDictionary(request, response));
571 public void testUpdateFirewallTagPickerDictionary() {
573 "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":"
574 + "\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":"
575 + "\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
576 testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
577 () -> controller.saveFirewallTagPickerDictionary(request, response));
581 public void testRemoveFirewallTagPickerDictionary() {
582 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}";
583 testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas",
584 () -> controller.removeFirewallTagPickerDictionary(request, response));
588 public void testSaveFirewallTagDictionary() {
590 "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":"
591 + "\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
592 testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
593 () -> controller.saveFirewallTagDictionary(request, response));
597 public void testUpdateFirewallTagDictionary() {
599 "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":"
600 + "[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
601 testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
602 () -> controller.saveFirewallTagDictionary(request, response));
606 public void testRemoveFirewallTagDictionary() {
607 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}";
608 testRemove(FWTag.class, "fwTagDictionaryDatas",
609 () -> controller.removeFirewallTagDictionary(request, response));
613 * Tests a "get" function that uses commonClassDao.getDataByColumn().
620 private void test_WithGetDataByColumn(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
621 when(commonClassDao.getDataByColumn(clazz, contentName)).thenReturn(data);
624 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
625 verify(commonClassDao).getDataByColumn(clazz, contentName);
626 } catch (Exception e) {
627 fail("get " + clazz.getName() + e);
632 * Tests a "get" function that uses commonClassDao.getData().
639 private void test_WithGetData(Class<?> clazz, String contentData, VoidFunc func) {
640 when(commonClassDao.getData(clazz)).thenReturn(new ArrayList<>());
643 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
644 verify(commonClassDao).getData(clazz);
645 } catch (Exception e) {
646 fail("get " + clazz.getName() + e);
651 * Tests a function that uses commonClassDao.save().
658 private void testSave(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
659 testSave(clazz, contentData, contentName, "Test", func);
663 * Tests a function that uses commonClassDao.save().
671 private void testSave(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
672 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
673 when(request.getReader()).thenReturn(br);
675 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
676 verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
677 verify(commonClassDao).save(any());
678 verify(commonClassDao, never()).update(any());
679 verify(commonClassDao).getData(clazz);
681 } catch (IOException e) {
682 fail("save " + clazz.getName() + e);
687 * Tests a function that uses commonClassDao.update().
694 private void testUpdate(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
695 testUpdate(clazz, contentData, contentName, "Test", func);
699 * Tests a function that uses commonClassDao.update().
707 private void testUpdate(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
708 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
709 when(request.getReader()).thenReturn(br);
711 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
712 verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
713 verify(commonClassDao, never()).save(any());
714 verify(commonClassDao).update(any());
715 verify(commonClassDao).getData(clazz);
717 } catch (IOException e) {
718 fail("update " + clazz.getName() + e);
723 * Tests a function that uses commonClassDao.delete() and
724 * commonClassDao.getData().
730 private void testRemove(Class<?> clazz, String contentData, VoidFunc func) {
731 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
732 when(request.getReader()).thenReturn(br);
734 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
735 verify(commonClassDao).delete(any());
736 verify(commonClassDao).getData(clazz);
738 } catch (IOException e) {
739 fail("remove " + clazz.getName() + e);
744 * Tests a "validate" function.
750 private void testValidate(Class<?> clazz, String contentData, VoidFunc func) {
751 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
752 when(request.getReader()).thenReturn(br);
754 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
756 } catch (IOException e) {
757 fail("save " + clazz.getName() + e);
762 private static interface VoidFunc {
763 public void apply() throws IOException;