diff --git a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java index 4e3b0869..24b0f3a0 100644 --- a/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/UserAccountServiceImpl.java @@ -138,7 +138,6 @@ public class UserAccountServiceImpl implements UserAccountService { */ @Override public UserAccount getUserByToken(String token) { - String username = userAccountCacheManager.getUsernameByToken(token); if (username != null && username.length() > 0) { diff --git a/src/test/java/com/dispose/TestSuit/SmokeTest.java b/src/test/java/com/dispose/TestSuit/SmokeTest.java new file mode 100644 index 00000000..aebb212c --- /dev/null +++ b/src/test/java/com/dispose/TestSuit/SmokeTest.java @@ -0,0 +1,16 @@ +package com.dispose.TestSuit; + +import com.dispose.controller.AuthControllerExceptionSmokeTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * The type Smoke test. + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + AuthControllerExceptionSmokeTest.class +}) + +public class SmokeTest { +} diff --git a/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java b/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java index 50f15c91..4792b2a0 100644 --- a/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java +++ b/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java @@ -8,6 +8,7 @@ import com.dispose.pojo.dto.ProtocolRespDTO; import com.dispose.pojo.po.ReturnStatus; import com.dispose.pojo.vo.auth.LoginReq; import com.dispose.pojo.vo.auth.LoginRsp; +import com.dispose.pojo.vo.auth.LogoutRsp; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; @@ -57,7 +58,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a1_normalAuthTest() throws Exception { + public void a1_loginNormalLoginTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + "\"msgContent\":\"{\\\"password\\\"" + ":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + @@ -92,7 +93,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a2_verJsonExceptionTest() throws Exception { + public void a2_loginVerJsonExceptionTest() throws Exception { String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" + "\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -121,7 +122,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a3_verNullExceptionTest() throws Exception { + public void a3_loginVerNullExceptionTest() throws Exception { String reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -150,7 +151,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a4_cryptoJsonExceptionTest() throws Exception { + public void a4_loginCryptoJsonExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -179,7 +180,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a5_cryptoNullExceptionTest() throws Exception { + public void a5_loginCryptoNullExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":null,\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -208,7 +209,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a6_usernameNotExistExceptionTest() throws Exception { + public void a6_loginUsernameNotExistExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"123456\\\"}\"}"; @@ -237,7 +238,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a7_usernameEmptyExceptionTest() throws Exception { + public void a7_loginUsernameEmptyExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":\\\"\\\"}\"}"; @@ -266,7 +267,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a8_usernameNullExceptionTest() throws Exception { + public void a8_loginUsernameNullExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + "\\\"userName\\\":null}\"}"; @@ -295,7 +296,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void a9_passwordEmptyExceptionTest() throws Exception { + public void a9_loginPasswordEmptyExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + "\"msgContent\":\"{\\\"password\\\":\\\"\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -323,7 +324,7 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void b1_passwordNullExceptionTest() throws Exception { + public void b1_loginPasswordNullExceptionTest() throws Exception { String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + "\"msgContent\":\"{\\\"password\\\":null,\\\"userName\\\":\\\"admin\\\"}\"}"; @@ -351,8 +352,9 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { * @throws Exception the exception */ @Test - public void b2_passwordErrorExceptionTest() throws Exception { - String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"{\\\"password\\\":\\\"123456\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; + public void b2_loginPasswordErrorExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604296988," + + "\"msgContent\":\"{\\\"password\\\":\\\"123456\\\",\\\"userName\\\":\\\"admin\\\"}\"}"; String ret = mockMvc.perform(MockMvcRequestBuilders .post("/auth/login") @@ -371,4 +373,122 @@ public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_PASSWORD.getCode())); } + + /** + * C 1 normal logout test. + * + * @throws Exception the exception + */ + @Test + public void c1_logoutNormalLogoutTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + + "\"msgContent\":\"{\\\"userName\\\":\\\"admin\\\"}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/auth/logout") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .content(reqData)) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_OK.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + LogoutRsp rspInfo = objectMapper.readValue(verifyResp(ret), LogoutRsp.class) ; + + Assert.assertNotNull(rspInfo); + Assert.assertNotNull(rspInfo.getUserName()); + Assert.assertNotNull(rspInfo.getMessage()); + Assert.assertNotNull(rspInfo.getStatus()); + + Assert.assertEquals(Long.valueOf(rspInfo.getStatus()), Long.valueOf(ErrorCode.ERR_OK.getCode())); + } + + /** + * C 2 username type exception test. + * + * @throws Exception the exception + */ + @Test + public void c2_logoutUsernameTypeExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + + "\"msgContent\":\"{\\\"userName\\\":1,\\\"admin\\\"}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/auth/logout") + .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(); + + 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 2 username empty exception test. + * + * @throws Exception the exception + */ + @Test + public void c2_logoutUsernameEmptyExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + + "\"msgContent\":\"{\\\"userName\\\":\\\"\\\"}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/auth/logout") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .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 3 username null exception test. + * + * @throws Exception the exception + */ + @Test + public void c3_logoutUsernameNullExceptionTest() throws Exception { + String reqData = "{\"ver\":2,\"cryptoType\":0,\"timeStamp\":1587604300195," + + "\"msgContent\":\"{\\\"userName\\\":null}\"}"; + + String ret = mockMvc.perform(MockMvcRequestBuilders + .post("/auth/logout") + .contentType(MediaType.APPLICATION_JSON) + .header("Authorization", "Bearer " + getLogToken()) + .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())); + } }