diff --git a/src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java b/src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java new file mode 100644 index 00000000..f1bb9f8c --- /dev/null +++ b/src/test/java/com/dispose/test/manager/DisposeTaskManagerTest.java @@ -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 + */ +@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 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 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 taskList = disposeTaskMapper.selectAll(); + + long newNumber = taskList.stream().filter(v -> v.getCurrentStatus() == DisposeTaskStatus.TASK_NEW).count(); + log.info("newNumber-->{}", newNumber); + + List 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()); + } + }); + } +} diff --git a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java index 55baff83..f111f364 100644 --- a/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/DisposeTaskMapperTest.java @@ -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)); } } }