1. 添加HandlerMethodValidationException全局异常器
2. 新增防护对象类,添加Service、Mapper、Controller(Controller仍然在开发中) 3. page和pageSize添加@Min注解,限定最低整数大小 4. 将所有的批量类型方法修改为forEach,在SpringBoot中循环执行并整合为事务
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.realtime.protection.server.defense.object;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
@SpringBootTest
|
||||
class ProtectObjectServiceTest {
|
||||
|
||||
private final ProtectObjectService protectObjectService;
|
||||
|
||||
@Autowired
|
||||
ProtectObjectServiceTest(ProtectObjectService protectObjectService) {
|
||||
this.protectObjectService = protectObjectService;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteProtectObject() {
|
||||
Boolean success = protectObjectService.deleteProtectObjects(List.of(1, 2, 3, 4));
|
||||
assertFalse(success);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@@ -24,7 +26,7 @@ class TemplateServiceTest {
|
||||
template = new Template();
|
||||
|
||||
template.setTemplateName("反射型DDOS攻击");
|
||||
template.setTemplateElements(new String[]{"对端IP", "协议", "URL"});
|
||||
template.setTemplateElements(List.of("对端IP", "协议", "URL"));
|
||||
template.setDefaultOp("阻断");
|
||||
}
|
||||
|
||||
@@ -36,10 +38,26 @@ class TemplateServiceTest {
|
||||
|
||||
@Test
|
||||
void testNewTemplateIllegalArgument() {
|
||||
template.setTemplateElements(new String[]{"DDNS"});
|
||||
template.setTemplateElements(List.of("DDNS"));
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
Integer templateId = templateService.newTemplate(template);
|
||||
assertTrue(templateId > 0);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateTemplateSuccess() {
|
||||
template.setTemplateName("洪泛型DDOS攻击");
|
||||
assertTrue(templateService.updateTemplate(3, template));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddTemplateUsedTimes() {
|
||||
List<Template> templates = templateService.queryTemplates("洪泛型DDOS攻击", 1, 1);
|
||||
Template originalTemplate = templates.get(0);
|
||||
Boolean success = templateService.addTemplateUsedTimes(3, 4);
|
||||
templates = templateService.queryTemplates("洪泛型DDOS攻击", 1, 1);
|
||||
assertEquals(templates.get(0).getTemplateUsedTimes(), originalTemplate.getTemplateUsedTimes() + 4);
|
||||
assertTrue(success);
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,12 @@ class TaskServiceTest {
|
||||
task.setTaskEndTime(taskEndTime);
|
||||
task.setTaskAct("阻断");
|
||||
task.setTaskType("静态任务");
|
||||
task.setStaticRuleIds(new Integer[]{1, 2});
|
||||
task.setDynamicRuleIds(new Integer[]{});
|
||||
task.setStaticRuleIds(List.of(1, 2));
|
||||
task.setDynamicRuleIds(List.of());
|
||||
task.setTaskCreateUserId(1);
|
||||
task.setTaskCreateUsername("xxx");
|
||||
task.setTaskCreateDepart("xxx");
|
||||
task.setProtectObjectIds(new Integer[]{1});
|
||||
task.setProtectObjectIds(List.of(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user