@Test
 @Transactional
 public void updatePet() throws Exception {
   Pet pet7 = this.clinicService.findPetById(7);
   String old = pet7.getName();
   pet7.setName(old + "X");
   this.clinicService.savePet(pet7);
   pet7 = this.clinicService.findPetById(7);
   assertEquals(old + "X", pet7.getName());
 }
 @Test
 public void findPet() {
   Collection<PetType> types = this.clinicService.findPetTypes();
   Pet pet7 = this.clinicService.findPetById(7);
   assertTrue(pet7.getName().startsWith("Samantha"));
   assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), pet7.getType().getId());
   assertEquals("Jean", pet7.getOwner().getFirstName());
   Pet pet6 = this.clinicService.findPetById(6);
   assertEquals("George", pet6.getName());
   assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), pet6.getType().getId());
   assertEquals("Peter", pet6.getOwner().getFirstName());
 }
Пример #3
0
 /**
  * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Pet}
  * instance.
  */
 private MapSqlParameterSource createPetParameterSource(Pet pet) {
   return new MapSqlParameterSource()
       .addValue("id", pet.getId())
       .addValue("name", pet.getName())
       .addValue("birth_date", pet.getBirthDate().toDate())
       .addValue("type_id", pet.getType().getId())
       .addValue("owner_id", pet.getOwner().getId());
 }
Пример #4
0
 /**
  * Return the Pet with the given name, or null if none found for this Owner.
  *
  * @param name to test
  * @return true if pet name is already in use
  */
 @Nullable
 public Pet getPet(String name, boolean ignoreNew) {
   name = name.toLowerCase();
   for (Pet pet : getPetsInternal()) {
     if (!ignoreNew || !pet.isNew()) {
       String compName = pet.getName();
       if (compName != null && compName.toLowerCase().equals(name)) {
         return pet;
       }
     }
   }
   return null;
 }