diff --git a/src/main/java/com/dispose/common/ConstValue.java b/src/main/java/com/dispose/common/ConstValue.java index fb8d55c2..2e713ceb 100644 --- a/src/main/java/com/dispose/common/ConstValue.java +++ b/src/main/java/com/dispose/common/ConstValue.java @@ -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. */ diff --git a/src/main/java/com/dispose/common/GlobalVar.java b/src/main/java/com/dispose/common/GlobalVar.java index 83585a72..7d719f00 100644 --- a/src/main/java/com/dispose/common/GlobalVar.java +++ b/src/main/java/com/dispose/common/GlobalVar.java @@ -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; } diff --git a/src/main/java/com/dispose/config/EncodingFilterConfig.java b/src/main/java/com/dispose/config/EncodingFilterConfig.java index b99b6c3c..b386b77f 100644 --- a/src/main/java/com/dispose/config/EncodingFilterConfig.java +++ b/src/main/java/com/dispose/config/EncodingFilterConfig.java @@ -16,8 +16,8 @@ public class EncodingFilterConfig { * @return the filter registration bean */ @Bean - public FilterRegistrationBean filterRegistrationBean() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + public FilterRegistrationBean filterRegistrationBean() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setForceEncoding(true); characterEncodingFilter.setEncoding("UTF-8"); diff --git a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java b/src/main/java/com/dispose/controller/DisposeNodeInfoController.java index df6ae778..b2983c3c 100644 --- a/src/main/java/com/dispose/controller/DisposeNodeInfoController.java +++ b/src/main/java/com/dispose/controller/DisposeNodeInfoController.java @@ -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 devList = disposeNodeManager.getAllDisposeDevice(); if (devList != null && devList.size() > 0) { diff --git a/src/main/java/com/dispose/controller/DisposeTaskController.java b/src/main/java/com/dispose/controller/DisposeTaskController.java index e2311c0d..bf189fb1 100644 --- a/src/main/java/com/dispose/controller/DisposeTaskController.java +++ b/src/main/java/com/dispose/controller/DisposeTaskController.java @@ -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; diff --git a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java index 421ca070..b5376d37 100644 --- a/src/main/java/com/dispose/dispose/impl/DPTechImpl.java +++ b/src/main/java/com/dispose/dispose/impl/DPTechImpl.java @@ -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. diff --git a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java index 1264f818..23376831 100644 --- a/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java +++ b/src/main/java/com/dispose/mapper/DisposeDeviceMapper.java @@ -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, - IdsMapper, MySqlMapper { +public interface DisposeDeviceMapper extends Mapper, MySqlMapper { /** * Add new dispose device. * diff --git a/src/main/java/com/dispose/mapper/DisposeTaskMapper.java b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java new file mode 100644 index 00000000..87dcdb84 --- /dev/null +++ b/src/main/java/com/dispose/mapper/DisposeTaskMapper.java @@ -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, + IdsMapper, MySqlMapper { + + /** + * 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 getAllTaskByDisposeIp(String ipAddr); + + /** + * Gets all task by node dev id. + * + * @param devId the dev id + * @return the all task by node dev id + */ + List getAllTaskByNodeDevId(Long devId); + + /** + * Gets all task by node user id. + * + * @param userId the user id + * @return the all task by node user id + */ + List getAllTaskByNodeUserId(Long userId); +} diff --git a/src/main/java/com/dispose/mapper/UserAccountMapper.java b/src/main/java/com/dispose/mapper/UserAccountMapper.java index 267780f4..e4d23025 100644 --- a/src/main/java/com/dispose/mapper/UserAccountMapper.java +++ b/src/main/java/com/dispose/mapper/UserAccountMapper.java @@ -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, + IdsMapper, MySqlMapper { /** * Gets user by name. * diff --git a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java b/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java index e3abe062..38b57654 100644 --- a/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java +++ b/src/main/java/com/dispose/pojo/vo/common/DisposeCapacity.java @@ -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. */ diff --git a/src/main/java/com/dispose/pojo/vo/task/TaskInfoData.java b/src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java similarity index 90% rename from src/main/java/com/dispose/pojo/vo/task/TaskInfoData.java rename to src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java index 0b4c3ad3..fb40eef0 100644 --- a/src/main/java/com/dispose/pojo/vo/task/TaskInfoData.java +++ b/src/main/java/com/dispose/pojo/vo/common/TaskInfoData.java @@ -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; diff --git a/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java b/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java new file mode 100644 index 00000000..7e4c4316 --- /dev/null +++ b/src/main/java/com/dispose/pojo/vo/common/TaskInfoDetail.java @@ -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; +} diff --git a/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java b/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java index 7c5edf21..94251aca 100644 --- a/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java +++ b/src/main/java/com/dispose/pojo/vo/task/TaskInfoRsp.java @@ -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; diff --git a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java b/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java index 7afaa95f..6011ae0c 100644 --- a/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeNodeManagerImpl.java @@ -87,7 +87,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager { DisposeDevice dev = disposeDevMap.get(ipAddr); - if(dev == null) { + if (dev == null) { return ErrorCode.ERR_NOSUCHDEVICE; } diff --git a/src/main/resources/mappers/DisposeTask.xml b/src/main/resources/mappers/DisposeTask.xml new file mode 100644 index 00000000..a5f6671e --- /dev/null +++ b/src/main/resources/mappers/DisposeTask.xml @@ -0,0 +1,64 @@ + + + + + INSERT IGNORE INTO + dispose_task(deviceId, accountId, type, disposeIp, + planEndTime, flowDirection, attackType, flowBandWidth, + currentStatus) + VALUES + (#{deviceId}, #{accountId}, #{type}, #{disposeIp}, + #{planEndTime}, #{flowDirection}, #{attackType}, + #{flowBandWidth}, #{currentStatus} + ) + + + + DELETE + dispose_task + FROM + dispose_task + WHERE + dispose_task.id = #{id} + + + + UPDATE + dispose_task + SET + currentStatus = #{status, jdbcType=INTEGER} + WHERE + id = #{id, jdbcType=INTEGER} + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/dispose/Global/InitTestEnvironment.java b/src/test/java/com/dispose/Global/InitTestEnvironment.java index a4bb6680..e5f5d1b1 100644 --- a/src/test/java/com/dispose/Global/InitTestEnvironment.java +++ b/src/test/java/com/dispose/Global/InitTestEnvironment.java @@ -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"); - } } diff --git a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java index 14e71173..27955f41 100644 --- a/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java +++ b/src/test/java/com/dispose/TestSuit/AllDisposePlatformTest.java @@ -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, diff --git a/src/test/java/com/dispose/controller/AuthControllerTest.java b/src/test/java/com/dispose/controller/AuthControllerTest.java index 32e766df..ea66d929 100644 --- a/src/test/java/com/dispose/controller/AuthControllerTest.java +++ b/src/test/java/com/dispose/controller/AuthControllerTest.java @@ -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; diff --git a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java index a6b33a31..5f23d094 100644 --- a/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java +++ b/src/test/java/com/dispose/controller/DeviceNodeInfoControllerTest.java @@ -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) diff --git a/src/test/java/com/dispose/controller/TaskControllerTest.java b/src/test/java/com/dispose/controller/TaskControllerTest.java index ac4d120b..ff9d0ef6 100644 --- a/src/test/java/com/dispose/controller/TaskControllerTest.java +++ b/src/test/java/com/dispose/controller/TaskControllerTest.java @@ -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; diff --git a/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java index 5cc2a561..c277658f 100644 --- a/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java +++ b/src/test/java/com/dispose/dptech/DPTechInterfaceTestCase.java @@ -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. diff --git a/src/test/java/com/dispose/exception/ExceptionTest.java b/src/test/java/com/dispose/exception/ExceptionTest.java index d077673a..1847f217 100644 --- a/src/test/java/com/dispose/exception/ExceptionTest.java +++ b/src/test/java/com/dispose/exception/ExceptionTest.java @@ -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))) diff --git a/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java b/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java index 457c964d..f09a9a59 100644 --- a/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java +++ b/src/test/java/com/dispose/mapper/DisposeDeviceMapperTest.java @@ -77,9 +77,7 @@ public class DisposeDeviceMapperTest extends InitTestEnvironment { List 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 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)); } /** diff --git a/src/test/java/com/dispose/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/mapper/DisposeTaskMapperTest.java new file mode 100644 index 00000000..9cc4017d --- /dev/null +++ b/src/test/java/com/dispose/mapper/DisposeTaskMapperTest.java @@ -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())); + }); + } +}