REM:
1. 增加任务管理数据库接口
2. 增加任务管理数据库接口单元测试用例
3. 修正部分接口字段和协议不符问题
4. 重新格式化代码,符合公司代码规范
This commit is contained in:
huangxin 2020-04-23 19:19:30 +08:00
parent d41bb15bfa
commit 2b5d0e859d
24 changed files with 503 additions and 86 deletions

View File

@ -125,6 +125,72 @@ public class ConstValue {
}
}
public enum DisposeTaskStatus {
TASK_NEW(0, "新建"),
TASK_RUNNING(1, "运行中"),
TASK_STOP(2, "停止"),
TASK_FINISH(3, "结束"),
TASK_DELETE(4, "删除");
private final int code;
private final String readme;
DisposeTaskStatus(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets code.
*
* @return the code
*/
public int getCode() {
return this.code;
}
/**
* Gets readme.
*
* @return the readme
*/
public String getReadme() {
return this.readme;
}
}
public enum FlowDirection {
DIRECTION_INPUT(0, "流入"),
DIRECTION_OUTPUT(1, "流出"),
DIRECTION_TWOWAY(2, "双向");
private final int code;
private final String readme;
FlowDirection(int code, String readme) {
this.code = code;
this.readme = readme;
}
/**
* Gets code.
*
* @return the code
*/
public int getCode() {
return this.code;
}
/**
* Gets readme.
*
* @return the readme
*/
public String getReadme() {
return this.readme;
}
}
/**
* The type Global configure.
*/

View File

@ -5,28 +5,24 @@ package com.dispose.common;
*/
public class GlobalVar {
/**
* The constant MAX_THREAT_INFO_VERSION.
*/
public static volatile int MAX_THREAT_INFO_VERSION = -1;
/**
* The constant THREAT_INFO_TYPE.
*/
public static volatile String THREAT_INFO_TYPE = "1";
/**
* The constant USED_VIRTUAL_DISPOSE_MODE.
*/
public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false;
/**
* The constant SOAP_CONNECT_TIMEOUT.
*/
public static final int SOAP_CONNECT_TIMEOUT = 1000;
/**
* The constant SOAP_RECEIVE_TIMEOUT.
*/
public static final int SOAP_RECEIVE_TIMEOUT = 1000;
/**
* The constant MAX_THREAT_INFO_VERSION.
*/
public static volatile int MAX_THREAT_INFO_VERSION = -1;
/**
* The constant THREAT_INFO_TYPE.
*/
public static volatile String THREAT_INFO_TYPE = "1";
/**
* The constant USED_VIRTUAL_DISPOSE_MODE.
*/
public static volatile boolean USED_VIRTUAL_DISPOSE_MODE = false;
}

View File

@ -16,8 +16,8 @@ public class EncodingFilterConfig {
* @return the filter registration bean
*/
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
public FilterRegistrationBean<CharacterEncodingFilter> filterRegistrationBean() {
FilterRegistrationBean<CharacterEncodingFilter> registrationBean = new FilterRegistrationBean<>();
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setForceEncoding(true);
characterEncodingFilter.setEncoding("UTF-8");

View File

@ -80,7 +80,7 @@ public class DisposeNodeInfoController {
if (devs != null && devs.size() > 0) {
devs.forEach(v -> {
LinkStatusRsp linkStat = LinkStatusRsp.builder().online(v.getLinkStatus()).build();
linkStat.setId(v.getId().toString());
linkStat.setStatus(ErrorCode.ERR_OK.getCode());
linkStat.setMessage(ErrorCode.ERR_OK.getMsg());
@ -97,6 +97,7 @@ public class DisposeNodeInfoController {
err = ErrorCode.ERR_OK;
} else {
linkStat = LinkStatusRsp.builder().online(0).build();
linkStat.setId(v);
err = ErrorCode.ERR_NOSUCHDEVICE;
}
@ -387,18 +388,28 @@ public class DisposeNodeInfoController {
public ProtocolRespDTO getDisposeNodeList(@RequestBody ProtocolReqDTO mr,
@RequestHeader HttpHeaders headers)
throws JsonProcessingException {
boolean isGetAllNode = false;
IDArrayReq reqInfo = null;
ErrorCode err = mr.verifyRequest(headers);
if (err != ErrorCode.ERR_OK) {
return ProtocolRespDTO.result(err);
}
IDArrayReq reqInfo = mr.getRequestObject(IDArrayReq.class);
if (mr.getMsgContent() == null || mr.getMsgContent().length() == 0) {
isGetAllNode = true;
} else {
reqInfo = mr.getRequestObject(IDArrayReq.class);
if (reqInfo == null || reqInfo.getId() == null || reqInfo.getId().length == 0) {
isGetAllNode = true;
}
}
DisposeNodeListRsp rspInfo = new DisposeNodeListRsp();
rspInfo.setItems(new ArrayList<>());
if (reqInfo.getId().length == 0) {
if (isGetAllNode) {
List<DisposeDevice> devList = disposeNodeManager.getAllDisposeDevice();
if (devList != null && devList.size() > 0) {

View File

@ -4,10 +4,10 @@ import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.common.TaskInfoData;
import com.dispose.pojo.vo.task.StartTaskReq;
import com.dispose.pojo.vo.task.StartTaskRsp;
import com.dispose.pojo.vo.task.StopTaskReq;
import com.dispose.pojo.vo.task.TaskInfoData;
import com.dispose.pojo.vo.task.TaskInfoRsp;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;

View File

@ -32,13 +32,12 @@ import org.apache.wss4j.dom.handler.WSHandlerConstants;
*/
@Slf4j
public class DPTechImpl implements DisposeEntryManager {
@Resource
private DisposeConfigure disposeConfigure;
/**
* The Clean type port.
*/
AbnormalFlowCleaningServicePortType cleanTypePort;
@Resource
private DisposeConfigure disposeConfigure;
/**
* Instantiates a new Dp tech.

View File

@ -1,15 +1,13 @@
package com.dispose.mapper;
import com.dispose.pojo.entity.DisposeDevice;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
/**
* The interface Dispose device mapper.
*/
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>,
IdsMapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
/**
* Add new dispose device.
*

View File

@ -0,0 +1,78 @@
package com.dispose.mapper;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
/**
* The interface Dispose task mapper.
*/
public interface DisposeTaskMapper extends Mapper<TaskInfoDetail>,
IdsMapper<TaskInfoDetail>, MySqlMapper<TaskInfoDetail> {
/**
* Add new task.
*
* @param taskInfo the task info
*/
void addNewTask(TaskInfoDetail taskInfo);
/**
* Remove task by id.
*
* @param id the id
*/
void removeTaskById(Long id);
/**
* Change task current status.
*
* @param id the id
* @param status the status
*/
void changeTaskCurrentStatus(@Param("id") Long id,
@Param("status") int status);
/**
* Gets task current status.
*
* @param id the id
* @return the task current status
*/
int getTaskCurrentStatus(Long id);
/**
* Gets task info by id.
*
* @param id the id
* @return the task info by id
*/
TaskInfoDetail getTaskInfoById(Long id);
/**
* Gets all task by dispose ip.
*
* @param ipAddr the ip addr
* @return the all task by dispose ip
*/
List<TaskInfoDetail> getAllTaskByDisposeIp(String ipAddr);
/**
* Gets all task by node dev id.
*
* @param devId the dev id
* @return the all task by node dev id
*/
List<TaskInfoDetail> getAllTaskByNodeDevId(Long devId);
/**
* Gets all task by node user id.
*
* @param userId the user id
* @return the all task by node user id
*/
List<TaskInfoDetail> getAllTaskByNodeUserId(Long userId);
}

View File

@ -2,11 +2,15 @@ package com.dispose.mapper;
import com.dispose.pojo.entity.UserAccount;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.IdsMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
/**
* The interface User account mapper.
*/
public interface UserAccountMapper {
public interface UserAccountMapper extends Mapper<UserAccount>,
IdsMapper<UserAccount>, MySqlMapper<UserAccount> {
/**
* Gets user by name.
*

View File

@ -26,16 +26,19 @@ public class DisposeCapacity {
private int tolCapacity;
@JsonView(CapacityView.class)
private int usedCapacity;
/**
* The interface Base view.
*/
public interface BaseView {
}
/**
* The interface Capacity view.
*/
public interface CapacityView extends BaseView {
}
/**
* The interface Depend ip view.
*/

View File

@ -1,6 +1,5 @@
package com.dispose.pojo.vo.task;
package com.dispose.pojo.vo.common;
import com.dispose.pojo.vo.common.IDReturnStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;

View File

@ -0,0 +1,77 @@
package com.dispose.pojo.vo.common;
import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.Style;
/**
* The type Task info detail.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "dispose_task")
@NameStyle(Style.normal)
public class TaskInfoDetail implements Serializable {
/**
* The constant serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* The Id.
*/
@Id
private Long id;
/**
* The Device id.
*/
private Long deviceId;
/**
* The Account id.
*/
private Long accountId;
/**
* The Type.
*/
private int type;
/**
* The Dispose ip.
*/
private String disposeIp;
/**
* The Begin time.
*/
private String beginTime;
/**
* The Plan end time.
*/
private String planEndTime;
/**
* The End time.
*/
private String endTime;
/**
* The Flow direction.
*/
private int flowDirection;
/**
* The Attack type.
*/
private String attackType;
/**
* The Flow band width.
*/
private int flowBandWidth;
/**
* The Current status.
*/
private int currentStatus;
}

View File

@ -1,5 +1,6 @@
package com.dispose.pojo.vo.task;
import com.dispose.pojo.vo.common.TaskInfoData;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;

View File

@ -87,7 +87,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
DisposeDevice dev = disposeDevMap.get(ipAddr);
if(dev == null) {
if (dev == null) {
return ErrorCode.ERR_NOSUCHDEVICE;
}

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dispose.mapper.DisposeTaskMapper">
<insert id="addNewTask" useGeneratedKeys="true" keyProperty="id" parameterType="com.dispose.pojo.vo.common.TaskInfoDetail">
INSERT IGNORE INTO
dispose_task(deviceId, accountId, type, disposeIp,
planEndTime, flowDirection, attackType, flowBandWidth,
currentStatus)
VALUES
(#{deviceId}, #{accountId}, #{type}, #{disposeIp},
#{planEndTime}, #{flowDirection}, #{attackType},
#{flowBandWidth}, #{currentStatus}
)
</insert>
<delete id="removeTaskById" parameterType="java.lang.Long">
DELETE
dispose_task
FROM
dispose_task
WHERE
dispose_task.id = #{id}
</delete>
<update id="changeTaskCurrentStatus">
UPDATE
dispose_task
SET
currentStatus = #{status, jdbcType=INTEGER}
WHERE
id = #{id, jdbcType=INTEGER}
</update>
<select id="getTaskCurrentStatus" resultType="java.lang.Integer">
SELECT currentStatus FROM dispose_task
WHERE
id = #{id, jdbcType=INTEGER}
</select>
<select id="getTaskInfoById" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
SELECT * FROM dispose_task
WHERE
id = #{id, jdbcType=INTEGER}
</select>
<select id="getAllTaskByDisposeIp" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
SELECT * FROM dispose_task
WHERE
disposeIp = #{disposeIp, jdbcType=VARCHAR}
</select>
<select id="getAllTaskByNodeDevId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
SELECT * FROM dispose_task
WHERE
deviceId = #{devId, jdbcType=INTEGER}
</select>
<select id="getAllTaskByNodeUserId" resultType="com.dispose.pojo.vo.common.TaskInfoDetail">
SELECT * FROM dispose_task
WHERE
deviceId = #{userId, jdbcType=INTEGER}
</select>
</mapper>

View File

@ -4,14 +4,12 @@ import com.dispose.common.ErrorCode;
import com.dispose.common.GlobalVar;
import com.dispose.pojo.po.MReturnType;
import com.dispose.service.UserAccountService;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.context.annotation.Profile;
import org.springframework.test.context.ActiveProfiles;
/**
@ -21,13 +19,21 @@ import org.springframework.test.context.ActiveProfiles;
@Getter
@ActiveProfiles("test")
public class InitTestEnvironment {
private static String logToken = "45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122";
private final String USER_NAME = "admin";
private final String PASSWORD = "c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58";
private static String logToken = "45509b805d955cfd5ef7093e27a8bb99b3733d9a7bf90e88ba528bcbd29c6122";
@Resource
private UserAccountService userAccountService;
/**
* Init virtual device.
*/
@BeforeClass
public static void initVirtualDevice() {
GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true;
log.warn("Current Used Virtual Dispose Device");
}
/**
* User login.
*
@ -52,13 +58,4 @@ public class InitTestEnvironment {
public String getLogToken() {
return logToken;
}
/**
* Init virtual device.
*/
@BeforeClass
public static void initVirtualDevice() {
GlobalVar.USED_VIRTUAL_DISPOSE_MODE = true;
log.warn("Current Used Virtual Dispose Device");
}
}

View File

@ -11,6 +11,7 @@ import com.dispose.dptech.DPTechInterfaceTestCase;
import com.dispose.help.GetVersionTest;
import com.dispose.manager.UserAccountManagerTest;
import com.dispose.mapper.DisposeDeviceMapperTest;
import com.dispose.mapper.DisposeTaskMapperTest;
import com.dispose.mapper.UserAccountMapperTest;
import com.dispose.service.UserAccountServiceTest;
import org.junit.runner.RunWith;
@ -24,6 +25,7 @@ import org.junit.runners.Suite;
MyConfigTest.class,
DisposeConfigureTest.class,
GetVersionTest.class,
DisposeTaskMapperTest.class,
DPTechInterfaceTestCase.class,
UserAccountMapperTest.class,
UserAccountManagerTest.class,

View File

@ -2,18 +2,14 @@ package com.dispose.controller;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.dto.ProtocolRespDTO;
import com.dispose.pojo.po.MReturnType;
import com.dispose.pojo.vo.auth.LoginReq;
import com.dispose.pojo.vo.auth.LoginRsp;
import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;

View File

@ -2,18 +2,14 @@ package com.dispose.controller;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MReturnType;
import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -78,23 +74,6 @@ public class DeviceNodeInfoControllerTest extends InitTestEnvironment {
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/version")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
reqData = IDArrayReq.builder()
.id(new String[]{})
.build();
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/information/version")
.contentType(MediaType.APPLICATION_JSON)

View File

@ -2,9 +2,7 @@ package com.dispose.controller;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.common.ErrorCode;
import com.dispose.pojo.dto.ProtocolReqDTO;
import com.dispose.pojo.po.MReturnType;
import com.dispose.pojo.vo.common.IDArrayReq;
import com.dispose.pojo.vo.task.StartTaskReq;
import com.dispose.pojo.vo.task.StopTaskData;
@ -13,14 +11,10 @@ import com.dispose.service.UserAccountService;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@ -33,8 +27,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@AutoConfigureMockMvc
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class TaskControllerTest extends InitTestEnvironment {
@Resource
private MockMvc mockMvc;

View File

@ -29,7 +29,8 @@ import org.springframework.test.context.junit4.SpringRunner;
public class DPTechInterfaceTestCase extends InitTestEnvironment {
@Override
public void userLogin() {}
public void userLogin() {
}
/**
* T 1 get all detection object from umc.

View File

@ -58,7 +58,7 @@ public class ExceptionTest {
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
String ret = mockMvc.perform(MockMvcRequestBuilders
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(reqInfo)))

View File

@ -77,9 +77,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v -> {
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0);
});
dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsByIp(v.getIpAddr()), 0));
}
/**
@ -92,9 +90,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment {
List<DisposeDevice> dp = disposeDeviceMapper.selectAll();
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(dp));
dp.forEach(v -> {
Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0);
});
dp.forEach(v -> Assert.assertNotEquals(disposeDeviceMapper.isDeviceExistsById(v.getId()), 0));
}
/**

View File

@ -0,0 +1,158 @@
package com.dispose.mapper;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* The type Dispose task mapper test.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DisposeTaskMapperTest extends InitTestEnvironment {
/**
* The Obj mapper.
*/
@Resource
private ObjectMapper objMapper;
/**
* The Dispose task mapper.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* The User account mapper.
*/
@Resource
private UserAccountMapper userAccountMapper;
/**
* The Dispose device mapper.
*/
@Resource
private DisposeDeviceMapper disposeDeviceMapper;
/**
* The Device id.
*/
private Long deviceId;
/**
* The Account id.
*/
private Long accountId;
/**
* User login.
*/
@Override
public void userLogin() {
deviceId = disposeDeviceMapper.selectAll().get(0).getId();
accountId = userAccountMapper.selectAll().get(0).getId();
}
/**
* T 1 add new task test.
*/
@Test
public void t1_addNewTaskTest() {
LocalDateTime endTime = LocalDateTime.now().plusMinutes(10);
TaskInfoDetail taskData = TaskInfoDetail.builder()
.id(-1L)
.deviceId(deviceId)
.accountId(accountId)
.type(ConstValue.DeviceCapacity.CLEANUP.getCode())
.disposeIp("192.168.0.1")
.flowDirection(ConstValue.FlowDirection.DIRECTION_TWOWAY.getCode())
.currentStatus(ConstValue.DisposeTaskStatus.TASK_NEW.getCode())
.planEndTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.endTime(endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.build();
disposeTaskMapper.addNewTask(taskData);
Assert.assertNotEquals(java.util.Optional.ofNullable(taskData.getId()), -1L);
Assert.assertNotNull(disposeTaskMapper.getTaskInfoById(taskData.getId()));
}
/**
* T 2 change task status test.
*/
@Test
public void t2_changeTaskStatusTest() {
disposeTaskMapper.selectAll().forEach(v -> {
for (ConstValue.DisposeTaskStatus k : ConstValue.DisposeTaskStatus.values()) {
disposeTaskMapper.changeTaskCurrentStatus(v.getId(), k.getCode());
Assert.assertEquals(disposeTaskMapper.getTaskCurrentStatus(v.getId()), k.getCode());
}
});
}
/**
* T 3 get task info by id test.
*/
@Test
public void t3_getTaskInfoByIdTest() {
disposeTaskMapper.selectAll().forEach(v -> {
TaskInfoDetail taskInfo = disposeTaskMapper.getTaskInfoById(v.getId());
Assert.assertNotNull(taskInfo);
Assert.assertEquals(taskInfo.getId(), v.getId());
});
}
/**
* T 4 get all task by dispose ip test.
*/
@Test
public void t4_getAllTaskByDisposeIpTest() {
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
.getAllTaskByDisposeIp(v.getDisposeIp())
.forEach(k -> Assert.assertEquals(k.getDisposeIp(), v.getDisposeIp())));
}
/**
* T 5 get all task by node dev id.
*/
@Test
public void t5_getAllTaskByNodeDevId() {
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
.getAllTaskByNodeDevId(v.getDeviceId())
.forEach(k -> Assert.assertEquals(k.getDeviceId(), v.getDeviceId())));
}
/**
* T 6 get all task by node user id.
*/
@Test
public void t6_getAllTaskByNodeUserId() {
disposeTaskMapper.selectAll().forEach(v -> disposeTaskMapper
.getAllTaskByNodeUserId(v.getAccountId())
.forEach(k -> Assert.assertEquals(k.getAccountId(), v.getAccountId())));
}
/**
* T 99 remove task test.
*/
@Test
public void t99_removeTaskTest() {
disposeTaskMapper.selectAll().forEach(v -> {
disposeTaskMapper.removeTaskById(v.getId());
Assert.assertNull(disposeTaskMapper.getTaskInfoById(v.getId()));
});
}
}