REM:
1. 认证和节点管理单测
This commit is contained in:
wangyiyun 2020-06-09 09:55:37 +08:00
parent 941be7d19a
commit 0ede48d647
2 changed files with 405 additions and 0 deletions

View File

@ -279,6 +279,119 @@ public class AuthControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
}
/**
* B 3 password empty exception test.
*
* @throws Exception the exception
*/
@Test
public void b3_loginPasswordEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PASSWORD.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode()));
}
/**
* B 4 msg empty exception test.
*
* @throws Exception the exception
*/
@Test
public void b4_loginMsgEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* B 5 msg null exception test.
*
* @throws Exception the exception
*/
@Test
public void b5_loginMsgNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," +
"\"msgContent\":\"null\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* B 6 username type exception test.
*
* @throws Exception the exception
*/
@Test
public void b6_loginUsernameTypeExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" +
"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," +
"\\\"userName\\\":1}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/login")
.contentType(MediaType.APPLICATION_JSON)
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_USERNOTFOUND.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_USERNOTFOUND.getCode()));
}
/**
* C 1 normal logout test .
*
@ -396,4 +509,62 @@ public class AuthControllerQATest extends InitTestEnvironment {
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMS.getCode()));
}
/**
* C 5 msg empty exception test.
*
* @throws Exception the exception
*/
@Test
public void c5_logoutMsgEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
"\"msgContent\":\"\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/logout")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* C 6 msg null exception test.
*
* @throws Exception the exception
*/
@Test
public void c6_logoutMsgNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," +
"\"msgContent\":\"null\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.post("/auth/logout")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
ReturnStatus rspInfo = objectMapper.readValue(verifyResp(ret), ReturnStatus.class) ;
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
}

View File

@ -276,6 +276,214 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment {
}
/**
* A 10 add device node ver json exception test.
*
* @throws Exception the exception
*/
@Test
public void a10_addDeviceNodeVerJsonExceptionTest() throws Exception {
String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 11 add device node ver null exception test.
*
* @throws Exception the exception
*/
@Test
public void a11_addDeviceNodeVerNullExceptionTest() throws Exception {
String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 12 add device node ver string exception test.
*
* @throws Exception the exception
*/
@Test
public void a12_addDeviceNodeVerStingChaExceptionTest() throws Exception {
String reqData = "{\"ver\":\"a\",\"cryptoType\":0,\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 13 add device node ver string exception test.
*
* @throws Exception the exception
*/
@Test
public void a13_addDeviceNodeVerStingNumExceptionTest() throws Exception {
String reqData = "{\"ver\":\"1\",\"cryptoType\":0,\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_VERSION.getCode()));
}
/**
* A 14 add device node crypto json exception test.
*
* @throws Exception the exception
*/
@Test
public void a14_addDeviceNodeCryptoJsonExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 15 add device node crypto null exception test.
*
* @throws Exception the exception
*/
@Test
public void a15_addDeviceNodeCryptoNullExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* A 16 add device node crypto string exception test.
*
* @throws Exception the exception
*/
@Test
public void a16_addDeviceNodeCryptoStringExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":\"a\",\"timeStamp\":1587628826908," +
"\"msgContent\":\"{\\\"items\\\":[{\\\"areaCode\\\":0,\\\"ipAddr\\\":\\\"10.88.77.15\\\"," +
"\\\"manufacturer\\\":\\\"DPTech\\\",\\\"model\\\":\\\"UMC\\\",\\\"name\\\":\\\"中移杭研实验室清洗设备\\\"," +
"\\\"readme\\\":\\\"实验室测试设备\\\",\\\"type\\\":0,\\\"version\\\":\\\"5.7.13\\\"}]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* B 2 del device node Msg Empty exception test.
*
@ -379,6 +587,32 @@ public class DeviceNodeManagerControllerQATest extends InitTestEnvironment {
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));
}
/**
* B 6 del device node id empty exception test.
*
* @throws Exception the exception
*/
@Test
public void b6_delDeviceNodeIdEmptyExceptionTest() throws Exception {
String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604308040,\"msgContent\":\"{\\\"id\\\":[]}\"}";
String ret = mockMvc.perform(MockMvcRequestBuilders
.put("/manager/device")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
.content(reqData))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
AddNodeRetData rspInfo = objectMapper.readValue(verifyResp(ret), AddNodeRetData.class);
Assert.assertNotNull(rspInfo.getMessage());
Assert.assertNotNull(rspInfo.getStatus());
Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PARAMEXCEPTION.getCode()));