diff --git a/src/test/java/com/dispose/test/dev/controller/UserBusinessControllerTest.java b/src/test/java/com/dispose/test/dev/controller/UserBusinessControllerTest.java index 7e196a1d..73fee63f 100644 --- a/src/test/java/com/dispose/test/dev/controller/UserBusinessControllerTest.java +++ b/src/test/java/com/dispose/test/dev/controller/UserBusinessControllerTest.java @@ -8,6 +8,7 @@ import com.dispose.pojo.dto.protocol.base.ProtocolReqDTO; import com.dispose.pojo.dto.protocol.base.ProtocolRespDTO; import com.dispose.pojo.dto.protocol.device.business.AddUserSvrReq; import com.dispose.pojo.dto.protocol.device.business.AddUserSvrRsp; +import com.dispose.pojo.dto.protocol.device.business.BusinessIdArray; import com.dispose.pojo.dto.protocol.device.business.UserSvrInfo; import com.dispose.service.UserBusinessManagerService; import com.dispose.test.dev.Global.InitTestEnvironment; @@ -98,7 +99,6 @@ public class UserBusinessControllerTest extends InitTestEnvironment { reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode()); reqInfo.setTimeStamp(System.currentTimeMillis()); reqInfo.setMsgContent(req); - log.info("reqIfo: {}",reqInfo); String ret = mockMvc.perform(MockMvcRequestBuilders .put("/business/manage") @@ -134,5 +134,110 @@ public class UserBusinessControllerTest extends InitTestEnvironment { } + /** + * A 2 update business test. + * + * @throws Exception the exception + */ + @Test + public void a2_updateBusinessTest() throws Exception{ + List newList = new ArrayList<>(); + newList.add(UserSvrInfo.builder() + .businessId("controller1") + .businessType("DNS") + .businessIp("192.168.11.11") + .businessBandwidth("200") + .build()); + AddUserSvrReq req = AddUserSvrReq.builder() + .items(newList) + .build(); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO<>(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode()); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(req); + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/business/updateBusiness") + .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)); + + Assert.assertNotNull(rspInfo.getMsgContent().getItems()); + + rspInfo.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getStatus()); + if (k.getStatus() == ErrorCode.ERR_OK.getCode()) { + Assert.assertNotNull(k.getMessage()); + Assert.assertNotNull(k.getBusinessId()); + Assert.assertTrue(serviceGroupMapper.selectAll().stream().anyMatch(v -> + k.getBusinessId().equals(v.getServiceId()) + )); + } + }); + + } + + /** + * A 3 del user business test. + * + * @throws Exception the exception + */ + @Test + public void a3_delUserBusinessTest() throws Exception{ + String[] newList = new String[]{"controller2"}; + BusinessIdArray req = new BusinessIdArray(newList); + + ProtocolReqDTO reqInfo = new ProtocolReqDTO<>(); + reqInfo.setVer(ConstValue.Protocol.VERSION); + reqInfo.setCryptoType(ProtoCryptoType.CRYPTO_NONE.getCode()); + reqInfo.setTimeStamp(System.currentTimeMillis()); + reqInfo.setMsgContent(req); + + String ret = mockMvc.perform(MockMvcRequestBuilders + .delete("/business/manage") + .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)); + + Assert.assertNotNull(rspInfo.getMsgContent().getItems()); + + rspInfo.getMsgContent().getItems().forEach(k -> { + Assert.assertNotNull(k.getStatus()); + if (k.getStatus() == ErrorCode.ERR_OK.getCode()) { + Assert.assertNotNull(k.getMessage()); + Assert.assertNotNull(k.getBusinessId()); + Assert.assertTrue(serviceGroupMapper.selectAll().stream().noneMatch(v -> + k.getBusinessId().equals(v.getServiceId()) + )); + } + }); + + } }