REM:
1. 修改manager层清洗任务管理的单元测试
2. 修改数据库DisposeTask的打印日志
This commit is contained in:
chenlinghy 2020-08-24 15:49:42 +08:00
parent c1a352b272
commit e1fa24f3b9
2 changed files with 150 additions and 1 deletions

View File

@ -0,0 +1,149 @@
package com.dispose.test.manager;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.manager.DisposeTaskManager;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.entity.DisposeTask;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
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.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.util.List;
/**
* The type Dispose device manager test.
*
* @author <huangxin@cmhi.chinamoblie.com>
*/
@RunWith(SpringRunner.class)
@Slf4j
@SpringBootTest
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Transactional
@Rollback
public class DisposeTaskManagerTest {
/**
* The Object mapper.
*/
@Resource
private ObjectMapper objectMapper;
/**
* The Object mapper.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* The Dispose task manager.
*/
@Resource
private DisposeTaskManager disposeTaskManager;
/**
* A 1 Dispose ip running boolean.
*/
@Test
public void a1_disposeIpRunning() {
disposeTaskMapper.selectAll().forEach(v -> {
boolean runningResult = disposeTaskManager.disposeIpRunning(v.getDeviceId(), v.getDisposeIp(), v.getDisposeCapacity());
log.info("runningResult-->{}", runningResult);
if (v.getCurrentStatus() == DisposeTaskStatus.TASK_FINISHED
|| v.getCurrentStatus() == DisposeTaskStatus.TASK_CANCELED
|| v.getCurrentStatus() == DisposeTaskStatus.TASK_EXPIRED) {
Assert.assertFalse(runningResult);
} else {
Assert.assertTrue(runningResult);
}
});
}
/**
* A 2 Gets expired tasks.
*/
@Test
public void a2_getExpiredTasks() {
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);
List<DisposeTask> disposeTaskList = disposeTaskManager.getExpiredTasks();
Assert.assertNotNull(disposeTaskList);
if (expiredNumber > 0) {
Assert.assertNotEquals(disposeTaskList.size(), 0);
} else {
Assert.assertEquals(disposeTaskList.size(), 0);
}
}
/**
* A 3 Gets new dispose tasks.
*/
@Test
public void a3_getNewDisposeTasks() {
List<DisposeTask> taskList = disposeTaskMapper.selectAll();
long newNumber = taskList.stream().filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW).count();
log.info("newNumber-->{}", newNumber);
List<DisposeTask> disposeTaskList = disposeTaskManager.getNewDisposeTasks();
Assert.assertNotNull(disposeTaskList);
if (newNumber > 0) {
Assert.assertNotEquals(disposeTaskList.size(), 0);
} else {
Assert.assertEquals(disposeTaskList.size(), 0);
}
}
/**
* A 4 Gets dispose task by id.
*/
@Test
public void a4_getDisposeTaskById() {
disposeTaskMapper.selectAll().forEach(v -> {
log.info("taskId-->{}", v.getId());
DisposeTask disposeTask = disposeTaskManager.getDisposeTaskById(v.getId());
Assert.assertNotNull(disposeTask);
try {
log.info("DisposeTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(disposeTask));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
});
}
/**
* A 5 Change dispose task status boolean.
*/
@Test
public void a5_changeDisposeTaskStatus() {
disposeTaskMapper.selectAll().forEach(v -> {
for (DisposeTaskStatus d : DisposeTaskStatus.values()
) {
boolean result = disposeTaskManager.changeDisposeTaskStatus(v.getId(), d);
log.info("DisposeTaskStatus-->{}, result-->{}", d, result);
Assert.assertTrue(result);
Assert.assertEquals(d, disposeTaskMapper.getDisposeTaskById(v.getId()).getCurrentStatus());
}
});
}
}

View File

@ -217,7 +217,7 @@ public class DisposeTaskMapperTest {
Assert.assertNotNull(expiredTasks);
Assert.assertNotEquals(expiredTasks.size(), 0);
log.info("new Tasks: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(expiredTasks));
log.info("expired Tasks: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(expiredTasks));
}
}
}