REM:
1. 修改数据库Mysql语句
2. 编写数据库DisposeTask单元测试
This commit is contained in:
chenlinghy 2020-08-24 11:37:28 +08:00
parent 4762558d1b
commit c1a352b272
2 changed files with 83 additions and 15 deletions

View File

@ -67,7 +67,7 @@
ti.status status ti.status status
FROM dispose_task dt FROM dispose_task dt
LEFT JOIN device_task ti on dt.id = ti.taskId LEFT JOIN device_task ti on dt.id = ti.taskId
AND dt.id = #{taskId} WHERE dt.id = #{taskId}
</select> </select>
<select id="getRunningTask" resultMap="dispose_task"> <select id="getRunningTask" resultMap="dispose_task">

View File

@ -84,33 +84,44 @@ public class DisposeTaskMapperTest {
Assert.assertEquals(ret, 1); Assert.assertEquals(ret, 1);
log.debug("add ret {}: {}", ret, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task)); log.info("add ret {}: {}", ret, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
List<DisposeTask> taskList = disposeTaskMapper.selectAll(); List<DisposeTask> taskList = disposeTaskMapper.selectAll();
Assert.assertNotNull(taskList); Assert.assertNotNull(taskList);
Assert.assertNotEquals(taskList.size(), 0); Assert.assertNotEquals(taskList.size(), 0);
log.debug("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList)); log.info("Database: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskList));
} }
/** /**
* D 1 get task status. * A 2 gets dispose task by id.
*
* @throws JsonProcessingException the json processing exception
*/ */
@Test @Test
public void d1_getTaskStatus() { public void a2_getDisposeTaskById() throws JsonProcessingException {
List<DisposeTask> taskList = disposeTaskMapper.selectAll(); List<DisposeTask> disposeTaskList = disposeTaskMapper.selectAll();
if (taskList != null && taskList.size() > 0) { disposeTaskList.forEach(v->{
taskList.forEach(v -> { log.info("taskId-->{}",v.getId());
DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId()); DisposeTask task = disposeTaskMapper.getDisposeTaskById(v.getId());
Assert.assertEquals(v.getCurrentStatus(), status); Assert.assertNotNull(task);
try {
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}); });
} }
}
/**
* A 3 gets running task.
*
* @throws JsonProcessingException the json processing exception
*/
@Test @Test
public void d2_getDisposeTask() throws JsonProcessingException { public void a3_getRunningTask() throws JsonProcessingException {
List<DisposeTask> taskList = disposeTaskMapper.getRunningTask(-1L, List<DisposeTask> taskList = disposeTaskMapper.getRunningTask(-1L,
DisposeCapacityType.CLEANUP, DisposeCapacityType.CLEANUP,
"192.168.0.1"); "192.168.0.1");
@ -137,19 +148,76 @@ public class DisposeTaskMapperTest {
} }
/** /**
* C 1 chang task status. * A 4 get task status.
*/ */
@Test @Test
public void c1_changTaskStatus() { public void a4_getTaskStatus() {
List<DisposeTask> taskList = disposeTaskMapper.selectAll();
if (taskList != null && taskList.size() > 0) {
taskList.forEach(v -> {
DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId());
Assert.assertEquals(v.getCurrentStatus(), status);
});
}
}
/**
* A 5 chang task status.
*/
@Test
public void a5_changTaskStatus() {
List<DisposeTask> taskList = disposeTaskMapper.selectAll(); List<DisposeTask> taskList = disposeTaskMapper.selectAll();
if (taskList != null && taskList.size() > 0) { if (taskList != null && taskList.size() > 0) {
taskList.forEach(v -> { taskList.forEach(v -> {
int ret = disposeTaskMapper.changTaskStatus(v.getId(), DisposeTaskStatus.TASK_FINISHED); int ret = disposeTaskMapper.changTaskStatus(v.getId(), DisposeTaskStatus.TASK_FINISHED);
Assert.assertEquals(ret, 1);
DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId()); DisposeTaskStatus status = disposeTaskMapper.getTaskStatus(v.getId());
Assert.assertEquals(DisposeTaskStatus.TASK_FINISHED, status); Assert.assertEquals(DisposeTaskStatus.TASK_FINISHED, status);
}); });
} }
} }
/**
* A 6 gets new task.
*/
@Test
public void a6_getNewTask() throws JsonProcessingException {
List<DisposeTask> taskList = disposeTaskMapper.selectAll();
long newNumber = taskList.stream().filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW).count();
log.info("newNumber-->{}", newNumber);
if(newNumber > 0){
List<DisposeTask> newTasks= disposeTaskMapper.getNewTask();
Assert.assertNotNull(newTasks);
Assert.assertNotEquals(newTasks.size(), 0);
log.info("new Tasks: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTasks));
}
}
/**
* A 7 gets expired task.
*/
@Test
public void a7_getExpiredTasks() throws JsonProcessingException {
List<DisposeTask> taskList = disposeTaskMapper.selectAll();
long expiredNumber = taskList.stream().filter(v -> (v.getCurrentStatus() == DisposeTaskStatus.TASK_FINISHED)
&&(v.getCurrentStatus() == DisposeTaskStatus.TASK_CANCELED)
&&(v.getCurrentStatus() == DisposeTaskStatus.TASK_EXPIRED)).count();
log.info("expiredNumber-->{}", expiredNumber);
if(expiredNumber > 0){
List<DisposeTask> expiredTasks= disposeTaskMapper.getNewTask();
Assert.assertNotNull(expiredTasks);
Assert.assertNotEquals(expiredTasks.size(), 0);
log.info("new Tasks: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(expiredTasks));
}
}
} }