REM:
1. 增加service层获取节点信息方法的单元测试
2. 增加获取处置能力节点接口的单元测试
This commit is contained in:
chenlinghy 2020-08-07 16:33:43 +08:00
parent b9bfbfd468
commit f93be79d55
3 changed files with 126 additions and 9 deletions

View File

@ -236,7 +236,7 @@ public class DisposeDeviceManagerController {
*/
@PostMapping("/device_list")
@ResponseBody
@ApiOperation("删除处置能力节点")
@ApiOperation("获取处置能力节点")
public ProtocolRespDTO<? extends BaseRespStatus> getAllDisposeDevice(
@Validated(ValidGroups.ProtocolCommonValid.class)
@RequestBody ProtocolReqDTO<GetDeviceReq> mr) {

View File

@ -340,9 +340,6 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(afterDev));
if (deviceInfoRsp.getStatus() == ErrorCode.ERR_OK.getCode()) {
log.info("+++++++++++++++++++++before{}", beforeDev.get(0).getSecondParam());
log.info("+++++++++++++++++++++after{}", afterDev.getVersion());
Assert.assertNotNull(deviceInfoRsp);
Assert.assertNotNull(deviceInfoRsp.getId());
Assert.assertNotNull(deviceInfoRsp.getMessage());
@ -352,4 +349,60 @@ public class DisposeDeviceManagerControllerTest extends InitTestEnvironment {
}
}
}
/**
* D 1 get dispose device.
*
* @throws Exception the exception
*/
@Test
public void d1_getAllDisposeDevice() throws Exception {
List<DisposeDevice> deviceList = disposeDeviceMapper.selectAll();
GetDeviceReq getReq = new GetDeviceReq();
for (int i = 1; i < 5; i++) {
getReq.setStartPage(i);
getReq.setPageSize(String.valueOf(i * 10));
ProtocolReqDTO<GetDeviceReq> reqInfo = new ProtocolReqDTO<>();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode());
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(getReq);
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/manager/device_list")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", ConstValue.STRING_HTTP_AUTH_HEAD + getLoginToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(HttpStatus.ok().status()))
.andReturn()
.getResponse()
.getContentAsString();
ProtocolRespDTO<GetDeviceRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<GetDeviceRsp>>() {
});
verifyRespProtocol(rspInfo);
log.debug(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(rspInfo));
double totalPages = Math.ceil(deviceList.size() / Double.parseDouble(getReq.getPageSize()));
Assert.assertEquals(rspInfo.getMsgContent().getCurPageNumber(), getReq.getStartPage());
Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getPageSize()), String.valueOf(getReq.getPageSize()));
Assert.assertEquals(String.valueOf(rspInfo.getMsgContent().getTotalItems()), String.valueOf(deviceList.size()));
Assert.assertEquals(Double.valueOf(rspInfo.getMsgContent().getTotalPages()), Double.valueOf(totalPages));
if(totalPages >= (double)(getReq.getStartPage())){
Assert.assertNotEquals(rspInfo.getMsgContent().getItems().size(), 0);
}else{
Assert.assertEquals(rspInfo.getMsgContent().getItems().size(), 0);
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.dispose.test.service;
import com.dispose.common.*;
import com.dispose.mapper.DisposeDeviceMapper;
import com.dispose.pojo.entity.DisposeDevice;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.service.DisposeDeviceManagerService;
@ -8,6 +9,7 @@ import com.dispose.service.UserAccountService;
import com.dispose.test.Global.InitTestEnvironment;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Before;
@ -56,6 +58,12 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
*/
@Resource
private ObjectMapper objectMapper;
/**
* The Object mapper.
*/
@Resource
private DisposeDeviceMapper disposeDeviceMapper;
/**
* User login test.
*
@ -103,7 +111,7 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.addDisposeDevice(devList);
ret.forEach(v->{
ret.forEach(v -> {
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertNotNull(v.getSecondParam().getId());
@ -150,14 +158,14 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
disposeDeviceManagerService.addDisposeDevice(devList);
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
devList.forEach(dev->{
devList.forEach(dev -> {
dev.setDeviceName("测试清洗设备");
dev.setManufacturer("Unknown");
});
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.upgradeDisposeDevice(devList);
ret.forEach(v->{
ret.forEach(v -> {
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertEquals(v.getSecondParam().getDeviceName(), "测试清洗设备");
@ -202,11 +210,11 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
disposeDeviceManagerService.addDisposeDevice(devList);
log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(devList));
devList.forEach(dev-> removeIds.add(dev.getId()));
devList.forEach(dev -> removeIds.add(dev.getId()));
List<MulReturnType<ErrorCode, DisposeDevice>> ret = disposeDeviceManagerService.removeDisposeDevice(removeIds);
ret.forEach(v->{
ret.forEach(v -> {
if (v.getFirstParam() == ErrorCode.ERR_OK) {
Assert.assertNotNull(v.getSecondParam());
Assert.assertEquals(v.getSecondParam().getStatus(), ObjectStatus.DELETED);
@ -216,4 +224,60 @@ public class DisposeDeviceManagerServiceTest extends InitTestEnvironment {
}
});
}
/**
* A 4 get all dispose device test.
*/
@Test
public void a4_getAllDisposeDeviceTest(){
List<DisposeDevice> devs = disposeDeviceMapper.selectAll();
for (int i = 1; i < 5; i++) {
Integer startPage = i;
Integer pageSize = i * 2;
MulReturnType<PageInfo<DisposeDevice>, List<DisposeDevice>> ret = disposeDeviceManagerService.getAllDisposeDevice(startPage, pageSize);
PageInfo<DisposeDevice> pageInfo = ret.getFirstParam();
List<DisposeDevice> deviceList = ret.getSecondParam();
Assert.assertEquals(pageInfo.getPageNum(), (long) startPage);
Assert.assertEquals(pageInfo.getPageSize(), (long) pageSize);
//数据库设备信息数据量比较大
if (devs.size() >= (startPage * pageSize)) {
if (pageInfo.getPageNum() != 1) {
Assert.assertFalse(pageInfo.isIsFirstPage());
Assert.assertTrue(pageInfo.isHasPreviousPage());
Assert.assertEquals(pageInfo.getPrePage(), startPage - 1);
} else {
Assert.assertTrue(pageInfo.isIsFirstPage());
Assert.assertFalse(pageInfo.isHasPreviousPage());
}
if ((deviceList.size() - startPage * pageSize) / pageSize >= 0) {
Assert.assertNotEquals(deviceList.size(), 0);
} else {
Assert.assertEquals(deviceList.size(), 0);
}
} else {
if (pageInfo.getPageNum() != 1) {
Assert.assertFalse(pageInfo.isIsFirstPage());
Assert.assertTrue(pageInfo.isHasPreviousPage());
Assert.assertEquals(pageInfo.getPrePage(), startPage - 1);
} else {
Assert.assertTrue(pageInfo.isIsFirstPage());
Assert.assertFalse(pageInfo.isHasNextPage());
}
if ((deviceList.size() - startPage * pageSize) / pageSize >= 0) {
Assert.assertNotEquals(deviceList.size(), 0);
} else {
Assert.assertEquals(deviceList.size(), 0);
}
Assert.assertFalse(pageInfo.isHasNextPage());
}
}
}
}