REM:
1.优化获取处置任务接口,响应结果排序
2.删除taskId字段的校验器
3.修改查询处置任务的响应类
4.测试测试用例
This commit is contained in:
chenlinghy 2020-09-25 09:56:51 +08:00
parent 14e1bb35c3
commit 49dd49b8ca
8 changed files with 67 additions and 51 deletions

View File

@ -46,6 +46,7 @@ import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@ -258,7 +259,7 @@ public class DisposeTaskController {
@PostMapping("/taskList")
@ResponseBody
@ApiOperation("获取处置任务")
public ProtocolRespDTO<? extends BaseRespStatus> getAllDisposeTask(
public ProtocolRespDTO<GetTaskRsp> getAllDisposeTask(
@Validated(ValidGroups.ProtocolCommonValid.class)
@RequestBody ProtocolReqDTO<BasePagesGetReq> mr
) {
@ -266,7 +267,7 @@ public class DisposeTaskController {
List<GetTaskDetail> getTaskDetail = new ArrayList<>();
//获取TaskId列表
List<Long> reqTaskIds = Arrays.stream(mr.getMsgContent().getTaskId()).
List<Long> reqTaskIds = Arrays.stream(Optional.ofNullable(mr.getMsgContent().getTaskId()).orElse(new String[]{})).
map(Long::parseLong).collect(Collectors.toList());
//获取所有可用处置任务
@ -299,10 +300,11 @@ public class DisposeTaskController {
.attackType(v.getAttackType().toString())
.flowBandWidth(v.getFlowBandWidth())
.currentStatus(v.getCurrentStatus().getValue())
.status(ErrorCode.ERR_OK.getCode())
.message(new String[]{ErrorCode.ERR_OK.getMsg()})
.deviceTask(new ArrayList<>())
.build();
taskDetail.setStatus(ErrorCode.ERR_OK.getCode());
taskDetail.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()});
v.getDeviceTask().forEach(k -> {
GetDeviceTaskDetail deviceTaskDetail = GetDeviceTaskDetail.builder()
.devTaskId(String.valueOf(k.getId()))
@ -310,7 +312,6 @@ public class DisposeTaskController {
.externId(String.valueOf(k.getExternId()))
.status(k.getStatus())
.build();
taskDetail.getDeviceTask().add(deviceTaskDetail);
});
@ -331,7 +332,9 @@ public class DisposeTaskController {
});
}
rspInfo.setItems(getTaskDetail);
// 对返回的信息按照TaskID排序
rspInfo.setItems(getTaskDetail.stream().sorted(Comparator.comparing(GetTaskDetail::getTaskId))
.collect(Collectors.toList()));
return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo);
}

View File

@ -26,8 +26,6 @@ public class BasePagesGetReq {
/**
* The Task Id.
*/
@NotNull(message = "taskId 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
@Size(min = 1, message = "taskId 字段必须指定明确任务id编号", groups = ValidGroups.ExplicitIdArrayValid.class)
private String[] taskId;
/**
* The Start page.

View File

@ -1,10 +1,12 @@
package com.dispose.pojo.dto.protocol.task;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.List;
@ -14,6 +16,7 @@ import java.util.List;
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@ -21,7 +24,7 @@ import java.util.List;
@JsonPropertyOrder({"taskId", "accountId", "disposeCapacity", "disposeIp", "createTime", "planEndTime", "endTime",
"flowDirection", "attackType", "flowBandWidth", "currentStatus", "deviceTask", "status", "message"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetTaskDetail {
public class GetTaskDetail extends BaseRespStatus {
/**
* The Task id.
@ -67,15 +70,6 @@ public class GetTaskDetail {
* The Current status.
*/
private Integer currentStatus;
/**
* 0成功其它失败原因.
*/
private Integer status;
/**
* 登录消息: status状态码对应的提示信息
*/
private String[] message;
/**
* The Device task.
*/

View File

@ -1,12 +1,10 @@
package com.dispose.pojo.dto.protocol.task;
import com.dispose.pojo.dto.protocol.base.BaseRespStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.ArrayList;
import java.util.List;
@ -16,13 +14,12 @@ import java.util.List;
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@AllArgsConstructor
@JsonPropertyOrder({"curPageNumber", "pageSize", "totalItems", "totalPages", "status", "message", "items"})
@JsonPropertyOrder({"curPageNumber", "pageSize", "totalItems", "totalPages", "items"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GetTaskRsp extends BaseRespStatus {
public class GetTaskRsp {
/**
* The Cur page number.

View File

@ -56,7 +56,11 @@ public class CodeCoverage {
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) CodeCoverage::verifyJsonExceptionResp)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.prepareCallback(c -> SecurityConfigValue.SECURITY_PROTOCOL_TYPE = ProtoCryptoType.CRYPTO_AES128.getCode())
.build(),
};

View File

@ -305,7 +305,7 @@ public class P1All {
.priority(TestPriority.P1_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," +
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"taskId\":[],\"startPage\":1," +
"\"pageSize\":10}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_OK)
@ -314,9 +314,9 @@ public class P1All {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long)v.getCode(), e.getHttpCode());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
//Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 1);
Assert.assertEquals((long) v.getMsgContent().getPageSize(), 10);
// Assert.assertEquals((long) v.getMsgContent().getPageSize(), 10);
Assert.assertNotEquals(v.getMsgContent().getItems().size(), 0);
})
.build(),

View File

@ -33,7 +33,7 @@ public class P2TaskList {
.priority(TestPriority.P2_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":2," +
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"taskId\":[], \"startPage\":2," +
"\"pageSize\":20}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_OK)
@ -43,9 +43,9 @@ public class P2TaskList {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
//Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 2);
Assert.assertEquals((long) v.getMsgContent().getCurPageNumber(), 1);
Assert.assertEquals((long)v.getMsgContent().getPageSize(), 20);
Assert.assertNotNull(v.getMsgContent().getItems());
@ -74,7 +74,7 @@ public class P2TaskList {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
//Assert.assertEquals((long) v.getMsgContent().getStatus(), e.getCode());
})
.build(),
};

View File

@ -257,18 +257,22 @@ public class P3All {
.verifyCallback((VerifyProtoRespCallback<TaskStopRsp>) P3All::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P3_ALL_ID + 18)
.name("msgContent为null")
.priority(TestPriority.P3_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":null}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) P3All::verifyJsonExceptionResp)
.build(),
QATestItem.builder()
.id(BASE_P3_ALL_ID + 18)
.name("msgContent为null")
.priority(TestPriority.P3_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":null}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.build(),
QATestItem.builder()
.id(BASE_P3_ALL_ID + 19)
@ -277,11 +281,15 @@ public class P3All {
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," +
"\"msgContent\":{\"startPage\":null,\"pageSize\":10}}")
"\"msgContent\":{\"taskId\":[],\"startPage\":null,\"pageSize\":10}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) P3All::verifyJsonExceptionResp)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.build(),
QATestItem.builder()
@ -291,11 +299,15 @@ public class P3All {
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234," +
"\"msgContent\":{\"startPage\":\"1\",\"pageSize\":10}}")
"\"msgContent\":{\"taskId\":[],\"startPage\":\"1\",\"pageSize\":10}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) P3All::verifyJsonExceptionResp)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.build(),
QATestItem.builder()
@ -304,12 +316,16 @@ public class P3All {
.priority(TestPriority.P3_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," +
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"taskId\":[],\"startPage\":1," +
"\"pageSize\":null}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) P3All::verifyJsonExceptionResp)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.build(),
QATestItem.builder()
@ -318,12 +334,16 @@ public class P3All {
.priority(TestPriority.P3_PRIORITY)
.urlPath("/task/taskList")
.method(RequestMethod.POST)
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"startPage\":1," +
.caseJsonValue("{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1598596065234,\"msgContent\":{\"taskId\":[],\"startPage\":1," +
"\"pageSize\":\"10\"}}")
.rspClass(GetTaskRsp.class)
.rspCode(ErrorCode.ERR_PARAMEXCEPTION)
.autoLogin(true)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) P3All::verifyJsonExceptionResp)
.verifyCallback((VerifyProtoRespCallback<GetTaskRsp>) (v, e, c) -> {
Assert.assertNotNull(v);
Assert.assertNotNull(v.getMsgContent());
Assert.assertEquals((long) v.getCode(), e.getHttpCode());
})
.build(),
};