mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:25:49 +00:00
Compare commits
1 commit
9432106118
...
c50c4d4daf
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c50c4d4daf |
5 changed files with 12 additions and 10 deletions
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.format.Formatter;
|
import org.springframework.format.Formatter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ public class PetTypeFormatter implements Formatter<PetType> {
|
||||||
|
|
||||||
private final OwnerRepository owners;
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
public PetTypeFormatter(OwnerRepository owners) {
|
public PetTypeFormatter(OwnerRepository owners) {
|
||||||
this.owners = owners;
|
this.owners = owners;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div th:with="valid=${!#fields.hasErrors(name)}"
|
<div th:with="valid=${!#fields.hasErrors(name)}"
|
||||||
th:class="${'form-group' + (valid ? '' : ' has-error')}"
|
th:class="${'form-group' + (valid ? '' : ' has-error')}"
|
||||||
class="form-group">
|
class="form-group">
|
||||||
<label th:for="${name}" class="col-sm-2 control-label" th:text="${label}">Label</label>
|
<label class="col-sm-2 control-label" th:text="${label}">Label</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<div th:switch="${type}">
|
<div th:switch="${type}">
|
||||||
<input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" />
|
<input th:case="'text'" class="form-control" type="text" th:field="*{__${name}__}" />
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div th:with="valid=${!#fields.hasErrors(name)}"
|
<div th:with="valid=${!#fields.hasErrors(name)}"
|
||||||
th:class="${'form-group' + (valid ? '' : ' has-error')}"
|
th:class="${'form-group' + (valid ? '' : ' has-error')}"
|
||||||
class="form-group">
|
class="form-group">
|
||||||
<label th:for="${name}" class="col-sm-2 control-label" th:text="${label}">Label</label>
|
<label class="col-sm-2 control-label" th:text="${label}">Label</label>
|
||||||
|
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<select th:field="*{__${name}__}">
|
<select th:field="*{__${name}__}">
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledInNativeImage;
|
import org.junit.jupiter.api.condition.DisabledInNativeImage;
|
||||||
|
@ -30,7 +31,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
@ -92,9 +92,9 @@ class OwnerControllerTests {
|
||||||
|
|
||||||
Owner george = george();
|
Owner george = george();
|
||||||
given(this.owners.findByLastNameStartingWith(eq("Franklin"), any(Pageable.class)))
|
given(this.owners.findByLastNameStartingWith(eq("Franklin"), any(Pageable.class)))
|
||||||
.willReturn(new PageImpl<>(List.of(george)));
|
.willReturn(new PageImpl<>(Lists.newArrayList(george)));
|
||||||
|
|
||||||
given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<>(List.of(george)));
|
given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<>(Lists.newArrayList(george)));
|
||||||
|
|
||||||
given(this.owners.findById(TEST_OWNER_ID)).willReturn(Optional.of(george));
|
given(this.owners.findById(TEST_OWNER_ID)).willReturn(Optional.of(george));
|
||||||
Visit visit = new Visit();
|
Visit visit = new Visit();
|
||||||
|
@ -143,14 +143,14 @@ class OwnerControllerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testProcessFindFormSuccess() throws Exception {
|
void testProcessFindFormSuccess() throws Exception {
|
||||||
Page<Owner> tasks = new PageImpl<>(List.of(george(), new Owner()));
|
Page<Owner> tasks = new PageImpl<>(Lists.newArrayList(george(), new Owner()));
|
||||||
when(this.owners.findByLastNameStartingWith(anyString(), any(Pageable.class))).thenReturn(tasks);
|
when(this.owners.findByLastNameStartingWith(anyString(), any(Pageable.class))).thenReturn(tasks);
|
||||||
mockMvc.perform(get("/owners?page=1")).andExpect(status().isOk()).andExpect(view().name("owners/ownersList"));
|
mockMvc.perform(get("/owners?page=1")).andExpect(status().isOk()).andExpect(view().name("owners/ownersList"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testProcessFindFormByLastName() throws Exception {
|
void testProcessFindFormByLastName() throws Exception {
|
||||||
Page<Owner> tasks = new PageImpl<>(List.of(george()));
|
Page<Owner> tasks = new PageImpl<>(Lists.newArrayList(george()));
|
||||||
when(this.owners.findByLastNameStartingWith(eq("Franklin"), any(Pageable.class))).thenReturn(tasks);
|
when(this.owners.findByLastNameStartingWith(eq("Franklin"), any(Pageable.class))).thenReturn(tasks);
|
||||||
mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin"))
|
mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin"))
|
||||||
.andExpect(status().is3xxRedirection())
|
.andExpect(status().is3xxRedirection())
|
||||||
|
@ -159,7 +159,7 @@ class OwnerControllerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testProcessFindFormNoOwnersFound() throws Exception {
|
void testProcessFindFormNoOwnersFound() throws Exception {
|
||||||
Page<Owner> tasks = new PageImpl<>(List.of());
|
Page<Owner> tasks = new PageImpl<>(Lists.newArrayList());
|
||||||
when(this.owners.findByLastNameStartingWith(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks);
|
when(this.owners.findByLastNameStartingWith(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks);
|
||||||
mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname"))
|
mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -29,7 +30,6 @@ import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -66,7 +66,7 @@ class PetControllerTests {
|
||||||
PetType cat = new PetType();
|
PetType cat = new PetType();
|
||||||
cat.setId(3);
|
cat.setId(3);
|
||||||
cat.setName("hamster");
|
cat.setName("hamster");
|
||||||
given(this.owners.findPetTypes()).willReturn(List.of(cat));
|
given(this.owners.findPetTypes()).willReturn(Lists.newArrayList(cat));
|
||||||
|
|
||||||
Owner owner = new Owner();
|
Owner owner = new Owner();
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
|
|
Loading…
Reference in a new issue