반응형
package site.metacoding.restdoc;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
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.restdocs.operation.preprocess.Preprocessors;
import org.springframework.test.context.junit.jupiter.SpringExtension;
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;
@ExtendWith({ SpringExtension.class, RestDocumentationExtension.class })
public abstract class AbstractControllerTest {
protected MockMvc mockMvc;
protected RestDocumentationResultHandler document;
@BeforeEach
private void setup(WebApplicationContext webApplicationContext,
RestDocumentationContextProvider restDocumentation) {
this.document = MockMvcRestDocumentation.document("{class-name}/{method-name}",
Preprocessors.preprocessRequest(Preprocessors.prettyPrint()),
Preprocessors.preprocessResponse(Preprocessors.prettyPrint()));
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
.addFilter(new CharacterEncodingFilter(StandardCharsets.UTF_8.name(), true))
.apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation))
// .apply(SecurityMockMvcConfigurers.springSecurity())
.alwaysDo(document)
.build();
}
}
반응형