2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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=========================================================
20 package org.onap.policy.pap.xacml.rest.controller;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
31 import java.io.BufferedReader;
32 import java.io.IOException;
33 import java.io.StringReader;
34 import java.util.ArrayList;
35 import java.util.List;
37 import javax.servlet.http.HttpServletRequest;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mockito;
42 import org.onap.policy.common.logging.flexlogger.FlexLogger;
43 import org.onap.policy.common.logging.flexlogger.Logger;
44 import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
45 import org.onap.policy.rest.adapter.Term;
46 import org.onap.policy.rest.dao.CommonClassDao;
47 import org.onap.policy.rest.jpa.ActionList;
48 import org.onap.policy.rest.jpa.AddressGroup;
49 import org.onap.policy.rest.jpa.FWTag;
50 import org.onap.policy.rest.jpa.FWTagPicker;
51 import org.onap.policy.rest.jpa.FirewallDictionaryList;
52 import org.onap.policy.rest.jpa.GroupServiceList;
53 import org.onap.policy.rest.jpa.PortList;
54 import org.onap.policy.rest.jpa.PrefixList;
55 import org.onap.policy.rest.jpa.ProtocolList;
56 import org.onap.policy.rest.jpa.SecurityZone;
57 import org.onap.policy.rest.jpa.ServiceList;
58 import org.onap.policy.rest.jpa.TermList;
59 import org.onap.policy.rest.jpa.UserInfo;
60 import org.onap.policy.rest.jpa.Zone;
61 import org.springframework.mock.web.MockHttpServletResponse;
63 public class FirewallDictionaryControllerTest {
65 private static Logger logger = FlexLogger.getLogger(FirewallDictionaryControllerTest.class);
66 private static CommonClassDao commonClassDao;
67 private String jsonString = null;
68 private HttpServletRequest request = null;
69 private FirewallDictionaryController controller = null;
70 private MockHttpServletResponse response = null;
71 private UserInfo userInfo;
72 private List<String> data;
75 public void setUp() throws Exception {
76 logger.info("setUp: Entering");
77 commonClassDao = Mockito.mock(CommonClassDao.class);
79 data = new ArrayList<>();
82 userInfo = new UserInfo();
83 userInfo.setUserLoginId("Test");
84 userInfo.setUserName("Test");
86 doNothing().when(commonClassDao).delete(any(Term.class));
87 doNothing().when(commonClassDao).save(any(Term.class));
89 controller = new FirewallDictionaryController();
90 FirewallDictionaryController.setCommonClassDao(commonClassDao);
92 request = Mockito.mock(HttpServletRequest.class);
93 response = new MockHttpServletResponse();
94 new DictionaryUtils(commonClassDao);
95 DictionaryUtils.setDictionaryUtils(new DictionaryUtils());
96 mock(DictionaryUtils.class);
97 logger.info("setUp: exit");
101 public void testGetPrefixListDictionaryEntityDataByName() {
102 test_WithGetDataByColumn(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
103 () -> controller.getPrefixListDictionaryEntityDataByName(response));
107 public void testGetPrefixListDictionaryEntityData() {
108 test_WithGetData(PrefixList.class, "prefixListDictionaryDatas",
109 () -> controller.getPrefixListDictionaryEntityData(response));
113 public void testGetPortListDictionaryEntityData() {
114 test_WithGetData(PortList.class, "portListDictionaryDatas",
115 () -> controller.getPortListDictionaryEntityData(response));
119 public void testGetProtocolListDictionaryEntityDataByName() {
120 test_WithGetDataByColumn(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
121 () -> controller.getProtocolListDictionaryEntityDataByName(response));
125 public void testGetProtocolListDictionaryEntityData() {
126 test_WithGetData(ProtocolList.class, "protocolListDictionaryDatas",
127 () -> controller.getProtocolListDictionaryEntityData(response));
131 public void testGetAddressGroupDictionaryEntityDataByName() {
132 test_WithGetDataByColumn(AddressGroup.class, "addressGroupDictionaryDatas", "name",
133 () -> controller.getAddressGroupDictionaryEntityDataByName(response));
137 public void testGetAddressGroupDictionaryEntityData() {
138 test_WithGetData(AddressGroup.class, "addressGroupDictionaryDatas",
139 () -> controller.getAddressGroupDictionaryEntityData(response));
143 public void testGetActionListDictionaryEntityDataByName() {
144 test_WithGetDataByColumn(ActionList.class, "actionListDictionaryDatas", "actionName",
145 () -> controller.getActionListDictionaryEntityDataByName(response));
149 public void testGetActionListDictionaryEntityData() {
150 test_WithGetData(ActionList.class, "actionListDictionaryDatas",
151 () -> controller.getActionListDictionaryEntityData(response));
155 public void testGetServiceGroupDictionaryEntityDataByName() {
156 test_WithGetDataByColumn(GroupServiceList.class, "serviceGroupDictionaryDatas", "name",
157 () -> controller.getServiceGroupDictionaryEntityDataByName(response));
161 public void testGetServiceGroupDictionaryEntityData() {
162 test_WithGetData(GroupServiceList.class, "serviceGroupDictionaryDatas",
163 () -> controller.getServiceGroupDictionaryEntityData(response));
167 public void testGetSecurityZoneDictionaryEntityDataByName() {
168 test_WithGetDataByColumn(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
169 () -> controller.getSecurityZoneDictionaryEntityDataByName(response));
173 public void testGetSecurityZoneDictionaryEntityData() {
174 test_WithGetData(SecurityZone.class, "securityZoneDictionaryDatas",
175 () -> controller.getSecurityZoneDictionaryEntityData(response));
179 public void testGetServiceListDictionaryEntityDataByName() {
180 test_WithGetDataByColumn(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
181 () -> controller.getServiceListDictionaryEntityDataByName(response));
185 public void testGetServiceListDictionaryEntityData() {
186 test_WithGetData(ServiceList.class, "serviceListDictionaryDatas",
187 () -> controller.getServiceListDictionaryEntityData(response));
191 public void testGetZoneDictionaryEntityDataByName() {
192 test_WithGetDataByColumn(Zone.class, "zoneDictionaryDatas", "zoneName",
193 () -> controller.getZoneDictionaryEntityDataByName(response));
197 public void testGetZoneDictionaryEntityData() {
198 test_WithGetData(Zone.class, "zoneDictionaryDatas", () -> controller.getZoneDictionaryEntityData(response));
202 public void testGetTermListDictionaryEntityDataByName() {
203 test_WithGetDataByColumn(TermList.class, "termListDictionaryDatas", "termName",
204 () -> controller.getTermListDictionaryEntityDataByName(response));
208 public void testGetTermListDictionaryEntityData() {
209 test_WithGetData(TermList.class, "termListDictionaryDatas",
210 () -> controller.getTermListDictionaryEntityData(response));
214 public void testGetFWDictListDictionaryEntityDataByName() {
215 test_WithGetDataByColumn(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
216 () -> controller.getFWDictListDictionaryEntityDataByName(response));
220 public void testGetFWDictionaryListEntityData() {
221 test_WithGetData(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
222 () -> controller.getFWDictionaryListEntityData(response));
226 public void testGetTagPickerNameEntityDataByName() {
227 test_WithGetDataByColumn(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
228 () -> controller.getTagPickerNameEntityDataByName(response));
232 public void testGetTagPickerDictionaryEntityData() {
233 test_WithGetData(FWTagPicker.class, "fwTagPickerDictionaryDatas",
234 () -> controller.getTagPickerDictionaryEntityData(response));
238 public void testGetTagNameEntityDataByName() {
239 test_WithGetDataByColumn(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
240 () -> controller.getTagNameEntityDataByName(response));
244 public void testGetTagDictionaryEntityData() {
245 test_WithGetData(FWTag.class, "fwTagDictionaryDatas", () -> controller.getTagDictionaryEntityData(response));
249 public void testSavePrefixListDictionary() {
250 jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"description\":\"test\",\"prefixListName\":\"Test\"}}";
251 testSave(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
252 () -> controller.savePrefixListDictionary(request, response));
256 public void testUpdatePrefixListDictionary() {
257 jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
258 testUpdate(PrefixList.class, "prefixListDictionaryDatas", "prefixListName",
259 () -> controller.savePrefixListDictionary(request, response));
263 public void testRemovePrefixListDictionary() {
264 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\"}}";
265 testRemove(PrefixList.class, "prefixListDictionaryDatas",
266 () -> controller.removePrefixListDictionary(request, response));
270 public void testValidatePrefixListDictionary() {
271 jsonString = "{\"userid\":\"demo\",\"prefixListDictionaryData\":{\"id\":1,\"description\":\"test\",\"prefixListName\":\"Test\",\"prefixListValue\":\"10.10.10\"}}";
272 testValidate(PrefixList.class, "result", () -> controller.validatePrefixListDictionary(request, response));
276 public void testSavePortListDictionary() {
277 jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"description\":\"test\",\"portName\":\"Test\"}}";
278 testSave(PortList.class, "portListDictionaryDatas", "portName",
279 () -> controller.savePortListDictionary(request, response));
283 public void testUpdatePortListDictionary() {
284 jsonString = "{\"userid\":\"demo\",\"portListDictionaryData\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
285 testUpdate(PortList.class, "portListDictionaryDatas", "portName",
286 () -> controller.savePortListDictionary(request, response));
290 public void testRemovePortListDictionary() {
291 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"portName\":\"Test\"}}";
292 testRemove(PortList.class, "portListDictionaryDatas",
293 () -> controller.removePortListDictionary(request, response));
297 public void testSaveProtocolListDictionary() {
298 jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"description\":\"test\",\"protocolName\":\"Test\"}}";
299 testSave(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
300 () -> controller.saveProtocolListDictionary(request, response));
304 public void testUpdateProtocolListDictionary() {
305 jsonString = "{\"userid\":\"demo\",\"protocolListDictionaryData\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
306 testUpdate(ProtocolList.class, "protocolListDictionaryDatas", "protocolName",
307 () -> controller.saveProtocolListDictionary(request, response));
311 public void testRemoveProtocolListDictionary() {
312 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"protocolName\":\"Test\"}}";
313 testRemove(ProtocolList.class, "protocolListDictionaryDatas",
314 () -> controller.removeProtocolListDictionary(request, response));
318 public void testSaveAddressGroupDictionary() {
319 jsonString = "{\"addressGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
320 testSave(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
321 () -> controller.saveAddressGroupDictionary(request, response));
325 public void testUpdateAddressGroupDictionary() {
326 jsonString = "{\"addressGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:409\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"groupName\":\"Test\"},\"userid\":\"demo\"}";
327 testUpdate(AddressGroup.class, "addressGroupDictionaryDatas", "name", "Group_Test",
328 () -> controller.saveAddressGroupDictionary(request, response));
332 public void testRemoveAddressGroupDictionary() {
333 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
334 testRemove(AddressGroup.class, "addressGroupDictionaryDatas",
335 () -> controller.removeAddressGroupDictionary(request, response));
339 public void testSaveActionListDictionary() {
340 jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"description\":\"test\",\"actionName\":\"Test\"}}";
341 testSave(ActionList.class, "actionListDictionaryDatas", "actionName",
342 () -> controller.saveActionListDictionary(request, response));
346 public void testUpdateActionListDictionary() {
347 jsonString = "{\"userid\":\"demo\",\"actionListDictionaryData\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
348 testUpdate(ActionList.class, "actionListDictionaryDatas", "actionName",
349 () -> controller.saveActionListDictionary(request, response));
353 public void testRemoveActionListDictionary() {
354 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"actionName\":\"Test\"}}";
355 testRemove(ActionList.class, "actionListDictionaryDatas",
356 () -> controller.removeActionListDictionary(request, response));
360 public void testSaveServiceGroupDictionary() {
361 jsonString = "{\"serviceGroupDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
362 testSave(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
363 () -> controller.saveServiceGroupDictionary(request, response));
367 public void testUpdateServiceGroupDictionary() {
368 jsonString = "{\"serviceGroupDictionaryData\":{\"id\":1, \"attributes\":[{\"$$hashKey\":\"object:657\",\"id\":\"choice1\",\"option\":\"Test\"}],\"groupName\":\"Test\"},\"userid\":\"demo\"}";
369 testUpdate(GroupServiceList.class, "serviceGroupDictionaryDatas", "name", "Group_Test",
370 () -> controller.saveServiceGroupDictionary(request, response));
374 public void testRemoveServiceGroupDictionary() {
375 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}";
376 testRemove(GroupServiceList.class, "serviceGroupDictionaryDatas",
377 () -> controller.removeServiceGroupDictionary(request, response));
381 public void testSaveSecurityZoneDictionary() {
382 jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"description\":\"test\",\"zoneName\":\"Test\"}}";
383 testSave(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
384 () -> controller.saveSecurityZoneDictionary(request, response));
388 public void testUpdateSecurityZoneDictionary() {
389 jsonString = "{\"userid\":\"demo\",\"securityZoneDictionaryData\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
390 testUpdate(SecurityZone.class, "securityZoneDictionaryDatas", "zoneName",
391 () -> controller.saveSecurityZoneDictionary(request, response));
395 public void testRemoveSecurityZoneDictionary() {
396 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"zoneName\":\"Test\"}}";
397 testRemove(SecurityZone.class, "securityZoneDictionaryDatas",
398 () -> controller.removeSecurityZoneDictionary(request, response));
402 public void testSaveServiceListDictionary() {
403 jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
404 testSave(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
405 () -> controller.saveServiceListDictionary(request, response));
409 public void testUpdateServiceListDictionary() {
410 jsonString = "{\"serviceListDictionaryData\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
411 testUpdate(ServiceList.class, "serviceListDictionaryDatas", "serviceName",
412 () -> controller.saveServiceListDictionary(request, response));
416 public void testRemoveServiceListDictionary() {
417 jsonString = "{\"data\":{\"appProtocols\":[{\"$$hashKey\":\"object:560\",\"id\":\"choice1\",\"option\":\"Test\"}],\"serviceDescription\":\"test\",\"id\":1,\"serviceName\":\"Test\",\"servicePorts\":\"1010\",\"transportProtocols\":[{\"$$hashKey\":\"object:555\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
418 testRemove(ServiceList.class, "serviceListDictionaryDatas",
419 () -> controller.removeServiceListDictionary(request, response));
423 public void testSaveZoneDictionary() {
424 jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
425 testSave(Zone.class, "zoneDictionaryDatas", "zoneName", () -> controller.saveZoneDictionary(request, response));
429 public void testUpdateZoneDictionary() {
430 jsonString = "{\"userid\":\"demo\",\"zoneDictionaryData\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
431 testUpdate(Zone.class, "zoneDictionaryDatas", "zoneName",
432 () -> controller.saveZoneDictionary(request, response));
436 public void testRemoveZoneDictionary() {
437 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"zoneValue\":\"test\",\"zoneName\":\"Test\"}}";
438 testRemove(Zone.class, "zoneDictionaryDatas", () -> controller.removeZoneDictionary(request, response));
442 public void testSaveTermListDictionary() {
443 jsonString = "{\"termListDictionaryData\":{\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
444 testSave(TermList.class, "termListDictionaryDatas", "termName",
445 () -> controller.saveTermListDictionary(request, response));
449 public void testUpdateTermListDictionary() {
450 jsonString = "{\"termListDictionaryData\":{\"id\":1,\"actionListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationListDatas\":[{\"$$hashKey\":\"object:1220\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"destinationServiceDatas\":[{\"$$hashKey\":\"object:1230\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"fromZoneDatas\":[{\"$$hashKey\":\"object:1245\",\"id\":\"choice1\",\"option\":\"Test\"}],\"sourceListDatas\":[{\"$$hashKey\":\"object:1215\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"sourceServiceDatas\":[{\"$$hashKey\":\"object:1225\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"termDescription\":\"test\",\"termName\":\"Test\",\"toZoneDatas\":[{\"$$hashKey\":\"object:1240\",\"id\":\"choice1\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
451 testUpdate(TermList.class, "termListDictionaryDatas", "termName",
452 () -> controller.saveTermListDictionary(request, response));
456 public void testRemoveTermListDictionary() {
457 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"termDescription\":\"test\",\"termName\":\"Test\"}}";
458 testRemove(TermList.class, "termListDictionaryDatas",
459 () -> controller.removeTermListDictionary(request, response));
463 public void testSaveFWDictionaryList() {
464 jsonString = "{\"fwDictListDictionaryData\":{\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
465 testSave(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
466 () -> controller.saveFWDictionaryList(request, response));
470 public void testUpdateFWDictionaryList() {
471 jsonString = "{\"fwDictListDictionaryData\":{\"id\":1,\"alAttributes\":[{\"$$hashKey\":\"object:1379\",\"id\":\"choice1\",\"option\":\"Group_Test\"}],\"attributes\":[{\"$$hashKey\":\"object:1374\",\"id\":\"choice1\",\"option\":\"Test\"}],\"description\":\"test\",\"parentItemName\":\"Test\"},\"userid\":\"demo\"}";
472 testUpdate(FirewallDictionaryList.class, "fwDictListDictionaryDatas", "parentItemName",
473 () -> controller.saveFWDictionaryList(request, response));
477 public void testRemoveFWDictionaryList() {
478 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"parentItemName\":\"Test\"}}";
479 testRemove(FirewallDictionaryList.class, "fwDictListDictionaryDatas",
480 () -> controller.removeFWDictionaryList(request, response));
484 public void testSaveFirewallTagPickerDictionary() {
485 jsonString = "{\"fwTagPickerDictionaryData\":{\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
486 testSave(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
487 () -> controller.saveFirewallTagPickerDictionary(request, response));
491 public void testUpdateFirewallTagPickerDictionary() {
492 jsonString = "{\"fwTagPickerDictionaryData\":{\"id\":1,\"description\":\"test\",\"networkRole\":\"test\",\"tagPickerName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1855\",\"id\":\"choice1\",\"number\":\"test\",\"option\":\"Test\"}]},\"userid\":\"demo\"}";
493 testUpdate(FWTagPicker.class, "fwTagPickerDictionaryDatas", "tagPickerName",
494 () -> controller.saveFirewallTagPickerDictionary(request, response));
498 public void testRemoveFirewallTagPickerDictionary() {
499 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"tagPickerName\":\"Test\"}}";
500 testRemove(FWTagPicker.class, "fwTagPickerDictionaryDatas",
501 () -> controller.removeFirewallTagPickerDictionary(request, response));
505 public void testSaveFirewallTagDictionary() {
506 jsonString = "{\"fwTagDictionaryData\":{\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
507 testSave(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
508 () -> controller.saveFirewallTagDictionary(request, response));
512 public void testUpdateFirewallTagDictionary() {
513 jsonString = "{\"fwTagDictionaryData\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\",\"tags\":[{\"$$hashKey\":\"object:1690\",\"id\":\"choice1\",\"tags\":\"test\"}]},\"userid\":\"demo\"}";
514 testUpdate(FWTag.class, "fwTagDictionaryDatas", "fwTagName",
515 () -> controller.saveFirewallTagDictionary(request, response));
519 public void testRemoveFirewallTagDictionary() {
520 jsonString = "{\"userid\":\"demo\",\"data\":{\"id\":1,\"description\":\"test\",\"fwTagName\":\"Test\"}}";
521 testRemove(FWTag.class, "fwTagDictionaryDatas",
522 () -> controller.removeFirewallTagDictionary(request, response));
526 * Tests a "get" function that uses commonClassDao.getDataByColumn().
533 private void test_WithGetDataByColumn(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
534 when(commonClassDao.getDataByColumn(clazz, contentName)).thenReturn(data);
537 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
538 verify(commonClassDao).getDataByColumn(clazz, contentName);
539 } catch (Exception e) {
540 fail("get " + clazz.getName() + e);
545 * Tests a "get" function that uses commonClassDao.getData().
552 private void test_WithGetData(Class<?> clazz, String contentData, VoidFunc func) {
553 when(commonClassDao.getData(clazz)).thenReturn(new ArrayList<>());
556 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
557 verify(commonClassDao).getData(clazz);
558 } catch (Exception e) {
559 fail("get " + clazz.getName() + e);
564 * Tests a function that uses commonClassDao.save().
571 private void testSave(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
572 testSave(clazz, contentData, contentName, "Test", func);
576 * Tests a function that uses commonClassDao.save().
584 private void testSave(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
585 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
586 when(request.getReader()).thenReturn(br);
588 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
589 verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
590 verify(commonClassDao).save(any());
591 verify(commonClassDao, never()).update(any());
592 verify(commonClassDao).getData(clazz);
594 } catch (IOException e) {
595 fail("save " + clazz.getName() + e);
600 * Tests a function that uses commonClassDao.update().
607 private void testUpdate(Class<?> clazz, String contentData, String contentName, VoidFunc func) {
608 testUpdate(clazz, contentData, contentName, "Test", func);
612 * Tests a function that uses commonClassDao.update().
620 private void testUpdate(Class<?> clazz, String contentData, String contentName, String testName, VoidFunc func) {
621 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
622 when(request.getReader()).thenReturn(br);
624 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
625 verify(commonClassDao).checkDuplicateEntry(testName, contentName, clazz);
626 verify(commonClassDao, never()).save(any());
627 verify(commonClassDao).update(any());
628 verify(commonClassDao).getData(clazz);
630 } catch (IOException e) {
631 fail("update " + clazz.getName() + e);
636 * Tests a function that uses commonClassDao.delete() and
637 * commonClassDao.getData().
643 private void testRemove(Class<?> clazz, String contentData, VoidFunc func) {
644 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
645 when(request.getReader()).thenReturn(br);
647 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
648 verify(commonClassDao).delete(any());
649 verify(commonClassDao).getData(clazz);
651 } catch (IOException e) {
652 fail("remove " + clazz.getName() + e);
657 * Tests a "validate" function.
663 private void testValidate(Class<?> clazz, String contentData, VoidFunc func) {
664 try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) {
665 when(request.getReader()).thenReturn(br);
667 assertTrue(response.getContentAsString() != null && response.getContentAsString().contains(contentData));
669 } catch (IOException e) {
670 fail("save " + clazz.getName() + e);
675 private static interface VoidFunc {
676 public void apply() throws IOException;