From dda105599bbe6a8ce8606c2269407e82d6b1a38a Mon Sep 17 00:00:00 2001 From: mengelhardt Date: Sat, 3 Oct 2015 21:11:54 -0400 Subject: [PATCH] Fix the display of pet type when using the JDBC profile Steps to reproduce: Set the web.xml context-param spring.profiles.active to jdbc. Run app and navigate to Find owners > Find Owner > Betty Davis. Notice that poor little Basil the hamster doesn't have his Type displayed. --- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 3 +++ .../samples/petclinic/service/AbstractClinicServiceTests.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 0a471b4d8..5a05b68fa 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -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,8 +115,10 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { params, new JdbcPetVisitExtractor() ); + Collection petTypes = getPetTypes(); for (JdbcPet pet : pets) { owner.addPet(pet); + pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId())); } } diff --git a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 428c285fd..7a902983f 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -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