/ * * CREATED ON 2005-4-21 * / package org.appfuse.model;
Import org.apache.commons.lang.builder.equalsbuilder; import org.apache.commons.lang.builder.hashcodebuilder; import org.apache.commons.lang.builder.tostringbuilder;
/ ** * @ hibernate.class table = "person" * / public class person extends baseobject {
Private long id;
Private string dimstname;
PRIVATE STRING LASTNAME;
/ ** * @Return Returns the firstname. * @ Hibernate.property column = "first_name" length = "50" * / public string getfirstname () {return firstname;}
/ ** * @Param firstname * the firstname to set. * / Public void setfirstname (string firstname) {this.firstname = firstname;}
/ ** * @Return Returns the ID. * @ Hibernate.id column = "id" generator-class = "native" unsaved-value = "null" * / public long position () {return id;}
/ ** * @Param ID * The id to set. * / Public void setid (long id) {this.id = id;}
/ ** * @return returns the lastname. * @ Hibernate.property column = "last_name" length = "50" * / public string getlastname () {Return LastName;}
/ ** * @Param lastname * the lastname to set. * / Public void setlastname (string lastname) {this.lastname = lastname;}
/ ** * @see java.lang.object # equals (object) * / public boolean equals (object object) {if (! (Ibject instanceof person)) {return false;} Person rhs = (Person) Object; return new Equalsbuilder () .append (this.firstname, rhs.firstname) .append (this.id, rhs.id) .append (this.lastname, rhs.lastname) .ISEquals ();} / ** * public boilean equals Object Object) {if (! (! ") {Return false;} address rhs = (address) Object;
Return new equalsbuilder (). append (this.postalcode) .append (this.country, rhs.country) .append (this.province, rhs.province). Append (this.city, rhs.city) .isequals ();} * / / ** * @see java.lang.object # hashcode () * / public int 6code () {Return new hashcodebuilder (-1196181247, -123855255 ) .Append (this.id) .append (this.lastname) .tohashcode ();
/ ** * @see java.lang.object # toString () * / public string toString () {Return New TostringBuilder (this) .append ("LastName", this.lastname) .append ("id", this.id ) .Append ("firstname", this.firstname) .toString ();}}
######################################################################################################################################################################################################################################################################################################## ############ package org.appfuse.da;
Import Org.Appfuse.Model.Person; import org.springframework.dao.dataaccessException;
Public Class PersondaOTest Extends BasedaOTestCase {// A basic initialization, destroying the JUnit Test Private Person Person = NULL for the Persondao object;
PRIVATE PERSONDAO DAO = NULL;
Protected void setup () throws exception {super.setup (); DAO = ("Persondao);} //" CTX "object is a reference to Spring ApplicationContext, it is in BaseDaotestCase's // The static code block is initialized. Protected void teardown () throws exception {super.teardown (); DAO = NULL;
/ / -------------------------------------------------------------------------------------------- -------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Person.setLastName ("RAIBLE");
Dao.savePerson (Person); AssertNotnull (Person.GetId ());
Person = DAO.GETPERSON (Person.GetId ()); assertequals (person.getfirstname (), "matt");}
Public void testsavePerson () throws exception {person = DAO.GETPERSON (New long (1)); Person.SetFirstName ("matt");
Person.setLastName ("Last Name Updated");
Dao.savePerson (Person);
IF (log.Indebugeload ()) {log.debug ("Updated Person:" Person);
Assertequals (Person.getLastName (), "Last Name Updated");
Public void testaddremovePerson () throws exception {person = new person (); person.setfirstname ("bill"); Person.SetLastname ("joy");
Dao.savePerson (Person);
Assertequals (Person.GetfirstName (), "Bill"); assertNotnull (Person.GetId ());
IF (log.Indebugeload ()) {log.debug ("remove person ...");}
DAO.RemovePerson (Person.GetId ());
Try {Person = DAO.GETPERSON ("" "(" Person Found In Database ");} catch (dataAccessException dae) {log.debug (" Excection: " dae.getMessage ()); askERTNOTNULL (dae);}}
}