From 2c0c60e29293e37bca87734b0fc8e31e3ee28c43 Mon Sep 17 00:00:00 2001 From: HuangXin Date: Tue, 2 Nov 2021 16:55:46 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20REM:=201.=20=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8D=95=E6=B5=8B=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../dev/controller/ErrorControllerTest.java | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/test/java/com/dispose/test/dev/controller/ErrorControllerTest.java diff --git a/.gitignore b/.gitignore index 349ebac4..7a08712c 100644 --- a/.gitignore +++ b/.gitignore @@ -118,3 +118,4 @@ basedir/ /phoenix_ddos_handle.iml /src/main/resources/git.properties /.run/ +/rule.xml diff --git a/src/test/java/com/dispose/test/dev/controller/ErrorControllerTest.java b/src/test/java/com/dispose/test/dev/controller/ErrorControllerTest.java new file mode 100644 index 00000000..ddca9c4e --- /dev/null +++ b/src/test/java/com/dispose/test/dev/controller/ErrorControllerTest.java @@ -0,0 +1,56 @@ +package com.dispose.test.dev.controller; + +import com.dispose.test.dev.Global.InitTestEnvironment; +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.test.annotation.DirtiesContext; +import org.springframework.test.annotation.Rollback; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +/** + * The type Error controller test. + */ +@AutoConfigureMockMvc +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@Transactional +@Rollback +@Slf4j +public class ErrorControllerTest extends InitTestEnvironment { + /** + * The Mock mvc. + */ + @Resource + private MockMvc mockMvc; + + /** + * A 1 not exist controller test. + * + * @throws Exception the exception + */ + @Test + public void a1_notExistControllerTest() throws Exception { + String ret = mockMvc.perform(MockMvcRequestBuilders + .get("/controller/unexists")) + .andExpect(status().isNotFound()) + .andReturn() + .getResponse() + .getContentAsString(); + + log.debug("result: {}", ret); + } +}