Пример #1
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());
 }
 @Test
 @Transactional
 public void insertPet() {
   Owner owner6 = this.clinicService.findOwnerById(6);
   int found = owner6.getPets().size();
   Pet pet = new Pet();
   pet.setName("bowser");
   Collection<PetType> types = this.clinicService.findPetTypes();
   pet.setType(EntityUtils.getById(types, PetType.class, 2));
   pet.setBirthDate(new DateTime());
   owner6.addPet(pet);
   assertEquals(found + 1, owner6.getPets().size());
   // both storePet and storeOwner are necessary to cover all ORM tools
   this.clinicService.savePet(pet);
   this.clinicService.saveOwner(owner6);
   owner6 = this.clinicService.findOwnerById(6);
   assertEquals(found + 1, owner6.getPets().size());
   assertNotNull("Pet Id should have been generated", pet.getId());
 }