diff --git a/config/logback.xml b/config/logback.xml index c88d5d92..29cc3007 100644 --- a/config/logback.xml +++ b/config/logback.xml @@ -6,7 +6,7 @@ - [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c][%t]%m%n + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n @@ -18,7 +18,7 @@ - [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c][%t]%m%n + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n - [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c][%t]%m%n + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n @@ -41,7 +41,7 @@ - [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c][%t]%m%n + [%d{yy-MM-dd HH:mm:ss:SSS}][%-5p][%c{0}][%M\(%L\)][%t]: %m%n diff --git a/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java b/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java new file mode 100644 index 00000000..e9dac582 --- /dev/null +++ b/src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java @@ -0,0 +1,77 @@ +package com.dispose.controller; + +import com.dispose.Global.InitTestEnvironment; +import com.dispose.common.ConstValue; +import com.dispose.common.ErrorCode; +import com.dispose.pojo.dto.ProtocolReqDTO; +import com.dispose.pojo.vo.auth.LoginReq; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import javax.annotation.Resource; + +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@AutoConfigureMockMvc +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Slf4j +public class AuthControllerExceptionSmokeTest extends InitTestEnvironment { + /** + * The Mock mvc. + */ + @Resource + private MockMvc mockMvc; + /** + * The Object mapper. + */ + @Resource + private ObjectMapper objectMapper; + + @Test + public void t1_VerExceptionTest() throws Exception { + String reqData = "{\"ver\":\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":" + + "\"{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + + "\\\"userName\\\":\\\"admin\\\"}\"}"; + + mockMvc.perform(MockMvcRequestBuilders + .post("/auth/login") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqData))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + + reqData = "{\"ver\":null,\"cryptoType\":0,\"timeStamp\":1587604296988,\"msgContent\":\"" + + "{\\\"password\\\":\\\"c3855e6b6bb120450f160ba91134522868f89d36062f2061ebeefd80817e1d58\\\"," + + "\\\"userName\\\":\\\"admin\\\"}\"}"; + + mockMvc.perform(MockMvcRequestBuilders + .post("/auth/login") + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqData))) + .andDo(print()).andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(ErrorCode.ERR_PARAMEXCEPTION.getHttpCode())) + .andReturn() + .getResponse() + .getContentAsString(); + } +}