openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Gallimore <>
Subject Functional testing with OpenEJB + Jetty + Selenium
Date Sat, 09 Aug 2008 22:07:25 GMT
Hi All,

I just wondered if I could share an approach I've taken to doing 
functional testing lately and see if anyone has any thoughts on it? If 
people think its good, I'd be happy to write it up properly. If its 
rubbish, or could do with some improvements then that feedback would be 
much appreciated.

Basically I'm looking to achieve the following:
- Complete end to end test of the system including JSPs, Servlets, EJBs 
and DB access
- Isolated from the developers app server installation
- Zero setup (i.e. a check out and build is all that should be necessary 
to run the functional tests)

Obviously OpenEJB is really great for unit testing EJBs and there's 
loads of great examples for this. I figured I could use this in-VM 
facility combined with an embedded Jetty to create a complete deployment 
of my app within the test, and I could then use Selenium to run the 
tests in the browser.

So I have a base class which looks like this:

public abstract class FunctionalTest extends TestCase {
    protected InitialContext ctx;

    protected void setUp() throws Exception {
        Properties properties = new Properties();

        // initialize OpenEJB
        ctx = new InitialContext(properties);

        // bind global JNDI names to local ones, repeat as needed for 
other beans required
        InitialContext context = new InitialContext();
        context.bind("java:comp/env/ejb/Store", new 

        // now we need to add some new products
        new ProductsFixture().addSampleProducts();

        // start a new Jetty server
        selenium = new DefaultSelenium("localhost", 4444, "*iexplore", 

    private void startServer() throws Exception {
        server = new Server(9091);
        WebAppContext webAppContext = new WebAppContext();

        String warPath = "web/src/main/webapp";


    protected void tearDown() throws Exception {

And then I could create a test like this:

public class GetAllProductsTest extends FunctionalTestCase {
    private static final String DUMMY_PRODUCT_NAME = "Sample1";

    public void testShouldShowAllProducts() throws Exception {
        Store store = ctx.lookup("StoreEJBRemote");
        store.addProduct(new Product(DUMMY_PRODUCT_NAME));

        // remote control to a browser


I realise its not a great example, but hopefully it shows what I'm 
trying to do.

I've noticed a few threads on the OpenEJB mailing lists about Jetty support:

I was a bit unclear on what it provides - is it just to provide support 
for Web services?
I think it would be pretty cool if we detect an EAR on the classpath, as 
well as Jetty perhaps we could deploy the web part of the app to an 
embedded Jetty server?

I'd really appreciate any thoughts / feedback on the above.



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message