Package org.springframework.samples.petclinic

Examples of org.springframework.samples.petclinic.Pet


        dataBinder.setDisallowedFields(new String[] {"id"});
    }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@RequestParam("petId") int petId, Model model) {
    Pet pet = this.clinic.loadPet(petId);
    Visit visit = new Visit();
    pet.addVisit(visit);
    model.addAttribute("visit", visit);
    return "visitForm";
  }
View Full Code Here


        dataBinder.setDisallowedFields(new String[] {"id"});
    }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@RequestParam("petId") int petId, Model model) {
    Pet pet = this.clinic.loadPet(petId);
    model.addAttribute("pet", pet);
    return "petForm";
  }
View Full Code Here

    }

    @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@RequestParam("ownerId") int ownerId, Model model) {
    Owner owner = this.clinic.loadOwner(ownerId);
    Pet pet = new Pet();
    owner.addPet(pet);
    model.addAttribute("pet", pet);
    return "petForm";
  }
View Full Code Here

  }

  public void storePet(Pet pet) {
    // Consider returning the persistent object here, for exposing
    // a newly assigned id using any persistence provider...
    Pet merged = this.em.merge(pet);
    this.em.flush();
    pet.setId(merged.getId());
  }
View Full Code Here

    assertEquals(old + "X", o1.getLastName());
  }

  public void testLoadPet() {
    Collection<PetType> types = this.clinic.getPetTypes();
    Pet p7 = this.clinic.loadPet(7);
    assertTrue(p7.getName().startsWith("Samantha"));
    assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), p7.getType().getId());
    assertEquals("Jean", p7.getOwner().getFirstName());
    Pet p6 = this.clinic.loadPet(6);
    assertEquals("George", p6.getName());
    assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), p6.getType().getId());
    assertEquals("Peter", p6.getOwner().getFirstName());
  }
View Full Code Here

  }

  public void testInsertPet() {
    Owner o6 = this.clinic.loadOwner(6);
    int found = o6.getPets().size();
    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinic.getPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new Date());
    o6.addPet(pet);
    assertEquals(found + 1, o6.getPets().size());
    this.clinic.storeOwner(o6);
    // assertTrue(!pet.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
    o6 = this.clinic.loadOwner(6);
View Full Code Here

    o6 = this.clinic.loadOwner(6);
    assertEquals(found + 1, o6.getPets().size());
  }

  public void testUpdatePet() throws Exception {
    Pet p7 = this.clinic.loadPet(7);
    String old = p7.getName();
    p7.setName(old + "X");
    this.clinic.storePet(p7);
    p7 = this.clinic.loadPet(7);
    assertEquals(old + "X", p7.getName());
  }
View Full Code Here

    p7 = this.clinic.loadPet(7);
    assertEquals(old + "X", p7.getName());
  }

  public void testInsertVisit() {
    Pet p7 = this.clinic.loadPet(7);
    int found = p7.getVisits().size();
    Visit visit = new Visit();
    p7.addVisit(visit);
    visit.setDescription("test");
    this.clinic.storePet(p7);
    // assertTrue(!visit.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
    p7 = this.clinic.loadPet(7);
    assertEquals(found + 1, p7.getVisits().size());
  }
View Full Code Here

    dataBinder.setDisallowedFields("id");
  }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("petId") int petId, Model model) {
    Pet pet = this.clinic.loadPet(petId);
    model.addAttribute("pet", pet);
    return "pets/form";
  }
View Full Code Here

    }
  }

  @RequestMapping(method = RequestMethod.DELETE)
  public String deletePet(@PathVariable int petId) {
    Pet pet = this.clinic.loadPet(petId);
    this.clinic.deletePet(petId);
    return "redirect:/owners/" + pet.getOwner().getId();
  }
View Full Code Here

TOP

Related Classes of org.springframework.samples.petclinic.Pet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.