At line 64 changed 1 line. |
;;''...we create methods that begin with "test" (all lower case). As long as these methods are public, have a void return type and take no arguments, they will be called by our <junit> task in our Ant build.xml file. Here's some simple tests for testing CRUD. An important thing to remember is that each method (also known as a test), should be autonomous.'' |
;:''...we create methods that begin with "test" (all lower case). As long as these methods are public, have a void return type and take no arguments, they will be called by our <junit> task in our Ant build.xml file. Here's some simple tests for testing CRUD. An important thing to remember is that each method (also known as a test), should be autonomous.'' |
At line 66 changed 1 line. |
Add the following methods to your PersonDaoTest.java file: |
Add the following methods to your PersonManagerTest.java file: |
{{{ |
public void testGetPerson() throws Exception { |
personForm = (PersonForm) mgr.getPerson("1"); |
At line 71 added 48 lines. |
if (log.isDebugEnabled()) { |
log.debug(personForm); |
} |
|
assertTrue(personForm != null); |
assertTrue(personForm.getRoles().size() == 1); |
} |
|
public void testSavePerson() throws Exception { |
personForm = (PersonForm) mgr.getPerson("1"); |
personForm.setFirstName("Joe"); |
|
if (log.isDebugEnabled()) { |
log.debug("saving person with updated firstName: " + personForm); |
} |
|
personForm = (PersonForm) mgr.savePerson(personForm); |
assertTrue(personForm.getFirstName().equals("Joe")); |
} |
|
public void testAddAndRemovePerson() throws Exception { |
personForm = new PersonForm(); |
|
// call populate method in super class to populate test data |
// from a properties file matching this class name |
personForm = (PersonForm) populate(personForm); |
|
personForm = (PersonForm) mgr.savePerson(personForm); |
assertTrue(personForm.getLastName().equals("Raible")); |
|
if (log.isDebugEnabled()) { |
log.debug("removing person..."); |
} |
|
mgr.removePerson(personForm); |
|
try { |
personForm = (PersonForm) mgr.getPerson("1"); |
fail("Expected 'Exception' not thrown"); |
} catch (Exception e) { |
if (log.isDebugEnabled()) { |
log.debug(e); |
} |
|
assertTrue(e != null); |
} |
} |
}}} |