From 8dd0abf8508baec4f3c03a6223c4a692bb4b2b11 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Fri, 8 May 2020 11:02:45 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=E6=9B=B4=E8=AF=A5log?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=90=8D=EF=BC=8C=E8=A1=8C=E5=8F=B7=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=92=E7=83=9F=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/logback.xml | 8 +- .../AuthControllerExceptionSmokeTest.java | 77 +++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/dispose/controller/AuthControllerExceptionSmokeTest.java 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(); + } +}