adding path param example

This commit is contained in:
John Thompson 2019-05-27 17:18:37 -04:00
parent 5dbf86e457
commit 40a65b05f2
No known key found for this signature in database
GPG Key ID: 25C80CE5BD1AF258

View File

@ -22,9 +22,14 @@ import java.util.UUID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
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.request.MockMvcRequestBuilders.*;
@ExtendWith(RestDocumentationExtension.class)
@AutoConfigureRestDocs
@WebMvcTest(BeerController.class)
@ -44,8 +49,11 @@ class BeerControllerTest {
void getBeerById() throws Exception {
given(beerRepository.findById(any())).willReturn(Optional.of(Beer.builder().build()));
mockMvc.perform(get("/api/v1/beer/" + UUID.randomUUID().toString()).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
mockMvc.perform(get("/api/v1/beer/{beerId}", UUID.randomUUID().toString()).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("v1/beer", pathParameters(
parameterWithName("beerId").description("UUID of desired beer to get.")
)));
}
@Test