mirror of
https://github.com/robindhole/sfg-restdocs-example.git
synced 2025-09-13 18:22:19 +00:00
adding query param example
This commit is contained in:
@@ -24,8 +24,7 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
|
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
|
||||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
import static org.springframework.restdocs.request.RequestDocumentation.*;
|
||||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
@@ -49,11 +48,17 @@ class BeerControllerTest {
|
|||||||
void getBeerById() throws Exception {
|
void getBeerById() throws Exception {
|
||||||
given(beerRepository.findById(any())).willReturn(Optional.of(Beer.builder().build()));
|
given(beerRepository.findById(any())).willReturn(Optional.of(Beer.builder().build()));
|
||||||
|
|
||||||
mockMvc.perform(get("/api/v1/beer/{beerId}", UUID.randomUUID().toString()).accept(MediaType.APPLICATION_JSON))
|
mockMvc.perform(get("/api/v1/beer/{beerId}", UUID.randomUUID().toString())
|
||||||
|
.param("iscold", "yes")
|
||||||
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andDo(document("v1/beer", pathParameters(
|
.andDo(document("v1/beer",
|
||||||
parameterWithName("beerId").description("UUID of desired beer to get.")
|
pathParameters (
|
||||||
)));
|
parameterWithName("beerId").description("UUID of desired beer to get.")
|
||||||
|
),
|
||||||
|
requestParameters(
|
||||||
|
parameterWithName("iscold").description("Is Beer Cold Query param")
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user