Skip to content

Commit

Permalink
test: 테스트 터지던거 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kkanggu committed Sep 24, 2023
1 parent 4634310 commit bfc6df1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 112 deletions.
Original file line number Diff line number Diff line change
@@ -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<DefaultMockMvcBuilder>(CharacterEncodingFilter("UTF-8", true))
.build()
}

@Sql("classpath:schema.sql")
@Sql("classpath:data.sql")
@Test
@WithMockUser
@DisplayName("FunSystem 리스트 컨트롤러 로직 확인")
fun getAllFunSystem() {

Expand All @@ -49,10 +27,7 @@ class FunSystemControllerTest {
println(result.response.contentAsString)
}

@Sql("classpath:schema.sql")
@Sql("classpath:data.sql")
@Test
@WithMockUser
@DisplayName("Funsystem 리스트 카테고리별 검색 확인")
fun getSomeFunSystemList() {

Expand All @@ -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")
Expand All @@ -93,4 +65,4 @@ class FunSystemControllerTest {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<DefaultMockMvcBuilder>(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() }

Expand All @@ -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 {
Expand All @@ -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")
Expand All @@ -105,4 +69,4 @@ class NoticeControllerTest {
}
}
}
}
}
15 changes: 0 additions & 15 deletions src/test/resources/data.sql

This file was deleted.

15 changes: 15 additions & 0 deletions src/test/resources/h2-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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');
25 changes: 0 additions & 25 deletions src/test/resources/schema.sql

This file was deleted.

0 comments on commit bfc6df1

Please sign in to comment.