REM:
1. 增加单元测试用例
This commit is contained in:
HuangXin 2020-04-30 10:27:45 +08:00
parent e6039e18fb
commit 6f08f56b37
5 changed files with 103 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import com.dispose.mapper.DisposeDeviceMapperTest;
import com.dispose.mapper.DisposeTaskMapperTest;
import com.dispose.mapper.UserAccountMapperTest;
import com.dispose.service.DisposeNodeManagerTest;
import com.dispose.service.TaskServiceTest;
import com.dispose.service.UserAccountServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@ -34,7 +35,8 @@ import org.junit.runners.Suite;
DeviceNodeManagerControllerTest.class,
DeviceNodeInfoControllerTest.class,
UserAccountServiceTest.class,
TaskControllerTest.class
TaskControllerTest.class,
TaskServiceTest.class
})
public class AllDisposePlatformTest {

View File

@ -105,4 +105,33 @@ public class AuthControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
}
/**
* Logout 2.
*
* @throws Exception the exception
*/
@Test
public void logout3() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName("admin2")
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/logout")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(502))
.andReturn()
.getResponse()
.getContentAsString();
}
}

View File

@ -190,6 +190,37 @@ public class TaskControllerTest extends InitTestEnvironment {
.getContentAsString();
}
@Test
public void t3_stopAllNodeIpTask() throws Exception {
StopTaskData itemData = StopTaskData.builder()
.disposeIp("192.168.5.2")
.type(DeviceCapacity.CLEANUP.getCode())
.id("-1")
.build();
StopTaskReq reqData = new StopTaskReq();
reqData.setItems(new ArrayList<>());
reqData.getItems().add(itemData);
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(reqData));
mockMvc.perform(MockMvcRequestBuilders
.post("/task/stop_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
}
/**
* T 4 stop node task.
*

View File

@ -8,6 +8,7 @@ import com.dispose.pojo.po.MReturnType;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
@ -59,6 +60,10 @@ public class DisposeNodeManagerTest extends InitTestEnvironment {
*/
@Override
public void userLogin() {
}
@After
public void reloadCacheData() {
disposeNodeManager.loadDisposeNodeFromDB();
}

View File

@ -0,0 +1,35 @@
package com.dispose.service;
import com.dispose.Global.InitTestEnvironment;
import com.dispose.common.ErrorCode;
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.context.junit4.SpringRunner;
import javax.annotation.Resource;
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TaskServiceTest extends InitTestEnvironment {
@Resource
private TaskService taskService;
@Override
public void userLogin() {
}
@Test
public void t1_stopTaskTest() {
ErrorCode err = taskService.stopTask(-1L);
Assert.assertEquals(err, ErrorCode.ERR_NOSUCHDEVICE);
}
}