parent
ee2ff75a26
commit
554cc51ec3
|
@ -1,15 +1,10 @@
|
||||||
package com.dispose.test.mapper;
|
package com.dispose.test.mapper;
|
||||||
|
|
||||||
import com.dispose.common.DisposeCapacityType;
|
import com.dispose.common.*;
|
||||||
import com.dispose.common.DisposeObjectType;
|
|
||||||
import com.dispose.common.DisposeTaskStatus;
|
|
||||||
import com.dispose.common.IpAddrType;
|
|
||||||
import com.dispose.mapper.DeviceTaskMapper;
|
import com.dispose.mapper.DeviceTaskMapper;
|
||||||
import com.dispose.mapper.DisposeDeviceMapper;
|
import com.dispose.mapper.DisposeDeviceMapper;
|
||||||
import com.dispose.mapper.DisposeTaskMapper;
|
import com.dispose.mapper.DisposeTaskMapper;
|
||||||
import com.dispose.mapper.UserAccountMapper;
|
|
||||||
import com.dispose.pojo.entity.DeviceTask;
|
import com.dispose.pojo.entity.DeviceTask;
|
||||||
import com.dispose.pojo.entity.DisposeCapacity;
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -79,14 +74,14 @@ public class DeviceTaskMapperTest {
|
||||||
.taskId(tId)
|
.taskId(tId)
|
||||||
.deviceId(dId)
|
.deviceId(dId)
|
||||||
.taskAttackType(10737508814L)
|
.taskAttackType(10737508814L)
|
||||||
.status((long)DisposeTaskStatus.TASK_FINISHED.getValue())
|
.status((long) DisposeTaskStatus.TASK_FINISHED.getValue())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
taskList.add(DeviceTask.builder()
|
taskList.add(DeviceTask.builder()
|
||||||
.taskId(tId)
|
.taskId(tId)
|
||||||
.deviceId(dId)
|
.deviceId(dId)
|
||||||
.taskAttackType(25097508814L)
|
.taskAttackType(25097508814L)
|
||||||
.status((long)DisposeTaskStatus.TASK_NEW.getValue())
|
.status((long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,8 +89,187 @@ public class DeviceTaskMapperTest {
|
||||||
|
|
||||||
int number = deviceTaskMapper.addNewTaskInfoList(taskList);
|
int number = deviceTaskMapper.addNewTaskInfoList(taskList);
|
||||||
|
|
||||||
log.info("number-->{}",number );
|
log.info("number-->{}", number);
|
||||||
Assert.assertNotNull(taskList);
|
Assert.assertNotNull(taskList);
|
||||||
Assert.assertEquals(number, taskList.size());
|
Assert.assertEquals(number, taskList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A 2 add new task info.
|
||||||
|
*
|
||||||
|
* @throws JsonProcessingException the json processing exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void a2_addNewTaskInfo() throws JsonProcessingException {
|
||||||
|
Long dId = disposeDeviceMapper.selectAll().get(0).getId();
|
||||||
|
Long tId = disposeTaskMapper.selectAll().get(0).getId();
|
||||||
|
|
||||||
|
DeviceTask deviceTask = DeviceTask.builder()
|
||||||
|
.taskId(tId)
|
||||||
|
.deviceId(dId)
|
||||||
|
.taskAttackType(8265301L)
|
||||||
|
.status((long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask));
|
||||||
|
|
||||||
|
int number = deviceTaskMapper.addNewTaskInfo(deviceTask);
|
||||||
|
|
||||||
|
log.info("number-->{}", number);
|
||||||
|
Assert.assertNotNull(deviceTask);
|
||||||
|
Assert.assertEquals(number, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A 3 gets task info by task id.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void a3_getTaskInfoByTaskId() {
|
||||||
|
deviceTaskMapper.selectAll().forEach(v -> {
|
||||||
|
List<DeviceTask> deviceTaskList = deviceTaskMapper.getTaskInfoByTaskId(v.getTaskId());
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("deviceTaskList: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTaskList));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertNotNull(deviceTaskList);
|
||||||
|
Assert.assertNotEquals(deviceTaskList.size(), 0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A 4 gets task info by id.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void a4_getTaskInfoById() {
|
||||||
|
deviceTaskMapper.selectAll().forEach(v -> {
|
||||||
|
DeviceTask deviceTask = deviceTaskMapper.getTaskInfoById(v.getId());
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("deviceTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deviceTask));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertNotNull(deviceTask);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A 5 gets task info.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void a5_getTaskInfo() throws JsonProcessingException {
|
||||||
|
List<DeviceTask> deviceTaskList = deviceTaskMapper.selectAll();
|
||||||
|
|
||||||
|
long newNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||||
|
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue())).count();
|
||||||
|
log.info("newNumber-->{}", newNumber);
|
||||||
|
|
||||||
|
if (newNumber > 0) {
|
||||||
|
List<DeviceTask> newTask = deviceTaskMapper.getNewTaskInfos();
|
||||||
|
log.info("newTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(newTask));
|
||||||
|
|
||||||
|
Assert.assertNotNull(newTask);
|
||||||
|
Assert.assertNotEquals(newTask.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
long runningNumber = deviceTaskList.stream().filter(v -> (v.getStatus() == (long) DisposeTaskStatus.TASK_NEW.getValue())
|
||||||
|
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTING.getValue()
|
||||||
|
|| (v.getStatus() == (long) DisposeTaskStatus.TASK_STARTED.getValue()))).count();
|
||||||
|
log.info("runningNumber-->{}", runningNumber);
|
||||||
|
|
||||||
|
if (runningNumber > 0) {
|
||||||
|
List<DeviceTask> runningTask = deviceTaskMapper.getRunningTaskInfos();
|
||||||
|
log.info("runningTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(runningTask));
|
||||||
|
|
||||||
|
Assert.assertNotNull(runningTask);
|
||||||
|
Assert.assertNotEquals(runningTask.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceTaskList.forEach(v -> {
|
||||||
|
List<DeviceTask> detailsTask = deviceTaskMapper.getTaskByDetails(v.getTaskId(), v.getDeviceId(), v.getTaskAttackType());
|
||||||
|
|
||||||
|
try {
|
||||||
|
log.info("detailsTask: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(detailsTask));
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertNotNull(detailsTask);
|
||||||
|
|
||||||
|
if (v.getStatus() == (long) DisposeTaskStatus.TASK_FINISHED.getValue()
|
||||||
|
|| v.getStatus() == (long) DisposeTaskStatus.TASK_CANCELED.getValue()
|
||||||
|
|| v.getStatus() == (long) DisposeTaskStatus.TASK_EXPIRED.getValue()) {
|
||||||
|
Assert.assertEquals(detailsTask.size(), 0);
|
||||||
|
} else {
|
||||||
|
Assert.assertNotEquals(detailsTask.size(), 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A 6 change task info.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void a6_changeTaskInfo() {
|
||||||
|
DeviceTask deviceTask = deviceTaskMapper.selectAll().get(0);
|
||||||
|
|
||||||
|
// change task status.
|
||||||
|
for (DisposeTaskStatus status : DisposeTaskStatus.values()
|
||||||
|
) {
|
||||||
|
int result = deviceTaskMapper.changeTaskStatus(deviceTask.getId(), status);
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(Long.valueOf(status.getValue()), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
// change exec attack type in value.
|
||||||
|
for (int i = 0; i <= 10; i++) {
|
||||||
|
int result = deviceTaskMapper.changeExecAttackTypeInValue(deviceTask.getId(), (long) i);
|
||||||
|
log.info("i-->{}, execAttackTypeIn-->{}", i, deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn());
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(Long.valueOf(i), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeIn());
|
||||||
|
}
|
||||||
|
|
||||||
|
// change exec attack type out value.
|
||||||
|
for (int i = 0; i <= 10; i++) {
|
||||||
|
int result = deviceTaskMapper.changeExecAttackTypeOutValue(deviceTask.getId(), (long) i);
|
||||||
|
log.info("i-->{}, execAttackTypeOut-->{}", i, deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut());
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(Long.valueOf(i), deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExecAttackTypeOut());
|
||||||
|
}
|
||||||
|
|
||||||
|
// change attack type status in value.
|
||||||
|
for (long i = 10737508814L; i <= 10737508824L; i++) {
|
||||||
|
int result = deviceTaskMapper.changeAttackTypeStatusInValue(deviceTask.getId(), i);
|
||||||
|
log.info("i-->{},attackTypeStatusIn-->{}", i, deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn());
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusIn()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// change attack type status out value.
|
||||||
|
for (long i = 10737508814L; i <= 10737508824L; i++) {
|
||||||
|
int result = deviceTaskMapper.changeAttackTypeStatusOutValue(deviceTask.getId(), i);
|
||||||
|
log.info("i-->{},attackTypeStatusOut-->{}", i, deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut());
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getAttackTypeStatusOut()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// change err retry.
|
||||||
|
for (int i = 0; i <= 5; i++) {
|
||||||
|
int result = deviceTaskMapper.changeErrRetry(deviceTask.getId(), i);
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getErrRetry()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// change extern id.
|
||||||
|
for (long i = 223L; i <= 230L; i++) {
|
||||||
|
int result = deviceTaskMapper.changeExternId(deviceTask.getId(), i);
|
||||||
|
Assert.assertEquals(result, 1);
|
||||||
|
Assert.assertEquals(String.valueOf(i), String.valueOf(deviceTaskMapper.getTaskInfoById(deviceTask.getId()).getExternId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue