mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:55:49 +00:00
PR example
This commit is contained in:
parent
923e2b7aa3
commit
5b1464a7b4
3 changed files with 21 additions and 0 deletions
|
@ -23,6 +23,7 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
|
@ -75,4 +76,13 @@ class VetController {
|
|||
return vets;
|
||||
}
|
||||
|
||||
@GetMapping({"/vets/{id}"})
|
||||
public @ResponseBody Vet getById(@PathVariable Integer id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("id is required");
|
||||
}
|
||||
System.out.println("id: " + id);
|
||||
return vetRepository.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,4 +55,7 @@ public interface VetRepository extends Repository<Vet, Integer> {
|
|||
@Cacheable("vets")
|
||||
Page<Vet> findAll(Pageable pageable) throws DataAccessException;
|
||||
|
||||
@Transactional(readOnly = false)
|
||||
Vet findById(Integer id) throws RuntimeException;
|
||||
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ class VetControllerTests {
|
|||
@BeforeEach
|
||||
void setup() {
|
||||
given(this.vets.findAll()).willReturn(Lists.newArrayList(james(), helen()));
|
||||
given(this.vets.findById(1)).willReturn(james());
|
||||
given(this.vets.findAll(any(Pageable.class)))
|
||||
.willReturn(new PageImpl<Vet>(Lists.newArrayList(james(), helen())));
|
||||
|
||||
|
@ -95,4 +96,11 @@ class VetControllerTests {
|
|||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShowResourcesVet() throws Exception {
|
||||
ResultActions actions = mockMvc.perform(get("/vets/1").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
actions.andExpect(jsonPath("$.id").value(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue