REM:
1. 处置接口相关单测b6b7c9c10d7e7f8g6
This commit is contained in:
wangyiyun 2020-06-16 17:37:44 +08:00
parent c213f1f8a6
commit a6518526a3
1 changed files with 233 additions and 0 deletions

View File

@ -703,7 +703,72 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
}
/**
* b6 stop task Array sort test. 排序
*
* @throws Exception the exception
*/
@Test
public void b6_stopTaskArraySortTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040," +
"\"msgContent\":\"{\\\"taskId\\\":[\\\"1411\\\", \\\"60\\\", \\\"2\\\", \\\"1142\\\"]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.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();
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(ret), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (task.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
}
}
}
/**
* b7 taskId int exception test.
*
* @throws Exception the exception
*/
@Test
public void b7_stopTaskTaskIdIntExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":1142}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop")
.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_PARAMEXCEPTION.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_PARAMEXCEPTION.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
}
/**
* c1 id null exception test.
*
@ -935,7 +1000,67 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* c9 type negative exception test.
*/
@Test
public void c9_stopTaskByIpTypeNegativeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":-5,\\\"disposeIp\\\":\\\"192.168.5.8\\\"}]}\"}";
String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_ip")
.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_PARAMS.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(taskStopByIp), 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());
}
/**
* c10 normal stop tasks by dispose ip test.
*/
@Test
public void c10_NormalStopTasksByDisposeIpTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":-1,\\\"disposeIp\\\":\\\"192.168.3.3\\\"}, {\\\"id\\\":\\\"2\\\",\\\"type\\\":2,\\\"disposeIp\\\":\\\"192.168.3.4\\\"}]}\"}";
String taskStopByIp = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_ip")
.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();
TaskInfoRsp startTaskRsp = objectMapper.readValue(verifyResp(taskStopByIp), TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = startTaskRsp.getItems();
for (TaskInfoData task : taskInfoList
) {
Assert.assertNotNull(task.getStatus());
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == 0) {
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (task.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
}
}
}
/**
* d1 stop task by single node test.
*/
@ -1129,6 +1254,34 @@ public class TaskControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMS.getMsg());
}
/**
* d7 type string exception test.
*
* @throws Exception the exception
*/
@Test
public void d7_stopTaskByNodeTypeStringExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\": \"{\\\"items\\\":" +
"[{\\\"id\\\":\\\"1\\\",\\\"type\\\":\\\"abc\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_node")
.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_PARAMEXCEPTION.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_PARAMEXCEPTION.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
}
/**
* e1 stop task all test.
@ -1339,7 +1492,32 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
}
}
/**
* e7 type error exception test.
*
* @throws Exception the exception
*/
@Test
public void e7_stopTaskAllTypeErrorExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"type\\\":6}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_all")
.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_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());
}
/**
* f1 get node task of node test.
*/
@ -1621,6 +1799,35 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
});
}
/**
* f8 get node task Array contains character test .
*/
@Test
public void f8_GetNodeTaskInfoArrayContainsCharacterTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"id\\\": " +
"[\\\"1\\\",\\\"ab\\\",\\\"123\\\"], \\\"type\\\":0}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/get_node")
.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_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
NodeTaskRsp nodeTaskRsp = objectMapper.readValue(verifyResp(ret), NodeTaskRsp.class);
Assert.assertNotNull(nodeTaskRsp);
nodeTaskRsp.getItems().forEach(v -> {
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
Assert.assertEquals(Long.valueOf(v.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
Assert.assertEquals(v.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
});
}
/**
* g1 get node detailed taskId empty exception test. 空字符串表示所有节点任务
@ -1784,4 +1991,30 @@ public class TaskControllerQATest extends InitTestEnvironment {
}
});
}
/**
* g6 get node detailed taskId int exception test .
*/
@Test
public void g6_GetNodeDetailedInfoTaskIdIntExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"taskId\\\":60}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/task/get")
.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_PARAMEXCEPTION.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_PARAMEXCEPTION.getCode()));
Assert.assertEquals(returnStatus.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
}
}