Methods Summary |
---|
protected void | setUp()Create an instance of the EJB component under test, to be used by
any of the test methods. Since the PeopleFinder EJB is a stateless
session bean, and therefore keeps no client state, this is a sensible
thing to have in the test fixture.
// Initialize an EJB reference
String beanName = "java:comp/env/ejb/junit-PeopleFinder";
try {
InitialContext ctx = new InitialContext();
PeopleFinderLocalHome home =
(PeopleFinderLocalHome)PortableRemoteObject.narrow(
ctx.lookup(beanName), PeopleFinderLocalHome.class);
this.mFinderBean = home.create();
}
catch (NamingException ne) {
fail("Unable to lookup EJB component using name '" +
beanName + "': " + ne.getMessage());
}
catch (CreateException ce) {
fail("Unable to create PeopleFinder bean: " + ce.getMessage());
}
|
protected void | tearDown()Clean up our EJB instance
try {
mFinderBean.remove();
mFinderBean = null;
}
catch (RemoveException re) {
fail("Removal of EJB in fixture failed: " + re.getMessage());
}
|
public void | testBadSearchArgument()
SearchArg arg = new SearchArg();
// Try to pass in an invalid search argument
arg.setName("invalidArg");
arg.setValue("foobar");
try {
mFinderBean.findPeople(new SearchArg[] {arg});
fail("PeopleFinder allowed an invalid search argument");
}
catch (InvalidSearchException ise) {
sLog.info("PeopleFinder correctly rejected an invalid parameter");
}
catch (PersistenceException pe) {
fail("Unexpected persistence exception: " + pe.getMessage());
}
|
public void | testNoSearchArguments()
// Try to pass in an empty parameter set
try {
mFinderBean.findPeople(new SearchArg[0]);
fail("PeopleFinder allowed an empty search");
}
catch (InvalidSearchException ise) {
sLog.info("PeopleFinder correctly rejected an empty search");
}
catch (PersistenceException pe) {
fail("Unexpected persistence exception: " + pe.getMessage());
}
|