FileDocCategorySizeDatePackage
TestPeopleFinderEJB.javaAPI DocExample4862Thu Dec 15 22:17:08 GMT 2005com.oreilly.jent.people.ejb

TestPeopleFinderEJB

public class TestPeopleFinderEJB extends org.apache.cactus.FilterTestCase
Class: TestPeopleFinderEJB Test cases for the PeopleFinder EJB component.
author
Jim Farley

Fields Summary
private PeopleFinderLocal
mFinderBean
private static Logger
sLog
Constructors Summary
public TestPeopleFinderEJB()


      
        super();
    
public TestPeopleFinderEJB(String name)

        super(name);
    
public TestPeopleFinderEJB(String name, Test child)

        super(name, child);
    
Methods Summary
protected voidsetUp()
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 voidtearDown()
Clean up our EJB instance

        try {
            mFinderBean.remove();
            mFinderBean = null;
        }
        catch (RemoveException re) {
            fail("Removal of EJB in fixture failed: " + re.getMessage());
        }
        
    
public voidtestBadSearchArgument()

        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 voidtestNoSearchArguments()

        // 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());
        }