package kr.pe.elex.examples;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import java.util.HashSet;
import java.util.Set;

import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(MyController.class)
@AutoConfigureRestDocs(outputDir = "build/generated-snippets")
public class WebLayerTest {
	@Autowired
	private MockMvc mockMvc;

	@Test
	public void defaultPage() throws Exception {
		this.mockMvc.perform(
				RestDocumentationRequestBuilders.get("/name/{name}", "Charlie"))
				.andExpect(status().isOk())
				.andDo(print())
				.andDo(document("home",
						pathParameters(parameterWithName("name")
								.description("Name...")),
						responseFields(fieldWithPath("name")
										.description("Name..."),
								fieldWithPath("age")
										.description("Age..."))
						));
	}
}
