REM:
1. 增加单元测试用例
This commit is contained in:
HuangXin 2020-05-20 15:53:27 +08:00
parent c6cbc91d59
commit 2f634fc540
1 changed files with 52 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package com.dispose.test.controller;
import com.dispose.common.ErrorCode;
import com.dispose.test.Global.InitTestEnvironment;
import com.dispose.common.ConstValue;
import com.dispose.pojo.dto.ProtocolReqDTO;
@ -54,7 +55,7 @@ public class AuthControllerTest extends InitTestEnvironment {
* @throws Exception the exception
*/
@Test
public void login1() throws Exception {
public void a1_login() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName(getUSER_NAME())
.password(getPASSWORD())
@ -88,7 +89,7 @@ public class AuthControllerTest extends InitTestEnvironment {
* @throws Exception the exception
*/
@Test
public void logout2() throws Exception {
public void a2_logout() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName("admin")
.build();
@ -117,7 +118,7 @@ public class AuthControllerTest extends InitTestEnvironment {
* @throws Exception the exception
*/
@Test
public void logout3() throws Exception {
public void a3_logout() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName("admin2")
.build();
@ -139,4 +140,52 @@ public class AuthControllerTest extends InitTestEnvironment {
.getResponse()
.getContentAsString();
}
@Test
public void a4_logoutBadVersionTest() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName("admin2")
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(1);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/logout")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_VERSION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
}
@Test
public void a5_logoutBadAuthHeadTest() throws Exception {
LoginReq logReq = LoginReq.builder()
.userName("admin2")
.build();
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
reqInfo.setVer(ConstValue.Protocol.VERSION);
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
reqInfo.setTimeStamp(System.currentTimeMillis());
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
mockMvc.perform(MockMvcRequestBuilders
.post("/auth/logout")
.contentType(MediaType.APPLICATION_JSON)
.header("Authorization", "" + getLogToken())
.content(objectMapper.writeValueAsString(reqInfo)))
.andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode()))
.andReturn()
.getResponse()
.getContentAsString();
}
}