parent
57637106a5
commit
684a56d5c8
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -14,6 +15,7 @@ import java.util.List;
|
|||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class TaskStartMulRsp {
|
||||
|
|
|
@ -8,19 +8,21 @@ import com.dispose.common.DisposeTaskStatus;
|
|||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.NetflowDirection;
|
||||
import com.dispose.common.ProtoCryptoType;
|
||||
import com.dispose.mapper.DisposeDeviceMapper;
|
||||
import com.dispose.mapper.DisposeTaskMapper;
|
||||
import com.dispose.pojo.dto.protocol.base.BaseIdResp;
|
||||
import com.dispose.pojo.dto.protocol.base.IdArraysReq;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO;
|
||||
import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO;
|
||||
import com.dispose.pojo.dto.protocol.task.TaskStartReq;
|
||||
import com.dispose.pojo.dto.protocol.task.TaskStartRsp;
|
||||
import com.dispose.pojo.dto.protocol.task.TaskStopRsp;
|
||||
import com.dispose.pojo.dto.protocol.device.manager.BasePagesGetReq;
|
||||
import com.dispose.pojo.dto.protocol.task.*;
|
||||
import com.dispose.pojo.entity.DisposeTask;
|
||||
import com.dispose.pojo.po.MulReturnType;
|
||||
import com.dispose.service.DisposeDeviceManagerService;
|
||||
import com.dispose.service.DisposeTaskService;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import jodd.net.HttpStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
|
@ -71,15 +73,20 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
/**
|
||||
* The Dispose task manager.
|
||||
* The Dispose task mapper.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskMapper disposeTaskManager;
|
||||
private DisposeTaskMapper disposeTaskMapper;
|
||||
/**
|
||||
* The Dispose device mapper.
|
||||
* The Dispose device manager service.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeDeviceMapper disposeDeviceMapper;
|
||||
private DisposeDeviceManagerService disposeDeviceManagerService;
|
||||
/**
|
||||
* The Dispose task service.
|
||||
*/
|
||||
@Resource
|
||||
private DisposeTaskService disposeTaskService;
|
||||
|
||||
/**
|
||||
* A 1 start task protocol resp dto.
|
||||
|
@ -89,7 +96,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
@Test
|
||||
public void a1_startTask() throws Exception {
|
||||
TaskStartReq req = TaskStartReq.builder()
|
||||
.id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId()))
|
||||
.id(String.valueOf(disposeDeviceManagerService.getAllDisposeDevice().get(0).getId()))
|
||||
.type(DisposeCapacityType.CLEANUP.getValue())
|
||||
.disposeIp("192.168.100.100")
|
||||
.disposeTime(60)
|
||||
|
@ -129,7 +136,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
Assert.assertNotNull(rspInfo.getMsgContent().getMessage());
|
||||
Assert.assertNotNull(rspInfo.getMsgContent().getTaskId());
|
||||
|
||||
disposeTaskManager.selectAll().forEach(v -> {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
if (v.getDeviceId().equals(Long.valueOf(req.getId())) &&
|
||||
v.getDisposeIp().equals(req.getDisposeIp()) &&
|
||||
v.getAttackType().equals((long) DDoSAttackType.ACK_FLOOD.getValue())) {
|
||||
|
@ -146,7 +153,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
*/
|
||||
@Test
|
||||
public void a2_startTaskExisted() throws Exception {
|
||||
DisposeTask disposeTask = disposeTaskManager.selectAll().get(0);
|
||||
DisposeTask disposeTask = disposeTaskMapper.selectAll().get(0);
|
||||
|
||||
TaskStartReq req = TaskStartReq.builder()
|
||||
.id(String.valueOf(disposeTask.getDeviceId()))
|
||||
|
@ -207,9 +214,9 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
List<String> taskIds = new ArrayList<>();
|
||||
List<String> runTaskIds = new ArrayList<>();
|
||||
|
||||
disposeTaskManager.selectAll().forEach(v -> taskIds.add(String.valueOf(v.getId())));
|
||||
disposeTaskMapper.selectAll().forEach(v -> taskIds.add(String.valueOf(v.getId())));
|
||||
|
||||
disposeTaskManager.selectAll().forEach(v -> {
|
||||
disposeTaskMapper.selectAll().forEach(v -> {
|
||||
if (v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW ||
|
||||
v.getCurrentStatus() == DisposeTaskStatus.TASK_STARTING ||
|
||||
v.getCurrentStatus() == DisposeTaskStatus.TASK_STARTED) {
|
||||
|
@ -276,7 +283,7 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
String[] mulDisposeIp = {"192.168.5.2", "192.168.5.3"};
|
||||
|
||||
TaskStartReq req = TaskStartReq.builder()
|
||||
.id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId()))
|
||||
.id(String.valueOf(disposeDeviceManagerService.getAllDisposeDevice().get(0).getId()))
|
||||
.type(DisposeCapacityType.CLEANUP.getValue())
|
||||
.mulDisposeIp(mulDisposeIp)
|
||||
.disposeTime(60)
|
||||
|
@ -303,15 +310,17 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ProtocolRespDTO<List<TaskStartRsp>> rspInfo = objectMapper.readValue(ret,
|
||||
new TypeReference<ProtocolRespDTO<List<TaskStartRsp>>>() {
|
||||
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(ret));
|
||||
ProtocolRespDTO<TaskStartMulRsp> rspInfo = objectMapper.readValue(ret,
|
||||
new TypeReference<ProtocolRespDTO<TaskStartMulRsp>>() {
|
||||
});
|
||||
|
||||
verifyRespProtocol(rspInfo);
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMsgContent());
|
||||
rspInfo.getMsgContent().forEach(v->{
|
||||
rspInfo.getMsgContent().getItems().forEach(v -> {
|
||||
Assert.assertNotNull(v.getStatus());
|
||||
Assert.assertNotNull(v.getMessage());
|
||||
Assert.assertNotNull(v.getDisposeIp());
|
||||
|
@ -323,4 +332,49 @@ public class DisposeTaskControllerTest extends InitTestEnvironment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A 5 gets all dispose task.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
public void a5_getAllDisposeTask() throws Exception {
|
||||
BasePagesGetReq req = BasePagesGetReq.builder()
|
||||
.startPage(1)
|
||||
.pageSize(20)
|
||||
.build();
|
||||
|
||||
ProtocolReqDTO<BasePagesGetReq> reqInfo = new ProtocolReqDTO<>();
|
||||
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode());
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(req);
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/task/taskList")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + getLoginToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(HttpStatus.ok().status()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ProtocolRespDTO<GetTaskRsp> rspInfo = objectMapper.readValue(ret,
|
||||
new TypeReference<ProtocolRespDTO<GetTaskRsp>>() {
|
||||
});
|
||||
|
||||
verifyRespProtocol(rspInfo);
|
||||
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
|
||||
|
||||
Assert.assertNotNull(rspInfo.getMsgContent());
|
||||
Assert.assertTrue(rspInfo.getMsgContent().getCurPageNumber() <= req.getPageSize());
|
||||
Assert.assertEquals(rspInfo.getMsgContent().getPageSize(), req.getPageSize());
|
||||
|
||||
MulReturnType<PageInfo<DisposeTask>, List<DisposeTask>> result = disposeTaskService.getPageDisposeTask(req.getStartPage(), req.getPageSize());
|
||||
Assert.assertTrue(rspInfo.getMsgContent().getTotalItems() >= result.getSecondParam().size());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue