REM:
1. 增加启动处置任务接口的入参判断
2. 增加广播形式启动处置任务的QA测试用例
This commit is contained in:
chenlinghy 2020-07-08 10:48:46 +08:00
parent 0e890ee008
commit 4130dae820
2 changed files with 133 additions and 112 deletions

View File

@ -117,7 +117,7 @@ public class DisposeTaskController {
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
} }
if (reqInfo.getDisposeTime() == null) { if (reqInfo.getDisposeTime() == null || reqInfo.getDisposeTime() < 0) {
log.error("Request dispose time params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeTime()); log.error("Request dispose time params error, error:{} --> {}", mr.getMsgContent(), reqInfo.getDisposeTime());
return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS); return ProtocolRespDTO.result(ErrorCode.ERR_PARAMS);
} }

View File

@ -54,7 +54,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test @Test
public void a1_NormalContainsNonEmptyTaskTest() throws Exception { public void a1_NormalContainsNonEmptyTaskTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.4\\\", " + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.4\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " + "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}"; "\\\"flowBandwidth\\\":1024}\"}";
@ -85,6 +85,9 @@ public class TaskControllerQATest extends InitTestEnvironment {
} else if (startTaskRsp.getStatus() == 26) { } else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode())); Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg()); Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
} else if (startTaskRsp.getStatus() == 19) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
} }
} }
@ -95,7 +98,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/ */
@Test @Test
public void a2_startTaskDisPoseIpEmptyExceptionTest() throws Exception { public void a2_startTaskDisPoseIpEmptyExceptionTest() throws Exception {
String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNoIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":\\\"\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -125,7 +128,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test @Test
public void a3_startTaskDisposeIpNullExceptionTest() throws Exception { public void a3_startTaskDisposeIpNullExceptionTest() throws Exception {
//disposeIp null //disposeIp null
String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNullIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":null, \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -154,7 +157,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/ */
@Test @Test
public void a4_startTaskDisposeIpIntegerExceptionTest() throws Exception { public void a4_startTaskDisposeIpIntegerExceptionTest() throws Exception {
String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataIntegerIp = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":192345, \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":192345, \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -212,7 +215,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/ */
@Test @Test
public void a6_startTaskTypeEmptyExceptionTest() throws Exception { public void a6_startTaskTypeEmptyExceptionTest() throws Exception {
String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNoType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -241,7 +244,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
*/ */
@Test @Test
public void a7_startTaskTypeNullExceptionTest() throws Exception { //null type public void a7_startTaskTypeNullExceptionTest() throws Exception { //null type
String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNullType = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -271,7 +274,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test @Test
public void a8_startTaskDisposeTimeEmptyExceptionTest() throws Exception { public void a8_startTaskDisposeTimeEmptyExceptionTest() throws Exception {
//no disposeTime //no disposeTime
String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNoDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -301,7 +304,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test @Test
public void a9_startTaskDisposeTimeNullExceptionTest() throws Exception { public void a9_startTaskDisposeTimeNullExceptionTest() throws Exception {
//null disposeTime //null disposeTime
String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataNullDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":null}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":null}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -331,7 +334,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
@Test @Test
public void a10_startTaskDisposeTimeStringExceptionTest() throws Exception { public void a10_startTaskDisposeTimeStringExceptionTest() throws Exception {
//string disposeTime //string disposeTime
String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataStringDisposeTime = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":\\\"120\\\"}\"}"; "\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":\\\"120\\\"}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
@ -354,40 +357,12 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
/** /**
* a11 id empty exception test. * a11 id zero test.
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Test @Test
public void a11_startTaskIdEmptyExceptionTest() throws Exception { public void a11_startTaskIdZeroTest() throws Exception {
String reqDataIdEmpty = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataIdEmpty))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(ret), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* a12 id zero test.
*
* @throws Exception the exception
*/
@Test
public void a12_startTaskIdZeroTest() throws Exception {
String reqDataIdZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"0\\\"," + String reqDataIdZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"0\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
@ -407,67 +382,17 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp); Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus()); Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage()); Assert.assertNotNull(startTaskRsp.getMessage());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
if (startTaskRsp.getStatus() == 0) { Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
} else if (startTaskRsp.getStatus() == 19) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_NOSUCHDEVICE.getMsg());
}
} }
/** /**
* a13 id normal exception test. * a12 type error exception test.
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Test @Test
public void a13_startTaskIdNormalTest() throws Exception { public void a12_startTaskTypeErrorExceptionTest() throws Exception {
String reqDataIdNormal = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":\\\"1\\\"," +
"\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataIdNormal))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a14 type error exception test.
*
* @throws Exception the exception
*/
@Test
public void a14_startTaskTypeErrorExceptionTest() throws Exception {
String reqDataTypeError = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataTypeError = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":5, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}"; "\\\"type\\\":5, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":120}\"}";
@ -489,16 +414,17 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* a15 disposeTime negative exception test. * a13 disposeTime negative exception test.
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Test @Test
public void a15_startTaskDisposeTimeNegativeExceptionTest() throws Exception { public void a13_startTaskDisposeTimeNegativeExceptionTest() throws Exception {
//string disposeTime //string disposeTime
String reqDataDisposeTimeNegative = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + String reqDataDisposeTimeNegative = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":-10}\"}"; "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":-10}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
@ -518,22 +444,106 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* a16 disposeTime zero exception test. * a14 start dispose task Broadcast
* *
* @throws Exception the exception * @throws Exception the exception
*/ */
@Test @Test
public void a16_startTaskDisposeTimeZeroExceptionTest() throws Exception { public void a14_BroadcastNormalContainsNonEmptyTaskTest() throws Exception {
//string disposeTime String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
String reqDataDisposeTimeZero = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," + "\\\"type\\\":0, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"type\\\":null, \\\"disposeIp\\\":\\\"192.168.4.2\\\", \\\"disposeTime\\\":0}\"}"; "\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start") .post("/task/start")
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken()) .header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqDataDisposeTimeZero)) .content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a15 start dispose task Broadcast type negative. -1代表所有任务类型 清洗高防黑洞检测
*
* @throws Exception the exception
*/
@Test
public void a15_broadCastStartTaskTypeNegativeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":-1, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
StartTaskRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), StartTaskRsp.class);
Assert.assertNotNull(startTaskRsp);
Assert.assertNotNull(startTaskRsp.getStatus());
Assert.assertNotNull(startTaskRsp.getMessage());
if (startTaskRsp.getStatus() == 0) {
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (startTaskRsp.getStatus() == 26) {
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_TASKRUNNING.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_TASKRUNNING.getMsg());
}
}
/**
* a16 start dispose task Broadcast type negative. < -1
*
* @throws Exception the exception
*/
@Test
public void a16_broadCastStartTaskTypeNegativeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\":-1," +
"\\\"type\\\":-2, \\\"disposeIp\\\":\\\"192.168.5.2\\\", " +
"\\\"disposeTime\\\":120, \\\"flowDirection\\\":2, \\\"attackType\\\":[0], " +
"\\\"flowBandwidth\\\":1024}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/start")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk()) .andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode())) .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMS.getHttpCode()))
.andReturn() .andReturn()
@ -547,6 +557,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* b1 taskId empty exception test. 停止指定任务的时候必须指定id id不能为空字符串 * b1 taskId empty exception test. 停止指定任务的时候必须指定id id不能为空字符串
* *
@ -741,6 +752,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
} }
} }
/** /**
* b7 taskId int exception test. * b7 taskId int exception test.
* *
@ -769,6 +781,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
} }
/** /**
* c1 id null exception test. * c1 id null exception test.
* *
@ -1000,6 +1013,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* c9 type negative exception test. * c9 type negative exception test.
*/ */
@ -1024,6 +1038,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* c10 normal stop tasks by dispose ip test. * c10 normal stop tasks by dispose ip test.
*/ */
@ -1061,6 +1076,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
} }
} }
/** /**
* d1 stop task by single node test. * d1 stop task by single node test.
*/ */
@ -1254,6 +1270,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* d7 type string exception test. * d7 type string exception test.
* *
@ -1492,6 +1509,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
} }
} }
/** /**
* e7 type error exception test. * e7 type error exception test.
* *
@ -1518,6 +1536,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode())); Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg()); Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
} }
/** /**
* f1 get node task of node test. * f1 get node task of node test.
*/ */
@ -1540,7 +1559,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class);
Assert.assertNotNull(nodeTaskRsp); Assert.assertNotNull(nodeTaskRsp);
nodeTaskRsp.getItems().forEach(v->{ nodeTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getStatus()); Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage()); Assert.assertNotNull(v.getMessage());
@ -1570,7 +1589,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
/** /**
*f2 get node task id empty exception test.空表示所有能力节点 * f2 get node task id empty exception test.空表示所有能力节点
*/ */
@Test @Test
public void f2_NormalGetNodeTaskInfoIdTest() throws Exception { public void f2_NormalGetNodeTaskInfoIdTest() throws Exception {
@ -1591,7 +1610,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class); NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class);
Assert.assertNotNull(nodeTaskRsp); Assert.assertNotNull(nodeTaskRsp);
nodeTaskRsp.getItems().forEach(v->{ nodeTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getStatus()); Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage()); Assert.assertNotNull(v.getMessage());
@ -1799,6 +1818,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
} }
}); });
} }
/** /**
* f8 get node task Array contains character test . * f8 get node task Array contains character test .
*/ */
@ -1851,7 +1871,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp); Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{ startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getId()); Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getTaskId()); Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStartTime()); Assert.assertNotNull(v.getStartTime());
@ -1939,7 +1959,7 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp); Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{ startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getId()); Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getTaskId()); Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStartTime()); Assert.assertNotNull(v.getStartTime());
@ -1973,24 +1993,25 @@ public class TaskControllerQATest extends InitTestEnvironment {
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class); TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
Assert.assertNotNull(startTaskRsp); Assert.assertNotNull(startTaskRsp);
startTaskRsp.getItems().forEach(v->{ startTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v); Assert.assertNotNull(v);
Assert.assertNotNull(v.getTaskId()); Assert.assertNotNull(v.getTaskId());
Assert.assertNotNull(v.getStatus()); Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage()); Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 0){ if (v.getStatus() == 0) {
Assert.assertNotNull(v.getId()); Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getStartTime()); Assert.assertNotNull(v.getStartTime());
Assert.assertNotNull(v.getDisposeTime()); Assert.assertNotNull(v.getDisposeTime());
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg()); Assert.assertEquals(v.getMessage(), ErrorCode.ERR_OK.getMsg());
}else if(v.getStatus() == 30){ } else if (v.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode())); Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg()); Assert.assertEquals(v.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
} }
}); });
} }
/** /**
* g6 get node detailed taskId int exception test . * g6 get node detailed taskId int exception test .
*/ */