From bfc6df14b0947ec49d13121ea95ce6d9b70755af Mon Sep 17 00:00:00 2001 From: kkanggu Date: Sun, 24 Sep 2023 21:22:03 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=84=B0?= =?UTF-8?q?=EC=A7=80=EB=8D=98=EA=B1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/notice/FunSystemControllerTest.kt | 34 ++------------ .../domain/notice/NoticeControllerTest.kt | 46 ++----------------- src/test/resources/data.sql | 15 ------ src/test/resources/h2-data.sql | 15 ++++++ src/test/resources/schema.sql | 25 ---------- 5 files changed, 23 insertions(+), 112 deletions(-) delete mode 100644 src/test/resources/data.sql delete mode 100644 src/test/resources/schema.sql diff --git a/src/test/kotlin/com/example/daitssuapi/domain/notice/FunSystemControllerTest.kt b/src/test/kotlin/com/example/daitssuapi/domain/notice/FunSystemControllerTest.kt index 49f837a0..c1207b61 100644 --- a/src/test/kotlin/com/example/daitssuapi/domain/notice/FunSystemControllerTest.kt +++ b/src/test/kotlin/com/example/daitssuapi/domain/notice/FunSystemControllerTest.kt @@ -1,41 +1,19 @@ package com.example.daitssuapi.domain.notice -import org.junit.jupiter.api.BeforeEach +import com.example.daitssuapi.utils.ControllerTest import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.security.test.context.support.WithMockUser -import org.springframework.test.context.jdbc.Sql import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath -import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder -import org.springframework.test.web.servlet.setup.MockMvcBuilders -import org.springframework.web.context.WebApplicationContext -import org.springframework.web.filter.CharacterEncodingFilter -@AutoConfigureMockMvc -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +@ControllerTest class FunSystemControllerTest { @Autowired private lateinit var mockMvc: MockMvc - @Autowired - private lateinit var ctx : WebApplicationContext - - @BeforeEach - fun setup() { - mockMvc = MockMvcBuilders.webAppContextSetup(ctx) - .addFilters(CharacterEncodingFilter("UTF-8", true)) - .build() - } - - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("FunSystem 리스트 컨트롤러 로직 확인") fun getAllFunSystem() { @@ -49,10 +27,7 @@ class FunSystemControllerTest { println(result.response.contentAsString) } - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("Funsystem 리스트 카테고리별 검색 확인") fun getSomeFunSystemList() { @@ -72,10 +47,7 @@ class FunSystemControllerTest { } } - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("Funsystem 페이징 확인") fun getFunSystemPage() { mockMvc.get("/funsystem/page/1") @@ -93,4 +65,4 @@ class FunSystemControllerTest { } } } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/example/daitssuapi/domain/notice/NoticeControllerTest.kt b/src/test/kotlin/com/example/daitssuapi/domain/notice/NoticeControllerTest.kt index 1678beac..c8b98ca4 100644 --- a/src/test/kotlin/com/example/daitssuapi/domain/notice/NoticeControllerTest.kt +++ b/src/test/kotlin/com/example/daitssuapi/domain/notice/NoticeControllerTest.kt @@ -1,56 +1,26 @@ package com.example.daitssuapi.domain.notice -import com.example.daitssuapi.domain.notice.model.repository.NoticeRepository -import com.example.daitssuapi.domain.notice.service.NoticeService -import org.junit.jupiter.api.BeforeEach +import com.example.daitssuapi.utils.ControllerTest import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.mockito.Mockito.* import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.security.test.context.support.WithMockUser -import org.springframework.test.context.jdbc.Sql import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath -import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder -import org.springframework.test.web.servlet.setup.MockMvcBuilders -import org.springframework.web.context.WebApplicationContext -import org.springframework.web.filter.CharacterEncodingFilter -@AutoConfigureMockMvc -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) +@ControllerTest class NoticeControllerTest { @Autowired private lateinit var mockMvc: MockMvc - @Autowired - private lateinit var noticeService: NoticeService - - @Autowired - private lateinit var noticeRepository: NoticeRepository - - @Autowired - private lateinit var ctx : WebApplicationContext - - @BeforeEach - fun setup() { - mockMvc = MockMvcBuilders.webAppContextSetup(ctx) - .addFilters(CharacterEncodingFilter("UTF-8", true)) - .build() - } - - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("Notice 리스트 컨트롤러 로직 확인") fun getAllNoticeList() { // Act and Assert - val result = mockMvc.get("/notice/전체") + val result = mockMvc.get("/notice/ALL") .andExpect { status { isOk() } @@ -59,14 +29,11 @@ class NoticeControllerTest { println(result.response.contentAsString) } - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("Notice 리스트 카테고리별 검색 확인") fun getSomeNoticeList() { - mockMvc.get("/notice/구독") + mockMvc.get("/notice/ACADEMICS") .andExpect { status { isOk() } content { @@ -83,10 +50,7 @@ class NoticeControllerTest { } } - @Sql("classpath:schema.sql") - @Sql("classpath:data.sql") @Test - @WithMockUser @DisplayName("Notice 페이징 확인") fun getNoticePage() { mockMvc.get("/notice/page/1") @@ -105,4 +69,4 @@ class NoticeControllerTest { } } } -} \ No newline at end of file +} diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql deleted file mode 100644 index 7edd0d87..00000000 --- a/src/test/resources/data.sql +++ /dev/null @@ -1,15 +0,0 @@ -DELETE FROM notice.notice; -DELETE FROM notice.notice_fs; - -INSERT INTO notice.notice(id, title, department_id, content, category, created_at, updated_at) VALUES - (1,'공지사항1',1,'1번 공지 내용입니다!!','ACADEMICS','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (2,'공지사항2',2,'2번 공지 내용입니다!!','SUBSCRIPTION','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (3,'공지사항3',3,'3번 공지 내용입니다!!','SCHOLARSHIP','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (4,'공지사항4',4,'4번 공지 내용입니다!!','INTERNATIONAL_EXCHANGE','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (5,'공지사항4',5,'5번 공지 내용입니다!!','INTERNATIONAL_EXCHANGE','1000-01-01 00:00:00','1000-01-01 00:00:00'); - -INSERT INTO notice.notice_fs(id, title, content, category,url, created_at, updated_at) VALUES - (1,'공지사항1','1번 공지 내용입니다!!','CERTIFICATION','http://google.com','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (2,'공지사항2','2번 공지 내용입니다!!','SUBSCRIPTION','http://google.com','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (3,'공지사항3','3번 공지 내용입니다!!','CERTIFICATION','http://google.com','1000-01-01 00:00:00','1000-01-01 00:00:00'), - (4,'공지사항4','4번 공지 내용입니다!!','EXPERIENTIAL_ACTIVITIES','http://google.com','1000-01-01 00:00:00','1000-01-01 00:00:00'); \ No newline at end of file diff --git a/src/test/resources/h2-data.sql b/src/test/resources/h2-data.sql index 70b224a3..df878d5f 100644 --- a/src/test/resources/h2-data.sql +++ b/src/test/resources/h2-data.sql @@ -2,6 +2,8 @@ DELETE FROM course.user_course_relation; DELETE FROM course.course; DELETE FROM main.users; DELETE FROM main.department; +DELETE FROM notice.notice; +DELETE FROM notice.notice_fs; INSERT INTO main.department(id, name) VALUES (1, 'computer'), @@ -44,3 +46,16 @@ INSERT INTO course.calendar (id, name, course, type, due_at, is_completed) VALUE (12, '이 날까지 강의 시청', 'eat paper', 'VIDEO', '2023-07-27 23:59:59', false), (13, '강의', 'do it', 'VIDEO', '2023-02-27 23:59:59', false), (14, '강의', 'choco', 'VIDEO', '2023-05-31 23:59:59', false); + +INSERT INTO notice.notice(id, title, department_id, content, category, created_at, updated_at) VALUES + (1, '공지사항1', 1, '1번 공지 내용입니다!!', 'ACADEMICS', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (2, '공지사항2', 2, '2번 공지 내용입니다!!', 'SUBSCRIPTION', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (3, '공지사항3', 3, '3번 공지 내용입니다!!', 'SCHOLARSHIP', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (4, '공지사항4', 4, '4번 공지 내용입니다!!', 'INTERNATIONAL_EXCHANGE', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (5, '공지사항4', 5, '5번 공지 내용입니다!!', 'INTERNATIONAL_EXCHANGE', '1000-01-01 00:00:00', '1000-01-01 00:00:00'); + +INSERT INTO notice.notice_fs(id, title, content, category,url, created_at, updated_at) VALUES + (1, '공지사항1', '1번 공지 내용입니다!!', 'CERTIFICATION', 'http://google.com', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (2, '공지사항2', '2번 공지 내용입니다!!', 'SUBSCRIPTION', 'http://google.com', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (3, '공지사항3', '3번 공지 내용입니다!!', 'CERTIFICATION', 'http://google.com', '1000-01-01 00:00:00', '1000-01-01 00:00:00'), + (4, '공지사항4', '4번 공지 내용입니다!!', 'EXPERIENTIAL_ACTIVITIES', 'http://google.com', '1000-01-01 00:00:00', '1000-01-01 00:00:00'); diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql deleted file mode 100644 index 4b0b08df..00000000 --- a/src/test/resources/schema.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE SCHEMA IF NOT EXISTS notice; - -CREATE TABLE IF NOT EXISTS notice.notice( - id IDENTITY PRIMARY KEY, - title VARCHAR(1024) NOT NULL, - department_id integer NOT NULL, - content VARCHAR(2048) NOT NULL, - category VARCHAR(32) NOT NULL, - image_url VARCHAR(2048) NULL, - file_url VARCHAR(2048) NULL, - created_at TIMESTAMP NULL, - updated_at TIMESTAMP NULL -); - -CREATE TABLE IF NOT EXISTS notice.notice_fs( - id IDENTITY PRIMARY KEY, - title VARCHAR(1024) NOT NULL, - content VARCHAR(2048) NOT NULL, - category VARCHAR(32) NOT NULL, - image_url VARCHAR(2048) NULL, - url VARCHAR(2048) NOT NULL, - created_at TIMESTAMP NULL, - updated_at TIMESTAMP NULL -); -