Package org.springframework.samples.petclinic

Examples of org.springframework.samples.petclinic.Pet


  }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("ownerId") int ownerId, Model model) {
    Owner owner = this.clinic.loadOwner(ownerId);
    Pet pet = new Pet();
    owner.addPet(pet);
    model.addAttribute("pet", pet);
    return "pets/form";
  }
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

    this.em.flush();
    visit.setId(merged.getId());
  }

  public void deletePet(int id) throws DataAccessException {
    Pet pet = loadPet(id);
    this.em.remove(pet);
  }
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);
    Visit visit = new Visit();
    pet.addVisit(visit);
    model.addAttribute("visit", visit);
    return "pets/visitForm";
  }
View Full Code Here

  public void storeVisit(Visit visit) {
    sessionFactory.getCurrentSession().merge(visit);
  }

  public void deletePet(int id) throws DataAccessException {
    Pet pet = loadPet(id);
    sessionFactory.getCurrentSession().delete(pet);
  }
View Full Code Here

  @Before
  public void setUp() {
    visitView = new VisitsAtomView();
    PetType dog = new PetType();
    dog.setName("dog");
    Pet bello = new Pet();
    bello.setName("Bello");
    bello.setType(dog);
    Visit belloVisit = new Visit();
    belloVisit.setPet(bello);
    belloVisit.setDate(new Date(2009, 0, 1));
    belloVisit.setDescription("Bello visit");
    Pet wodan = new Pet();
    wodan.setName("Wodan");
    wodan.setType(dog);
    Visit wodanVisit = new Visit();
    wodanVisit.setPet(wodan);
    wodanVisit.setDate(new Date(2009, 0, 2));
    wodanVisit.setDescription("Wodan visit");
    List<Visit> visits = new ArrayList<Visit>();
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

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.