REM:
1. 添加DeviceNodeInfoController QA测试用例中获取节点防护IP接口正常用例和异常用例测试代码
This commit is contained in:
chenlinghy 2020-05-12 17:03:30 +08:00
parent 5c9b19d5af
commit 8ad1a028a5
1 changed files with 265 additions and 0 deletions

View File

@ -1002,6 +1002,271 @@ public class DeviceNodeInfoControllerQATest extends InitTestEnvironment{
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e1 get a node protection IP that exists.
*
*/
@Test
public void e1_NormalGetOneNodeProtectionIpTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":[\\\"1\\\"]}\"}";
String protectedIp = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class);
deviceCapacityRsp.getItems().forEach(v->{
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 0){
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode()));
}else{
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
}
if(v.getCapacity() != null){
v.getCapacity().forEach(k-> {
Assert.assertNotNull(k.getType());
Assert.assertNotNull(k.getDisposeIp());
});
}
});
}
/**
* e2 get multiple node protection IPs that exists.
*
*/
@Test
public void e2_NormalGetMultipleNodeProtectionIpsTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":[\\\"1\\\", \\\"2\\\"]}\"}";
String protectedIp = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class);
deviceCapacityRsp.getItems().forEach(v->{
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 0){
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode()));
}else{
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
}
if(v.getCapacity() != null){
v.getCapacity().forEach(k-> {
Assert.assertNotNull(k.getType());
Assert.assertNotNull(k.getDisposeIp());
});
}
});
}
/**
* e3 get a node protection IP that does not exist .
*
*/
@Test
public void e3_NormalGetNotExistedNodeProtectionIpTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":[\\\"2\\\"]}\"}";
String protectedIp = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andReturn()
.getResponse()
.getContentAsString();
DeviceCapacityRsp deviceCapacityRsp = objectMapper.readValue(verifyResp(protectedIp), DeviceCapacityRsp.class);
deviceCapacityRsp.getItems().forEach(v->{
Assert.assertNotNull(v.getId());
Assert.assertNotNull(v.getStatus());
Assert.assertNotNull(v.getMessage());
if(v.getStatus() == 0){
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_OK.getCode()));
}else{
Assert.assertEquals(String.valueOf(v.getStatus()), String.valueOf(ErrorCode.ERR_NOSUCHDEVICE.getCode()));
}
if(v.getCapacity() != null){
v.getCapacity().forEach(k-> {
Assert.assertNotNull(k.getType());
Assert.assertNotNull(k.getDisposeIp());
});
}
});
}
/**
* e4 msgContent empty .
*
* @throws Exception the exception
*/
@Test
public void e4_GetIpEmptyMsgExistExceptionTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"\"}";
String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e5 msgContent null .
*
* @throws Exception the exception
*/
@Test
public void e5_GetIpNullMsgExistExceptionTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":null}";
String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e6 id empty .
*
* @throws Exception the exception
*/
@Test
public void e6_GetIpNullMsgExistExceptionTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":null}\"}";
String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e7 id "abd" .
*
* @throws Exception the exception
*/
@Test
public void e7_GetIpErrIdExistExceptionTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":\\\"abd\\\"}\"}";
String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* e8 id Integer .
*
* @throws Exception the exception
*/
@Test
public void e8_GetIpIntegerIdExistExceptionTest() throws Exception{
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604310504," +
"\"msgContent\":\"{\\\"id\\\":1}\"}";
String capacity = mockMvc.perform(MockMvcRequestBuilders
.post("/information/protected_ip")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(521))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus returnStatus = objectMapper.readValue(verifyResp(capacity), ReturnStatus.class);
Assert.assertNotNull(returnStatus.getStatus());
Assert.assertNotNull(returnStatus.getMessage());
Assert.assertEquals(Long.valueOf(returnStatus.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* Verify device id exists boolean.
*