From 1a5c1eb76f3efda44fd71e8507bcb0ef9f979d1a Mon Sep 17 00:00:00 2001 From: chenlinghy Date: Mon, 31 Aug 2020 16:19:25 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=B7=BB=E5=8A=A0=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=A4=84=E7=BD=AE=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=202.=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=AA=E6=99=AE=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD?= =?UTF-8?q?IP=E6=98=AF=E5=90=A6=E5=9C=A8=E8=AE=BE=E5=A4=87=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E5=86=85=E3=80=81=E8=8E=B7=E5=8F=96=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E7=AD=89=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=203.=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B5=A9=E7=80=9A=E8=AE=BE=E5=A4=87=E5=88=A4=E6=96=AD?= =?UTF-8?q?IP=E6=98=AF=E5=90=A6=E5=9C=A8=E8=AE=BE=E5=A4=87=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E5=86=85=E3=80=81=E8=8E=B7=E5=8F=96=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E9=98=B2=E6=8A=A4=E5=AF=B9=E8=B1=A1=E7=AD=89=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95=204.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0service=E5=B1=82=E5=88=9B=E5=BB=BA=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/controller/AuthControllerTest.java | 2 - .../controller/DisposeTaskControllerTest.java | 189 ++++++++++++++++++ .../test/dptech/DPTechInterfaceTestCase.java | 23 ++- .../test/haohan/HAOHanInterfaceTestCast.java | 118 ++++++----- .../test/service/DisposeTaskServiceTest.java | 127 ++++++++++++ 5 files changed, 406 insertions(+), 53 deletions(-) create mode 100644 src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java create mode 100644 src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java diff --git a/src/test/java/com/dispose/test/controller/AuthControllerTest.java b/src/test/java/com/dispose/test/controller/AuthControllerTest.java index e89955d4..d48e381b 100644 --- a/src/test/java/com/dispose/test/controller/AuthControllerTest.java +++ b/src/test/java/com/dispose/test/controller/AuthControllerTest.java @@ -83,8 +83,6 @@ public class AuthControllerTest extends InitTestEnvironment { .getResponse() .getContentAsString(); - - ProtocolRespDTO rspInfo = objectMapper.readValue(ret, new TypeReference>(){}); diff --git a/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java new file mode 100644 index 00000000..c5a79c1f --- /dev/null +++ b/src/test/java/com/dispose/test/controller/DisposeTaskControllerTest.java @@ -0,0 +1,189 @@ +package com.dispose.test.controller; + +import com.dispose.common.*; +import com.dispose.mapper.DisposeDeviceMapper; +import com.dispose.mapper.DisposeTaskMapper; +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.TaskStartResp; +import com.dispose.pojo.entity.DisposeTask; +import com.dispose.test.Global.InitTestEnvironment; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import jodd.net.HttpStatus; +import lombok.extern.slf4j.Slf4j; +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.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.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * The type Auth controller test. + * + * @author + */ +@AutoConfigureMockMvc +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Slf4j +@Transactional +@Rollback +public class DisposeTaskControllerTest extends InitTestEnvironment { + /** + * The Mock mvc. + */ + @Resource + private MockMvc mockMvc; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + /** + * The Dispose task manager. + */ + @Resource + private DisposeTaskMapper disposeTaskManager; + /** + * The Dispose device mapper. + */ + @Resource + private DisposeDeviceMapper disposeDeviceMapper; + + /** + * A 1 add dispose device. + * + * @throws Exception the exception + */ + @Test + public void a1_startTask() throws Exception { + TaskStartReq req = TaskStartReq.builder() + .id(String.valueOf(disposeDeviceMapper.selectAll().get(0).getId())) + .type(DisposeCapacityType.CLEANUP.getValue()) + .disposeIp("192.168.5.3") + .disposeTime(60) + .flowDirection(NetflowDirection.DIRECTION_IN.getValue()) + .attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()}) + .flowBandwidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .build(); + + ProtocolReqDTO 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/start") + .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 rspInfo = objectMapper.readValue(ret, + new TypeReference>() { + }); + + verifyRespProtocol(rspInfo); + + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); + + Assert.assertNotNull(rspInfo.getMsgContent().getStatus()); + Assert.assertNotNull(rspInfo.getMsgContent().getMessage()); + + if (rspInfo.getMsgContent().getStatus() == ErrorCode.ERR_OK.getCode()) { + Assert.assertNotNull(rspInfo.getMsgContent().getTaskId()); + + disposeTaskManager.selectAll().forEach(v -> { + if (v.getDeviceId().equals(Long.valueOf(req.getId())) && + v.getDisposeIp().equals(req.getDisposeIp()) && + v.getAttackType().equals((long) DDoSAttackType.ACK_FLOOD.getValue())) { + Assert.assertEquals(Long.valueOf(rspInfo.getMsgContent().getTaskId()), v.getId()); + } + }); + } + } + + /** + * A 2 add dispose device existed. + * + * @throws Exception the exception + */ + @Test + public void a2_startTaskExisted() throws Exception { + DisposeTask disposeTask = disposeTaskManager.selectAll().get(0); + + TaskStartReq req = TaskStartReq.builder() + .id(String.valueOf(disposeTask.getId())) + .type(disposeTask.getDisposeCapacity().getValue()) + .disposeIp(disposeTask.getDisposeIp()) + .disposeTime(60) + .flowDirection(NetflowDirection.DIRECTION_IN.getValue()) + .attackType(new Integer[]{DDoSAttackType.ACK_FLOOD.getValue()}) + .flowBandwidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .build(); + + ProtocolReqDTO 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/start") + .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 rspInfo = objectMapper.readValue(ret, + new TypeReference>() { + }); + + verifyRespProtocol(rspInfo); + log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo)); + + Assert.assertNotNull(rspInfo.getMsgContent().getStatus()); + Assert.assertNotNull(rspInfo.getMsgContent().getMessage()); + + if (disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_FINISHED || + disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_CANCELED || + disposeTask.getCurrentStatus() == DisposeTaskStatus.TASK_EXPIRED) { + Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode())); + } else { + Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getStatus()), String.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); + } + } + +} diff --git a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java b/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java index c8e7d6c8..7440d99f 100644 --- a/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java +++ b/src/test/java/com/dispose/test/dptech/DPTechInterfaceTestCase.java @@ -85,7 +85,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment { db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); MulReturnType ret = db.runDispose("192.168.3.5", DisposeCapacityType.CLEANUP, - NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); + NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); } @@ -127,7 +127,7 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment { Assert.assertTrue(db.getDeviceLinkStatus()); MulReturnType ret = db.stopDispose("192.168.3.5", DisposeCapacityType.CLEANUP, - NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); + NetflowDirection.DIRECTION_BI, DDoSAttackType.ALL_ATTACKS.getValue(), -1L); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); } @@ -177,6 +177,25 @@ public class DPTechInterfaceTestCase extends InitTestEnvironment { Assert.assertEquals(ret.getSecondParam().getKernel(), "Windows"); Assert.assertEquals(ret.getSecondParam().getArch(), "x86_64"); Assert.assertEquals(ret.getSecondParam().getVersion(), "5.7.31"); + + //to device attack type long. + Long ddosAttackTypeMask = 10737508814L; + + Long result = db.toDeviceAttackType(ddosAttackTypeMask); + + log.info("ddosAttackTypeMask-->{}, result-->{}", ddosAttackTypeMask, result); + Assert.assertNotNull(result); + Assert.assertNotEquals(String.valueOf(result), "0"); + + //gets dispose device protect object. + db.getDisposeDeviceProtectObject(); + + //is carry protect ip boolean. + boolean carryResult = db.isCarryProtectIp("192.168.3.2"); + Assert.assertTrue(carryResult); + + carryResult = db.isCarryProtectIp("192.168.10.2"); + Assert.assertFalse(carryResult); } } } diff --git a/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java b/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java index 74e38517..d97c9d7e 100644 --- a/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java +++ b/src/test/java/com/dispose/test/haohan/HAOHanInterfaceTestCast.java @@ -56,21 +56,21 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { DisposeAbility db; DisposeDevice dev = DisposeDevice.builder() - .ipAddr("10.88.77.88") - .ipPort("18080") - .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) - .areaCode(0) - .deviceName("中移杭研实验室浩瀚清洗设备") - .manufacturer("Haohan") - .model("Unknown") - .version("Unknown") - .userName("") - .password("") - .urlPath("DDoSClean/clean") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); + .ipAddr("10.88.77.88") + .ipPort("18080") + .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) + .areaCode(0) + .deviceName("中移杭研实验室浩瀚清洗设备") + .manufacturer("Haohan") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("DDoSClean/clean") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); @@ -83,8 +83,8 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { db.initDeviceEnv(url, dev.getUserName(), dev.getPassword()); MulReturnType ret = db.runDispose("192.168.3.5", - DisposeCapacityType.CLEANUP, - null, null, -1L); + DisposeCapacityType.CLEANUP, + null, null, -1L); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); } @@ -98,21 +98,21 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { DisposeAbility db; DisposeDevice dev = DisposeDevice.builder() - .ipAddr("10.88.77.88") - .ipPort("18080") - .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) - .areaCode(0) - .deviceName("中移杭研实验室浩瀚清洗设备") - .manufacturer("Haohan") - .model("Unknown") - .version("Unknown") - .userName("") - .password("") - .urlPath("DDoSClean/clean") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); + .ipAddr("10.88.77.88") + .ipPort("18080") + .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) + .areaCode(0) + .deviceName("中移杭研实验室浩瀚清洗设备") + .manufacturer("Haohan") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("DDoSClean/clean") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); @@ -126,8 +126,8 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { Assert.assertTrue(db.getDeviceLinkStatus()); MulReturnType ret = db.stopDispose("192.168.3.5", - DisposeCapacityType.CLEANUP, - null, null, -1L); + DisposeCapacityType.CLEANUP, + null, null, -1L); Assert.assertEquals(ret.getFirstParam(), ErrorCode.ERR_OK); } @@ -141,21 +141,21 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { DisposeAbility db; DisposeDevice dev = DisposeDevice.builder() - .ipAddr("10.88.77.88") - .ipPort("18080") - .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) - .areaCode(0) - .deviceName("中移杭研实验室浩瀚清洗设备") - .manufacturer("Haohan") - .model("Unknown") - .version("Unknown") - .userName("") - .password("") - .urlPath("DDoSClean/clean") - .urlType(HttpType.HTTP) - .readme("实验室测试设备") - .status(ObjectStatus.NORMAL) - .build(); + .ipAddr("10.88.77.88") + .ipPort("18080") + .deviceType(DisposeDeviceType.HAOHAN_PLATFORM) + .areaCode(0) + .deviceName("中移杭研实验室浩瀚清洗设备") + .manufacturer("Haohan") + .model("Unknown") + .version("Unknown") + .userName("") + .password("") + .urlPath("DDoSClean/clean") + .urlType(HttpType.HTTP) + .readme("实验室测试设备") + .status(ObjectStatus.NORMAL) + .build(); String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); @@ -176,6 +176,26 @@ public class HAOHanInterfaceTestCast extends InitTestEnvironment { Assert.assertEquals(ret.getSecondParam().getKernel(), "Linux"); Assert.assertEquals(ret.getSecondParam().getArch(), "x86_64"); Assert.assertEquals(ret.getSecondParam().getVersion(), "Unknown"); + + //to device attack type long. + Long ddosAttackTypeMask = 10737508814L; + + Long result = db.toDeviceAttackType(ddosAttackTypeMask); + + log.info("ddosAttackTypeMask-->{}, result-->{}", ddosAttackTypeMask, result); + Assert.assertNotNull(result); + Assert.assertEquals(String.valueOf(ddosAttackTypeMask), String.valueOf(result)); + + + //gets dispose device protect object. + db.getDisposeDeviceProtectObject(); + + //is carry protect ip boolean. 所有IP都可执行清洗命令 + boolean carryResult = db.isCarryProtectIp("192.168.5.2"); + Assert.assertTrue(carryResult); + + carryResult = db.isCarryProtectIp(""); + Assert.assertTrue(carryResult); } } } diff --git a/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java b/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java new file mode 100644 index 00000000..ca99adf9 --- /dev/null +++ b/src/test/java/com/dispose/test/service/DisposeTaskServiceTest.java @@ -0,0 +1,127 @@ +package com.dispose.test.service; + +import com.dispose.common.*; +import com.dispose.manager.DisposeTaskManager; +import com.dispose.mapper.DisposeDeviceMapper; +import com.dispose.mapper.UserAccountMapper; +import com.dispose.pojo.entity.DisposeTask; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.DisposeTaskService; +import com.dispose.service.UserAccountService; +import com.dispose.test.Global.InitTestEnvironment; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Before; +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.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.security.NoSuchAlgorithmException; + +/** + * The type User account service test. + * + * @author + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Transactional +@Rollback +public class DisposeTaskServiceTest extends InitTestEnvironment { + /** + * The constant token. + */ + private static String token = ""; + /** + * The User account service. + */ + @Resource + private UserAccountService userAccountService; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + /** + * The user account mapper. + */ + @Resource + private UserAccountMapper userAccountMapper; + /** + * The Dispose device mapper. + */ + @Resource + private DisposeDeviceMapper disposeDeviceMapper; + /** + * The Dispose task manager. + */ + @Resource + private DisposeTaskManager disposeTaskManager; + /** + * The Dispose task service. + */ + @Resource + private DisposeTaskService disposeTaskService; + + /** + * User login test. + * + * @throws NoSuchAlgorithmException the no such algorithm exception + */ + @Before + public void userLoginTest() throws NoSuchAlgorithmException { + MulReturnType ret = userAccountService.loginService(getUSER_NAME(), + getPASSWORD()); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + DisposeTaskServiceTest.token = ret.getSecondParam(); + } + } + + /** + * creat task mul return type. + */ + @Test + public void a1_createTask() throws JsonProcessingException { + // 构成处置任务参数 + DisposeTask newTask = DisposeTask.builder() + .deviceId(disposeDeviceMapper.selectAll().get(0).getId()) + .accountId(userAccountMapper.selectAll().get(0).getId()) + .disposeCapacity(DisposeCapacityType.CLEANUP) + .disposeIp("192.168.5.2") + .planEndTime("30") + .flowDirection(NetflowDirection.DIRECTION_IN) + .attackType(DDoSAttackType.getTypeMaskFromAttackType(new Integer[]{DDoSAttackType.ALL_ATTACKS.getValue()})) + .flowBandWidth(DisposeConfigValue.DEFAULT_DISPOSE_BANDWIDTH) + .build(); + + log.info("creat new task: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask)); + + MulReturnType ret = disposeTaskService.createTask(newTask); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + Assert.assertNotNull(ret.getSecondParam()); + } else { + Assert.assertNotEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_OK.getCode()); + } + Assert.assertEquals(ret.getSecondParam(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(), + newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); + + ret = disposeTaskService.createTask(newTask); + + Assert.assertEquals(ret.getFirstParam().getCode(), ErrorCode.ERR_TASKRUNNING.getCode()); + Assert.assertEquals(ret.getSecondParam(), disposeTaskManager.getDisposeTask(newTask.getDeviceId(), + newTask.getDisposeIp(), newTask.getDisposeCapacity()).getId()); + } +} +