Merge remote-tracking branch 'origin/v2.0.5_dev'

This commit is contained in:
HuangXin 2021-01-26 09:58:29 +08:00
commit 262a6b768c
1 changed files with 106 additions and 1 deletions

View File

@ -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<UserSvrInfo> 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<AddUserSvrReq> 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<AddUserSvrRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<AddUserSvrRsp>>() {
});
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<BusinessIdArray> 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<AddUserSvrRsp> rspInfo = objectMapper.readValue(ret,
new TypeReference<ProtocolRespDTO<AddUserSvrRsp>>() {
});
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())
));
}
});
}
}