diff --git a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java index fb6a44a1..d017f8d5 100644 --- a/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java +++ b/src/main/java/com/dispose/controller/DisposeDeviceManagerController.java @@ -236,7 +236,7 @@ public class DisposeDeviceManagerController { */ @PostMapping("/device_list") @ResponseBody - @ApiOperation("删除处置能力节点") + @ApiOperation("获取处置能力节点") public ProtocolRespDTO getAllDisposeDevice( @Validated(ValidGroups.ProtocolCommonValid.class) @RequestBody ProtocolReqDTO mr) { diff --git a/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java b/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java index a71d7ce3..a5bf3837 100644 --- a/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java +++ b/src/test/java/com/dispose/test/controller/DisposeDeviceManagerControllerTest.java @@ -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 deviceList = disposeDeviceMapper.selectAll(); + + GetDeviceReq getReq = new GetDeviceReq(); + + for (int i = 1; i < 5; i++) { + getReq.setStartPage(i); + getReq.setPageSize(String.valueOf(i * 10)); + + ProtocolReqDTO 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 rspInfo = objectMapper.readValue(ret, + new TypeReference>() { + }); + + 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); + } + } + } } diff --git a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java b/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java index d8bc231c..134726f6 100644 --- a/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java +++ b/src/test/java/com/dispose/test/service/DisposeDeviceManagerServiceTest.java @@ -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> 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> 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> 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 devs = disposeDeviceMapper.selectAll(); + + for (int i = 1; i < 5; i++) { + Integer startPage = i; + Integer pageSize = i * 2; + + MulReturnType, List> ret = disposeDeviceManagerService.getAllDisposeDevice(startPage, pageSize); + + PageInfo pageInfo = ret.getFirstParam(); + List 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()); + } + } + } }