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.
This commit is contained in:
mengelhardt 2015-10-03 21:11:54 -04:00
parent e0be3a39b6
commit dda105599b
2 changed files with 5 additions and 0 deletions

View file

@ -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<PetType> petTypes = getPetTypes();
for (JdbcPet pet : pets) {
owner.addPet(pet);
pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId()));
}
}

View file

@ -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