REM:
1. 移除部分重复单元测试用例
This commit is contained in:
HuangXin 2020-09-17 09:38:04 +08:00
parent bbe8b13cff
commit b542a0e307
1 changed files with 225 additions and 238 deletions

View File

@ -1,18 +1,8 @@
package com.dispose.test.dev.manager; package com.dispose.test.dev.manager;
import com.dispose.common.DisposeTaskStatus;
import com.dispose.common.NetflowDirection;
import com.dispose.manager.DeviceTaskManager;
import com.dispose.mapper.DeviceTaskMapper;
import com.dispose.mapper.DisposeTaskMapper;
import com.dispose.pojo.entity.DeviceTask;
import com.dispose.test.dev.Global.InitTestEnvironment; import com.dispose.test.dev.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -21,9 +11,6 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/** /**
* The type Dispose device manager test. * The type Dispose device manager test.
* *
@ -37,229 +24,229 @@ import java.util.List;
@Transactional @Transactional
@Rollback @Rollback
public class DeviceTaskManagerTest extends InitTestEnvironment { public class DeviceTaskManagerTest extends InitTestEnvironment {
/** // /**
* The Object mapper. // * The Object mapper.
*/ // */
@Resource // @Resource
private ObjectMapper objectMapper; // private ObjectMapper objectMapper;
//
/** // /**
* The device task mapper. // * The device task mapper.
*/ // */
@Resource // @Resource
private DeviceTaskMapper deviceTaskMapper; // private DeviceTaskMapper deviceTaskMapper;
/** // /**
* The device task manager. // * The device task manager.
*/ // */
@Resource // @Resource
private DeviceTaskManager deviceTaskManager; // private DeviceTaskManager deviceTaskManager;
/** // /**
* The Dispose task mapper. // * The Dispose task mapper.
*/ // */
@Resource // @Resource
private DisposeTaskMapper disposeTaskMapper; // private DisposeTaskMapper disposeTaskMapper;
//
/** // /**
* A 1 add dispose device task info boolean. // * A 1 add dispose device task info boolean.
*/ // */
@Test // @Test
public void a1_addDisposeDeviceTaskInfo() { // public void a1_addDisposeDeviceTaskInfo() {
Long deviceId = deviceTaskMapper.selectAll().get(0).getDeviceId(); // Long deviceId = deviceTaskMapper.selectAll().get(0).getDeviceId();
Long taskId = disposeTaskMapper.selectAll().get(0).getId(); // Long taskId = disposeTaskMapper.selectAll().get(0).getId();
//
// 如果已经存在相同任务不再添加重复任务 // // 如果已经存在相同任务不再添加重复任务
deviceTaskMapper.selectAll().forEach(v -> { // deviceTaskMapper.selectAll().forEach(v -> {
boolean result = deviceTaskManager.addDisposeDeviceTaskInfo(v.getTaskId(), v.getDeviceId(), v.getTaskAttackType()); // boolean result = deviceTaskManager.addDisposeDeviceTaskInfo(v.getTaskId(), v.getDeviceId(), v.getTaskAttackType());
log.info("result-->{}", result); // log.info("result-->{}", result);
Assert.assertTrue(result); // Assert.assertTrue(result);
}); // });
//
//
DeviceTask deviceTask = DeviceTask.builder() // DeviceTask deviceTask = DeviceTask.builder()
.taskId(taskId) // .taskId(taskId)
.deviceId(deviceId) // .deviceId(deviceId)
.taskAttackType(10737508815L) // .taskAttackType(10737508815L)
.build(); // .build();
//
boolean addResult = deviceTaskManager.addDisposeDeviceTaskInfo(deviceTask.getTaskId(), deviceTask.getDeviceId(), // boolean addResult = deviceTaskManager.addDisposeDeviceTaskInfo(deviceTask.getTaskId(), deviceTask.getDeviceId(),
deviceTask.getTaskAttackType()); // deviceTask.getTaskAttackType());
log.info("addResult-->{}", addResult); // log.info("addResult-->{}", addResult);
Assert.assertTrue(addResult); // Assert.assertTrue(addResult);
} // }
//
/** // /**
* A 2 gets new dispose device task info. // * A 2 gets new dispose device task info.
*/ // */
@Test // @Test
public void a2_getNewDisposeDeviceTaskInfo() throws JsonProcessingException { // public void a2_getNewDisposeDeviceTaskInfo() throws JsonProcessingException {
List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll(); // List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll();
//
long newNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue()) // long newNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue())).count(); // || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue())).count();
log.info("newNumber-->{}", newNumber); // log.info("newNumber-->{}", newNumber);
//
if (newNumber > 0) { // if (newNumber > 0) {
List<DeviceTask> newTask = deviceTaskManager.getNewDisposeDeviceTaskInfo(); // List<DeviceTask> newTask = deviceTaskManager.getNewDisposeDeviceTaskInfo();
log.info("newTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask)); // log.info("newTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask));
//
Assert.assertNotNull(newTask); // Assert.assertNotNull(newTask);
Assert.assertNotEquals(newTask.size(), 0); // Assert.assertNotEquals(newTask.size(), 0);
} // }
} // }
//
/** // /**
* A 3 gets started dispose device task info. // * A 3 gets started dispose device task info.
*/ // */
@Test // @Test
public void a3_getStartedDisposeDeviceTaskInfo() throws JsonProcessingException { // public void a3_getStartedDisposeDeviceTaskInfo() throws JsonProcessingException {
List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll(); // List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll();
//
long startedNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue()) // long startedNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue() // || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue()
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTED.getValue()))).count(); // || (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTED.getValue()))).count();
log.info("startedNumber-->{}", startedNumber); // log.info("startedNumber-->{}", startedNumber);
//
if (startedNumber > 0) { // if (startedNumber > 0) {
List<DeviceTask> startedTask = deviceTaskManager.getStartedDisposeDeviceTaskInfo(); // List<DeviceTask> startedTask = deviceTaskManager.getStartedDisposeDeviceTaskInfo();
log.info("startedTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(startedTask)); // log.info("startedTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(startedTask));
//
Assert.assertNotNull(startedTask); // Assert.assertNotNull(startedTask);
Assert.assertNotEquals(startedTask.size(), 0); // Assert.assertNotEquals(startedTask.size(), 0);
} // }
} // }
//
/** // /**
* A 4 change dispose device task info status. // * A 4 change dispose device task info status.
*/ // */
@Test // @Test
public void a4_changeDisposeDeviceTaskInfoStatus() { // public void a4_changeDisposeDeviceTaskInfoStatus() {
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); // DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
//
for (DisposeTaskStatus status : DisposeTaskStatus.values() // for (DisposeTaskStatus status : DisposeTaskStatus.values()
) { // ) {
boolean result = deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), status); // boolean result = deviceTaskManager.changeDisposeDeviceTaskInfoStatus(deviceTask.getId(), status);
Assert.assertTrue(result); // Assert.assertTrue(result);
Assert.assertEquals(Long.valueOf(status.getValue()), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getStatus()); // Assert.assertEquals(Long.valueOf(status.getValue()), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getStatus());
} // }
} // }
//
/** // /**
* A 5 exec attack type. // * A 5 exec attack type.
*/ // */
@Test // @Test
public void a5_execAttackType() { // public void a5_execAttackType() {
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); // DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
//
//sets exec attack type // //sets exec attack type
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
for (long i = 10737508814L; i <= 10737508824L; i++) { // for (long i = 10737508814L; i <= 10737508824L; i++) {
boolean result = deviceTaskManager.setExecAttackType(deviceTask.getId(), nf, i); // boolean result = deviceTaskManager.setExecAttackType(deviceTask.getId(), nf, i);
Assert.assertTrue(result); // Assert.assertTrue(result);
//
if (nf == NetflowDirection.DIRECTION_IN) { // if (nf == NetflowDirection.DIRECTION_IN) {
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn()));
} else { // } else {
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut()));
} // }
} // }
} // }
//
//exec attack type clean bits // //exec attack type clean bits
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 2); // deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 2);
deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 4); // deviceTaskManager.execAttackTypeCleanBit(deviceTask.getId(), nf, 4);
} // }
//
//exec attack type set bits // //exec attack type set bits
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 2); // deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 2);
deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 4); // deviceTaskManager.execAttackTypeSetBit(deviceTask.getId(), nf, 4);
} // }
} // }
//
/** // /**
* A 6 exec attack type status. // * A 6 exec attack type status.
*/ // */
@Test // @Test
public void a6_attackTypeStatus() { // public void a6_attackTypeStatus() {
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); // DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
//
//sets exec attack type // //sets exec attack type
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
for (long i = 10737508814L; i <= 10737508824L; i++) { // for (long i = 10737508814L; i <= 10737508824L; i++) {
boolean result = deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), nf, i); // boolean result = deviceTaskManager.setAttackTypeStatus(deviceTask.getId(), nf, i);
Assert.assertTrue(result); // Assert.assertTrue(result);
//
if (nf == NetflowDirection.DIRECTION_IN) { // if (nf == NetflowDirection.DIRECTION_IN) {
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn()));
} else { // } else {
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut()));
} // }
} // }
} // }
//
//attack type status clean bits // //attack type status clean bits
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 2); // deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 2);
deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 4); // deviceTaskManager.attackTypeStatusCleanBit(deviceTask.getId(), nf, 4);
} // }
//
//attack type status set bits // //attack type status set bits
for (NetflowDirection nf : NetflowDirection.values() // for (NetflowDirection nf : NetflowDirection.values()
) { // ) {
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 2); // deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 2);
deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 4); // deviceTaskManager.attackTypeStatusSetBit(deviceTask.getId(), nf, 4);
} // }
} // }
//
/** // /**
* A 7 sets task error retry times. // * A 7 sets task error retry times.
*/ // */
@Test // @Test
public void a7_setTaskErrRetryTimes() { // public void a7_setTaskErrRetryTimes() {
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); // DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
//
for (int i = 0; i <= 5; i++) { // for (int i = 0; i <= 5; i++) {
boolean result = deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), i); // boolean result = deviceTaskManager.setTaskErrRetryTimes(deviceTask.getId(), i);
Assert.assertTrue(result); // Assert.assertTrue(result);
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getErrRetry())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getErrRetry()));
} // }
} // }
//
/** // /**
* A 8 sets task extern id. // * A 8 sets task extern id.
*/ // */
@Test // @Test
public void a8_setTaskExternId() { // public void a8_setTaskExternId() {
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0); // DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
//
for (long i = 223L; i <= 230L; i++) { // for (long i = 223L; i <= 230L; i++) {
boolean result = deviceTaskManager.setTaskExternId(deviceTask.getId(), i); // boolean result = deviceTaskManager.setTaskExternId(deviceTask.getId(), i);
Assert.assertTrue(result); // Assert.assertTrue(result);
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId())); // Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId()));
} // }
} // }
//
/** // /**
* A 9 gets task by id. // * A 9 gets task by id.
*/ // */
@Test // @Test
public void a9_getTaskById() { // public void a9_getTaskById() {
deviceTaskMapper.selectAll().forEach(v -> { // deviceTaskMapper.selectAll().forEach(v -> {
DeviceTask deviceTask = deviceTaskManager.getTaskById(v.getId()); // DeviceTask deviceTask = deviceTaskManager.getTaskById(v.getId());
//
try { // try {
log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask)); // log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask));
} catch (JsonProcessingException e) { // } catch (JsonProcessingException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//
Assert.assertNotNull(deviceTask); // Assert.assertNotNull(deviceTask);
}); // });
} // }
} }