REM:
1. 修改测试用例断言
This commit is contained in:
chenlinghy 2020-06-10 15:06:29 +08:00
parent 6309a7135e
commit 689f1ad7a0
2 changed files with 93 additions and 21 deletions

View File

@ -80,8 +80,10 @@ public class TaskControllerSmokeTest extends InitTestEnvironment {
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());
}
}
@ -113,8 +115,10 @@ public class TaskControllerSmokeTest extends InitTestEnvironment {
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());
}
}
}
@ -147,8 +151,10 @@ public class TaskControllerSmokeTest extends InitTestEnvironment {
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());
}
}
}
@ -183,8 +189,10 @@ public class TaskControllerSmokeTest extends InitTestEnvironment {
Assert.assertNotNull(task.getStartTime());
Assert.assertNotNull(task.getDisposeTime());
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());
}
}
}

View File

@ -162,10 +162,11 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(startTaskRsp.getId());
Assert.assertNotNull(startTaskRsp.getTaskId());
Assert.assertNotNull(String.valueOf(startTaskRsp.getExpireTime()));
Assert.assertNotEquals(String.valueOf(startTaskRsp.getExpireTime()), -1);
Assert.assertEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals(Long.valueOf(startTaskRsp.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(startTaskRsp.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
@ -216,8 +217,10 @@ public class TaskControllerTest extends InitTestEnvironment {
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 {
Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -267,8 +270,10 @@ public class TaskControllerTest extends InitTestEnvironment {
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 {
Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -329,8 +334,10 @@ public class TaskControllerTest extends InitTestEnvironment {
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 {
Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -387,8 +394,10 @@ public class TaskControllerTest extends InitTestEnvironment {
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 {
Assert.assertNotEquals(Long.valueOf(task.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -445,12 +454,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -513,12 +523,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -575,12 +586,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -633,12 +645,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -687,12 +700,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -739,12 +753,13 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getMessage());
if (task.getStatus() == ErrorCode.ERR_OK.getCode()) {
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
Assert.assertNotNull(task.getId());
Assert.assertNotNull(task.getTaskId());
Assert.assertEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals((int) task.getStatus(), ErrorCode.ERR_OK.getCode());
Assert.assertNotEquals(task.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -780,7 +795,6 @@ public class TaskControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z";
String msgContent = verifyRep(getTask, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
@ -804,13 +818,14 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getStartTime());
Assert.assertNotNull(task.getStartTime());
Assert.assertNotNull(task.getDisposeIp());
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
}
Assert.assertEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -844,7 +859,6 @@ public class TaskControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
String regex = "\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z";
String msgContent = verifyRep(getTask, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
@ -868,13 +882,14 @@ public class TaskControllerTest extends InitTestEnvironment {
Assert.assertNotNull(task.getStartTime());
Assert.assertNotNull(task.getStartTime());
Assert.assertNotNull(task.getDisposeIp());
Assert.assertTrue(task.getDisposeIp().matches(regex));
}
}
Assert.assertEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg());
} else {
Assert.assertNotEquals(Long.valueOf(taskNode.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertNotEquals(taskNode.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
}
@ -890,13 +905,14 @@ public class TaskControllerTest extends InitTestEnvironment {
.taskId(new String[]{String.valueOf(getExistsTaskId()), "123"})
.build();
Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
String getTask = mockMvc.perform(MockMvcRequestBuilders
.post("/task/get")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
@ -906,6 +922,32 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
String msgContent = verifyRep(getTask, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskInfoRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskInfoRsp.getItems();
for (TaskInfoData taskInfoData : taskInfoList
) {
Assert.assertNotNull(taskInfoData);
Assert.assertNotNull(taskInfoData.getStatus());
Assert.assertNotNull(taskInfoData.getMessage());
if (taskInfoData.getStatus() == 0) {
Assert.assertNotNull(taskInfoData.getId());
Assert.assertNotNull(taskInfoData.getTaskId());
Assert.assertNotNull(taskInfoData.getStartTime());
Assert.assertNotNull(taskInfoData.getDisposeTime());
Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_OK.getMsg());
} else if (taskInfoData.getStatus() == 30) {
Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_NOSUCHTASK.getCode()));
Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_NOSUCHTASK.getMsg());
}
}
}
/**
@ -919,13 +961,14 @@ public class TaskControllerTest extends InitTestEnvironment {
.taskId(new String[]{})
.build();
Long reqTimeStamp = System.currentTimeMillis();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setTimeStamp(reqTimeStamp);
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
String getTask = mockMvc.perform(MockMvcRequestBuilders
.post("/task/get")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
@ -935,8 +978,29 @@ public class TaskControllerTest extends InitTestEnvironment {
.andReturn()
.getResponse()
.getContentAsString();
String msgContent = verifyRep(getTask, reqTimeStamp);
System.out.print("msgContent=" + msgContent);
//将json字符串转为TaskInfoRsp类
TaskInfoRsp taskInfoRsp = objectMapper.readValue(msgContent, TaskInfoRsp.class);
List<TaskInfoData> taskInfoList = taskInfoRsp.getItems();
for (TaskInfoData taskInfoData : taskInfoList
) {
Assert.assertNotNull(taskInfoData);
Assert.assertNotNull(taskInfoData.getId());
Assert.assertNotNull(taskInfoData.getTaskId());
Assert.assertNotNull(taskInfoData.getStartTime());
Assert.assertNotNull(taskInfoData.getDisposeTime());
Assert.assertNotNull(taskInfoData.getStatus());
Assert.assertNotNull(taskInfoData.getMessage());
Assert.assertEquals(Long.valueOf(taskInfoData.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode()));
Assert.assertEquals(taskInfoData.getMessage(), ErrorCode.ERR_OK.getMsg());
}
}
/**
* T 8 add task error test.
*/