@Test
 @Transactional
 public void insertVisit() {
   Pet pet7 = this.clinicService.findPetById(7);
   int found = pet7.getVisits().size();
   Visit visit = new Visit();
   pet7.addVisit(visit);
   visit.setDescription("test");
   // both storeVisit and storePet are necessary to cover all ORM tools
   this.clinicService.saveVisit(visit);
   this.clinicService.savePet(pet7);
   pet7 = this.clinicService.findPetById(7);
   assertEquals(found + 1, pet7.getVisits().size());
   assertNotNull("Visit Id should have been generated", visit.getId());
 }
 @Override
 public void save(Visit visit) {
   if (visit.getId() == null) {
     this.em.persist(visit);
   } else {
     this.em.merge(visit);
   }
 }
Пример #3
0
  public void validate(Visit visit, Errors errors) {
    String description = visit.getDescription();

    String vet1 = visit.getVet();
    String vet2 = visit.getVet2();
    // description validation
    if (!StringUtils.hasLength(description)) {
      errors.rejectValue("description", "required", "required");
    }

    Date date = new Date();
    DateTime dt = new DateTime(date);
    // date validation
    if (visit.getDate() == null) {
      errors.rejectValue("date", "required", "required");
    }
    if (visit.getDate().plusDays(1).compareTo(dt) < 0) {
      errors.rejectValue("date", "required", "future date required");
    }
    if (vet2.compareTo(vet1) == 0) {
      errors.rejectValue("vet2", "Must be different", "Must be different");
    }
  }