mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
Fix #101 display the pet type when using the JDBC profile
This commit is contained in:
parent
cb0504ee97
commit
4bb829cbd1
3 changed files with 6 additions and 1 deletions
|
@ -35,6 +35,7 @@ import org.springframework.samples.petclinic.model.Pet;
|
|||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
|
@ -114,7 +115,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
);
|
||||
Collection<PetType> petTypes = getPetTypes();
|
||||
for (JdbcPet pet : pets) {
|
||||
pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId()));
|
||||
owner.addPet(pet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class PetValidator implements Validator {
|
|||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return Pet.class.equals(clazz);
|
||||
return Pet.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,6 +69,8 @@ public abstract class AbstractClinicServiceTests {
|
|||
Owner owner = this.clinicService.findOwnerById(1);
|
||||
assertThat(owner.getLastName()).startsWith("Franklin");
|
||||
assertThat(owner.getPets().size()).isEqualTo(1);
|
||||
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
||||
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue