-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from TeamDMU/test/api-old
[Test] 구버전 API 테스트 작성
- Loading branch information
Showing
11 changed files
with
455 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dmforu-admin/src/test/kotlin/com/dmforu/admin/scheduler/crawling/DietCrawlingServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.dmforu.admin.scheduler.crawling | ||
|
||
import com.dmforu.crawling.parser.DietParser | ||
import com.dmforu.domain.diet.Diet | ||
import com.dmforu.domain.diet.DietWriter | ||
import com.dmforu.domain.schedule.Schedule | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class DietCrawlingServiceTest { | ||
|
||
@Mock | ||
private lateinit var dietParser: DietParser | ||
|
||
@Mock | ||
private lateinit var dietWriter: DietWriter | ||
|
||
@InjectMocks | ||
private lateinit var dietCrawlingService: DietCrawlingService | ||
|
||
@DisplayName("새로운 식단표를 덮어쓴다.") | ||
@Test | ||
fun updateToRecentSchedule() { | ||
// given | ||
val parseResult: List<Diet> = mock() | ||
given(dietParser.parse()).willReturn(parseResult) | ||
|
||
// when | ||
dietCrawlingService.updateToRecentDiet() | ||
|
||
// then | ||
verify(dietParser).parse() | ||
verify(dietWriter).overwrite(any()) | ||
|
||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...-admin/src/test/kotlin/com/dmforu/admin/scheduler/crawling/ScheduleCrawlingServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.dmforu.admin.scheduler.crawling | ||
|
||
import com.dmforu.crawling.parser.ScheduleParser | ||
import com.dmforu.domain.schedule.Schedule | ||
import com.dmforu.domain.schedule.ScheduleWriter | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.mockito.BDDMockito.given | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.any | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class ScheduleCrawlingServiceTest { | ||
|
||
@Mock | ||
private lateinit var scheduleParser: ScheduleParser | ||
|
||
@Mock | ||
private lateinit var scheduleWriter: ScheduleWriter | ||
|
||
@InjectMocks | ||
private lateinit var scheduleCrawlingService: ScheduleCrawlingService | ||
|
||
@DisplayName("새로운 학사 일정을 덮어쓴다.") | ||
@Test | ||
fun updateToRecentSchedule() { | ||
// given | ||
val parseResult: List<Schedule.Year> = mock() | ||
given(scheduleParser.parse(any())).willReturn(parseResult) | ||
|
||
// when | ||
scheduleCrawlingService.updateToRecentSchedule() | ||
|
||
// then | ||
verify(scheduleParser).parse(any()) | ||
verify(scheduleWriter).overwrite(any()) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dmforu-api/src/test/kotlin/com/dmforu/api/OldControllerTestSupport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.dmforu.api | ||
|
||
import com.dmforu.api.controller.old.OldDietController | ||
import com.dmforu.api.controller.old.OldNoticeController | ||
import com.dmforu.api.controller.old.OldScheduleController | ||
import com.dmforu.api.controller.old.OldSubscribeController | ||
import com.dmforu.api.controller.v1.DietController | ||
import com.dmforu.api.controller.v1.NoticeController | ||
import com.dmforu.api.controller.v1.ScheduleController | ||
import com.dmforu.api.controller.v1.SubscribeController | ||
import com.dmforu.domain.diet.DietReader | ||
import com.dmforu.domain.notice.NoticeReader | ||
import com.dmforu.domain.schedule.ScheduleReader | ||
import com.dmforu.domain.subscribe.OldSubscribeUpdater | ||
import com.dmforu.domain.subscribe.SubscribeReader | ||
import com.dmforu.domain.subscribe.SubscribeUpdater | ||
import com.dmforu.domain.subscribe.SubscribeWriter | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.boot.test.mock.mockito.MockBean | ||
import org.springframework.test.web.servlet.MockMvc | ||
|
||
@WebMvcTest(controllers = [OldDietController::class, OldNoticeController::class, OldScheduleController::class, OldSubscribeController::class]) | ||
abstract class OldControllerTestSupport { | ||
|
||
@Autowired | ||
protected lateinit var mockMvc: MockMvc | ||
|
||
@Autowired | ||
protected lateinit var objectMapper: ObjectMapper | ||
|
||
@MockBean | ||
protected lateinit var dietReader: DietReader | ||
|
||
@MockBean | ||
protected lateinit var noticeReader: NoticeReader | ||
|
||
@MockBean | ||
protected lateinit var scheduleReader: ScheduleReader | ||
|
||
@MockBean | ||
protected lateinit var subscribeWriter: SubscribeWriter | ||
|
||
@MockBean | ||
protected lateinit var subscribeUpdater: OldSubscribeUpdater | ||
} |
25 changes: 25 additions & 0 deletions
25
dmforu-api/src/test/kotlin/com/dmforu/api/controller/old/OldDietControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dmforu.api.controller.old | ||
|
||
import com.dmforu.api.OldControllerTestSupport | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.http.MediaType.APPLICATION_JSON | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
class OldDietControllerTest : OldControllerTestSupport() { | ||
|
||
@DisplayName("식단을 불러온다.") | ||
@Test | ||
fun readDiet() { | ||
mockMvc.perform( | ||
get("/api/v1/dmu/cafeteria") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
|
||
} |
150 changes: 150 additions & 0 deletions
150
dmforu-api/src/test/kotlin/com/dmforu/api/controller/old/OldNoticeControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package com.dmforu.api.controller.old | ||
|
||
import com.dmforu.api.OldControllerTestSupport | ||
import com.dmforu.api.support.error.ErrorCode | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.ArgumentMatchers.anyInt | ||
import org.mockito.ArgumentMatchers.anyString | ||
import org.mockito.BDDMockito.given | ||
import org.springframework.http.MediaType.APPLICATION_JSON | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
class OldNoticeControllerTest : OldControllerTestSupport() { | ||
|
||
@DisplayName("대학 공지를 불러온다.") | ||
@Test | ||
fun getUniversityNotice() { | ||
// given | ||
given(noticeReader.readUniversityNotice(anyInt(), anyInt())).willReturn(listOf()) | ||
|
||
// when then | ||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/universityNotice") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
|
||
@DisplayName("학과 공지를 불러온다.") | ||
@Test | ||
fun getDepartmentNotice() { | ||
// given | ||
given(noticeReader.readDepartmentNotice(anyString(), anyInt(), anyInt())).willReturn(listOf()) | ||
|
||
// when then | ||
mockMvc.perform( | ||
get("/api/v1/dmu/departmentNotice/{department}", "컴퓨터소프트웨어공학과") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
|
||
@DisplayName("학과 공지를 불러올 때, 학과는 필수 값이다.") | ||
@Test | ||
fun getDepartmentNoticeWhenDepartmentIsEmpty() { | ||
mockMvc.perform( | ||
get("/api/v1/dmu/departmentNotice/") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.error.code").value(ErrorCode.E404.name)) | ||
.andExpect(jsonPath("$.error.message").value("잘못된 URL로 요청을 하였습니다.")) | ||
.andExpect(jsonPath("$.error.data").isEmpty) | ||
} | ||
|
||
|
||
@DisplayName("공지를 검색한다.") | ||
@Test | ||
fun getNoticeByKeyword() { | ||
// given | ||
given(noticeReader.searchNotice(anyString(), anyString(), anyInt(), anyInt())).willReturn(listOf()) | ||
|
||
// when then | ||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/{searchWord}", "검색어") | ||
.param("department", "컴퓨터소프트웨어공학과") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
|
||
@DisplayName("공지를 검색할 때, 학과는 필수 값이다.") | ||
@Test | ||
fun getNoticeByKeywordWhen() { | ||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/{searchWord}", "검색어") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.error.code").value(ErrorCode.E400.name)) | ||
.andExpect(jsonPath("$.error.message").value("잘못된 요청을 하였습니다.")) | ||
.andExpect(jsonPath("$.error.data").isEmpty) | ||
} | ||
|
||
@DisplayName("공지를 검색할 때, 검색어는 필수 값이다. ") | ||
@Test | ||
fun getNoticeByKeywordWhenPathValueIsEmpty() { | ||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/") | ||
.param("department", "컴퓨터소프트웨어공학과") | ||
.param("page", "1") | ||
.param("size", "20") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isNotFound) | ||
.andExpect(jsonPath("$.error.code").value(ErrorCode.E404.name)) | ||
.andExpect(jsonPath("$.error.message").value("잘못된 URL로 요청을 하였습니다.")) | ||
.andExpect(jsonPath("$.error.data").isEmpty) | ||
} | ||
|
||
@DisplayName("공지를 불러올 때, 페이지네이션 값이 빠져있다면 페이지 1, 사이즈 20으로 자동 설정된다.") | ||
@Test | ||
fun getNoticeWithoutPagination() { | ||
// given | ||
given(noticeReader.readUniversityNotice(anyInt(), anyInt())).willReturn(listOf()) | ||
given(noticeReader.readDepartmentNotice(anyString(), anyInt(), anyInt())).willReturn(listOf()) | ||
given(noticeReader.searchNotice(anyString(), anyString(), anyInt(), anyInt())).willReturn(listOf()) | ||
|
||
// when then | ||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/universityNotice") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
|
||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/departmentNotice") | ||
.param("department", "컴퓨터소프트웨어공학과") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
|
||
mockMvc.perform( | ||
get("/api/v1/dmu/notice/{searchWord}", "검색어") | ||
.param("department", "컴퓨터소프트웨어공학과") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
dmforu-api/src/test/kotlin/com/dmforu/api/controller/old/OldScheduleControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dmforu.api.controller.old | ||
|
||
import com.dmforu.api.OldControllerTestSupport | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.BDDMockito.given | ||
import org.springframework.http.MediaType.APPLICATION_JSON | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
|
||
class OldScheduleControllerTest : OldControllerTestSupport() { | ||
|
||
@DisplayName("학사 일정을 불러온다.") | ||
@Test | ||
fun readSchedule() { | ||
// given | ||
given(scheduleReader.read()).willReturn(listOf()) | ||
|
||
// when // then | ||
mockMvc.perform( | ||
get("/api/v1/dmu/schedule") | ||
.contentType(APPLICATION_JSON) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$").isArray) | ||
} | ||
} |
Oops, something went wrong.