parent
35fe796e21
commit
23b455441c
|
@ -1,11 +1,15 @@
|
|||
package com.dispose.test.exception;
|
||||
|
||||
import com.dispose.common.ErrorCode;
|
||||
import com.dispose.common.GlobalVar;
|
||||
import com.dispose.pojo.po.ReturnStatus;
|
||||
import com.dispose.test.Global.InitTestEnvironment;
|
||||
import com.dispose.common.ConstValue;
|
||||
import com.dispose.pojo.dto.ProtocolReqDTO;
|
||||
import com.dispose.pojo.vo.auth.LoginReq;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
@ -53,13 +57,6 @@ public class ExceptionTest extends InitTestEnvironment {
|
|||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* User login.
|
||||
*/
|
||||
@Override
|
||||
public void userLogin() {
|
||||
}
|
||||
|
||||
/**
|
||||
* T 1 input exception.
|
||||
*
|
||||
|
@ -78,15 +75,22 @@ public class ExceptionTest extends InitTestEnvironment {
|
|||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(521))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,24 +98,183 @@ public class ExceptionTest extends InitTestEnvironment {
|
|||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test(expected = Exception.class)
|
||||
@Test(expected = Throwable.class)
|
||||
public void t2_globalException() throws Exception {
|
||||
expectedEx.expect(Exception.class);
|
||||
expectedEx.expect(Throwable.class);
|
||||
expectedEx.expectMessage("Expected exception: java.lang.Throwable");
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent("{}");
|
||||
reqInfo.setMsgContent(null);
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/protected_ip")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andDo(print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(521))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/protected_ip")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* T 3 global exception.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test(expected = Throwable.class)
|
||||
public void t3_globalException() throws Exception {
|
||||
expectedEx.expect(Throwable.class);
|
||||
expectedEx.expectMessage("Expected exception: java.lang.Throwable");
|
||||
|
||||
String reqData = "{\"id\":null}";
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(reqData);
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* T 4 global exception.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test(expected = Throwable.class)
|
||||
public void t4_globalException() throws Exception {
|
||||
expectedEx.expect(Throwable.class);
|
||||
expectedEx.expectMessage("Expected exception: java.lang.Throwable");
|
||||
|
||||
String reqData = "{\"id\":1}";
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(reqData);
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/information/version")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
* T 5 input exception.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test(expected = Throwable.class)
|
||||
public void t5_inputException() throws Exception {
|
||||
expectedEx.expect(Throwable.class);
|
||||
expectedEx.expectMessage("Expected exception: java.lang.Throwable");
|
||||
|
||||
LoginReq logReq = null;
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/auth/logout")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* T 6 input exception.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test(expected = Throwable.class)
|
||||
public void t6_inputException() throws Exception {
|
||||
expectedEx.expect(Throwable.class);
|
||||
expectedEx.expectMessage("Expected exception: java.lang.Throwable");
|
||||
|
||||
LoginReq logReq = null;
|
||||
|
||||
ProtocolReqDTO reqInfo = new ProtocolReqDTO();
|
||||
reqInfo.setVer(ConstValue.Protocol.VERSION);
|
||||
reqInfo.setCryptoType(ConstValue.Protocol.CRYPTO_NONE);
|
||||
reqInfo.setTimeStamp(System.currentTimeMillis());
|
||||
reqInfo.setMsgContent(objectMapper.writeValueAsString(logReq));
|
||||
|
||||
String ret = mockMvc.perform(MockMvcRequestBuilders
|
||||
.post("/task/start")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("Authorization", GlobalVar.STRING_HTTP_AUTH_HEAD + getLogToken())
|
||||
.content(objectMapper.writeValueAsString(reqInfo)))
|
||||
.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()));
|
||||
Assert.assertEquals(rspInfo.getMessage(), ErrorCode.ERR_PARAMEXCEPTION.getMsg());
|
||||
}
|
||||
}
|
|
@ -98,6 +98,8 @@ public class UserAccountManagerTest extends InitTestEnvironment {
|
|||
ErrorCode.ERR_LOGOUT);
|
||||
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME(), userToken + "13245"),
|
||||
ErrorCode.ERR_TOKENNOTFOUND);
|
||||
Assert.assertEquals(userAccountCacheManager.verifyUserLogin(getUSER_NAME() + "3213", userToken + "13245"),
|
||||
ErrorCode.ERR_LOGOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue