REM:
1. 添加TaskService单元测试用例
This commit is contained in:
HuangXin 2020-05-09 18:24:44 +08:00
parent a8ab31e69f
commit a0dda8322c
1 changed files with 58 additions and 4 deletions

View File

@ -1,7 +1,12 @@
package com.dispose.service;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.DeviceCapacity;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.ErrorCode;
import com.dispose.common.FlowDirection;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.vo.common.TaskInfoDetail;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
@ -9,27 +14,76 @@ 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;
/**
* The type Task service test.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@Transactional
@Rollback
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TaskServiceTest extends InitTestEnvironment {
/**
* The Task service.
*/
@Resource
private TaskService taskService;
@Override
public void userLogin() {
/**
* The Dispose task mapper.
*/
@Resource
private DisposeTaskMapper disposeTaskMapper;
/**
* User login.
*/
@Override
public void userLogin() throws Exception {
super.userLogin();
TaskInfoDetail taskData = TaskInfoDetail.builder()
.id(-1L)
.deviceId(1L)
.accountId(1L)
.type(DeviceCapacity.CLEANUP.getCode())
.disposeIp("192.168.5.3")
.attackType("0")
.flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode())
.currentStatus(DisposeTaskStatus.TASK_NEW.getCode())
.planEndTime("60")
.build();
taskService.createTask(taskData);
}
/**
* T 2 start task test.
*/
@Test
public void t2_startTaskTest() {
disposeTaskMapper.getAllTaskByStatus(DisposeTaskStatus.TASK_NEW.getCode()).forEach(v -> {
ErrorCode err = taskService.startTask(v.getId());
Assert.assertEquals(err, ErrorCode.ERR_OK);
});
}
/**
* T 1 stop task test.
*/
@Test
public void t1_stopTaskTest() {
ErrorCode err = taskService.stopTask(-1L);
disposeTaskMapper.getAllTaskByStatus(DisposeTaskStatus.TASK_RUNNING.getCode()).forEach(v -> {
ErrorCode err = taskService.stopTask(v.getId());
Assert.assertEquals(err, ErrorCode.ERR_OK);
});
Assert.assertNotEquals(err, ErrorCode.ERR_OK);
}
}