-
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.
* refactor: 사용하지 않는 gradle bootJar 설정 제거 * refactor: asciidoctor doFirst docs 삭제 추가 * refactor: 사용하지 않는 restassured 제거 * refactor: @WebMvcTest 합쳐서 컨텍스트 재사용 * refactor: Controller, Document 테스트 추상화 후 분리
- Loading branch information
Showing
9 changed files
with
97 additions
and
139 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
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
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
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
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
35 changes: 0 additions & 35 deletions
35
server/src/test/java/com/fluffy/support/AbstractAcceptanceTest.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
server/src/test/java/com/fluffy/support/AbstractControllerTest.java
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,70 @@ | ||
package com.fluffy.support; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fluffy.auth.api.AuthController; | ||
import com.fluffy.auth.application.AuthService; | ||
import com.fluffy.exam.api.ExamController; | ||
import com.fluffy.exam.application.ExamQueryService; | ||
import com.fluffy.exam.application.ExamService; | ||
import com.fluffy.global.web.Accessor; | ||
import com.fluffy.global.web.AuthArgumentResolver; | ||
import com.fluffy.global.web.cookie.CookieManager; | ||
import com.fluffy.oauth2.api.OAuth2Controller; | ||
import com.fluffy.oauth2.application.OAuth2Service; | ||
import com.fluffy.submission.api.SubmissionController; | ||
import com.fluffy.submission.application.SubmissionQueryService; | ||
import com.fluffy.submission.application.SubmissionService; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
@WebMvcTest({ | ||
AuthController.class, | ||
ExamController.class, | ||
OAuth2Controller.class, | ||
SubmissionController.class, | ||
}) | ||
@ActiveProfiles("test") | ||
public abstract class AbstractControllerTest { | ||
|
||
protected MockMvc mockMvc; | ||
|
||
@Autowired | ||
protected ObjectMapper objectMapper; | ||
|
||
@MockBean | ||
protected AuthArgumentResolver authArgumentResolver; | ||
|
||
@MockBean | ||
protected AuthService authService; | ||
|
||
@MockBean | ||
protected CookieManager cookieManager; | ||
|
||
@MockBean | ||
protected ExamService examService; | ||
|
||
@MockBean | ||
protected ExamQueryService examQueryService; | ||
|
||
@MockBean | ||
protected OAuth2Service oauth2Service; | ||
|
||
@MockBean | ||
protected SubmissionService submissionService; | ||
|
||
@MockBean | ||
protected SubmissionQueryService submissionQueryService; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
when(authArgumentResolver.resolveArgument(any(), any(), any(), any())) | ||
.thenReturn(new Accessor(1L)); | ||
} | ||
} |
54 changes: 22 additions & 32 deletions
54
server/src/test/java/com/fluffy/support/AbstractDocumentTest.java
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 |
---|---|---|
@@ -1,69 +1,59 @@ | ||
package com.fluffy.support; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fluffy.global.web.Accessor; | ||
import com.fluffy.global.web.AuthArgumentResolver; | ||
import com.fluffy.support.AbstractDocumentTest.RestDocsConfig; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.RestDocumentationExtension; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
import org.springframework.web.filter.CharacterEncodingFilter; | ||
|
||
@AutoConfigureRestDocs | ||
@ExtendWith(RestDocumentationExtension.class) | ||
@Import(RestDocsConfig.class) | ||
@ActiveProfiles("test") | ||
public abstract class AbstractDocumentTest { | ||
|
||
protected MockMvc mockMvc; | ||
|
||
protected ObjectMapper objectMapper; | ||
@Import(RestDocsConfig.class) | ||
@ExtendWith(RestDocumentationExtension.class) | ||
public abstract class AbstractDocumentTest extends AbstractControllerTest { | ||
|
||
@Autowired | ||
protected RestDocumentationResultHandler restDocs; | ||
|
||
@MockBean | ||
protected AuthArgumentResolver authArgumentResolver; | ||
|
||
@BeforeEach | ||
public void setUp( | ||
WebApplicationContext context, | ||
RestDocumentationContextProvider provider, | ||
@Autowired ObjectMapper objectMapper | ||
WebApplicationContext webApplicationContext, | ||
RestDocumentationContextProvider restDocumentation | ||
) { | ||
mockMvc = MockMvcBuilders.webAppContextSetup(context) | ||
.apply(documentationConfiguration(provider) | ||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) | ||
.apply(documentationConfiguration(restDocumentation) | ||
.operationPreprocessors() | ||
.withRequestDefaults( | ||
modifyUris() | ||
.scheme("https") | ||
.host("api.fluffy.com") | ||
.removePort() | ||
prettyPrint(), | ||
modifyUris().scheme("https").host("api.fluffy.com").removePort() | ||
) | ||
.withResponseDefaults(prettyPrint()) | ||
) | ||
.alwaysDo(print()) | ||
.alwaysDo(restDocs) | ||
.addFilter(new CharacterEncodingFilter("UTF-8", true)) | ||
.build(); | ||
} | ||
|
||
this.objectMapper = objectMapper; | ||
@TestConfiguration | ||
static class RestDocsConfig { | ||
|
||
when(authArgumentResolver.resolveArgument(any(), any(), any(), any())) | ||
.thenReturn(new Accessor(1L)); | ||
@Bean | ||
public RestDocumentationResultHandler restDocs() { | ||
return MockMvcRestDocumentation.document("{class-name}/{method-name}"); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
server/src/test/java/com/fluffy/support/RestDocsConfig.java
This file was deleted.
Oops, something went wrong.