REM:
1. 移除实体类部分字段的无用注解
2. 增加部分补充代码覆盖率单元测试
3. 修正某些log引起的异常
This commit is contained in:
HuangXin 2020-05-21 15:30:50 +08:00
parent aff557642d
commit 643c03ff7d
11 changed files with 70 additions and 15 deletions

View File

@ -59,9 +59,9 @@ public class TaskCacheManagerImpl implements TaskCacheManager {
|| taskData.getDisposeIp() == null
|| taskData.getDisposeIp().length() == 0
|| taskData.getId() == -1) {
if(taskData != null){
if (taskData != null) {
log.error("Add task error: taskId:{}, devId:{}, disposeIp:{}", taskData.getId(), taskData.getDeviceId(), taskData.getDisposeIp());
}else{
} else {
log.error("No Task info detail");
}
return ErrorCode.ERR_INPUTMISS;

View File

@ -82,7 +82,7 @@ public class UserAccountCacheManagerImpl implements UserAccountCacheManager {
return userAccountCache.get(token).getUsername();
}
log.error("according to token [{}] not found username {} in cache", token, userAccountCache.get(token).getUsername());
log.error("according to token [{}] not found username in cache", token);
return null;
}

View File

@ -3,7 +3,6 @@ package com.dispose.pojo.vo.device;
import com.dispose.pojo.vo.common.IDReturnStatus;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@ -14,7 +13,6 @@ import lombok.NoArgsConstructor;
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({"id", "ipAddr", "devId", "status", "message"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddNodeRetData extends IDReturnStatus {

View File

@ -2,8 +2,6 @@ package com.dispose.pojo.vo.device;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import java.util.ArrayList;
@ -13,8 +11,6 @@ import java.util.List;
* The type Add node rsp.
*/
@Data
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddNodeRsp {
/**

View File

@ -350,9 +350,6 @@ public class TaskServiceImpl implements TaskService {
*/
@Override
public boolean taskIsExpired(TaskInfoDetail task) {
LocalDateTime lt = LocalDateTime.parse(task.getPlanEndTime(),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
return LocalDateTime.parse(task.getPlanEndTime(),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
.isBefore(LocalDateTime.now());

View File

@ -147,7 +147,7 @@ public class UserAccountServiceImpl implements UserAccountService {
return userAccountMapper.getUserByName(username);
}
log.error("according to token [{}] not found username {}", token, username);
log.error("according to token [{}] not found username", token);
return null;
}
}

View File

@ -936,4 +936,38 @@ public class TaskControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
}
/**
* T 8 add task error test.
*/
@Test
public void t8_addTaskErrorTest() {
TaskInfoDetail taskData = TaskInfoDetail.builder()
.id(-1L)
.deviceId(1L)
.accountId(1L)
.type(DeviceCapacity.CLEANUP.getCode())
.disposeIp("")
.attackType("0")
.flowDirection(FlowDirection.DIRECTION_TWOWAY.getCode())
.currentStatus(DisposeTaskStatus.TASK_NEW.getCode())
.planEndTime("60")
.build();
Assert.assertEquals(taskCacheManager.addTask(null), ErrorCode.ERR_INPUTMISS);
Assert.assertEquals(taskCacheManager.addTask(taskData), ErrorCode.ERR_INPUTMISS);
Long taskId = createRunTaskStart();
taskData.setId(taskId);
taskData.setDisposeIp("1.1.1.1");
Assert.assertEquals(taskCacheManager.addTask(taskData), ErrorCode.ERR_DEVICEEXISTS);
}
/**
* T 8 upgrade task status error test.
*/
@Test
public void t8_upgradeTaskStatusErrorTest() {
Assert.assertEquals(taskCacheManager.upgradeTaskStatus(-123L, 3), ErrorCode.ERR_NOSUCHDEVICE);
}
}

View File

@ -67,6 +67,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
@Test
public void t1_permissionTest() {
Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken), ErrorCode.ERR_OK);
Assert.assertEquals(userAccountCacheManager.verifyPermission(userToken + "12345"), ErrorCode.ERR_LOGOUT);
}
/**
@ -75,6 +76,7 @@ public class UserAccountManagerTest extends InitTestEnvironment {
@Test
public void t2_getUsernameByTokenTest() {
Assert.assertEquals(userAccountCacheManager.getUsernameByToken(userToken), getUSER_NAME());
Assert.assertNull(userAccountCacheManager.getUsernameByToken(userToken + "12345"));
}
/**
@ -94,6 +96,8 @@ public class UserAccountManagerTest extends InitTestEnvironment {
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken), ErrorCode.ERR_OK);
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME() + "3213", userToken),
ErrorCode.ERR_LOGOUT);
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken + "13245"),
ErrorCode.ERR_TOKENNOTFOUND);
}
/**

View File

@ -125,4 +125,18 @@ public class DisposeNodeManagerTest extends InitTestEnvironment {
Assert.assertEquals(ret, ErrorCode.ERR_OK);
});
}
@Test
public void t6_delDisposeDeviceErrorTest() {
ErrorCode ret = disposeNodeManager.delDisposeDeviceById(-133L);
Assert.assertEquals(ret, ErrorCode.ERR_NOSUCHDEVICE);
ret = disposeNodeManager.delDisposeDeviceByIp("255.255.255.255");
Assert.assertEquals(ret, ErrorCode.ERR_NOSUCHDEVICE);
}
@Test
public void t7_getDisposeDeviceByIpTest() {
disposeDeviceMapper.selectAll().forEach(v -> Assert.assertNotNull(disposeNodeManager.getDisposeDeviceByIp(v.getIpAddr())));
}
}

View File

@ -77,7 +77,7 @@ public class TaskServiceTest extends InitTestEnvironment {
}
/**
* T 1 stop task test.
* T 2 stop task test.
*/
@Test
public void t2_stopTaskTest() {
@ -89,4 +89,16 @@ public class TaskServiceTest extends InitTestEnvironment {
});
}
@Test
public void t3_startTaskErrorTest() {
ErrorCode err = taskService.startTask(-133L);
Assert.assertEquals(err, ErrorCode.ERR_NOSUCHDEVICE);
}
@Test
public void t4_stopTaskErrorTest() {
ErrorCode err = taskService.stopTask(-133L);
Assert.assertEquals(err, ErrorCode.ERR_NOSUCHTASK);
}
}

View File

@ -88,8 +88,8 @@ public class UserAccountServiceTest extends InitTestEnvironment {
@Test
public void t3_getUserByTokenTest() {
UserAccount username = userAccountService.getUserByToken(UserAccountServiceTest.token);
Assert.assertEquals(username.getUsername(), getUSER_NAME());
Assert.assertNull(userAccountService.getUserByToken(UserAccountServiceTest.token + "1235"));
}
/**