openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karan Malhi" <karan.ma...@gmail.com>
Subject Re: Functional testing with OpenEJB + Jetty + Selenium
Date Tue, 12 Aug 2008 16:02:28 GMT
This is pretty cool. Would you be able to add this stuff to the wiki?

On Sat, Aug 9, 2008 at 6:07 PM, Jonathan Gallimore <
jonathan.gallimore@gmail.com> wrote:

> 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();
>       properties.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>
>       // 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
> LinkRef("java:openejb/ejb/StoreEJBRemote"));
>
>       // now we need to add some new products
>       new ProductsFixture().addSampleProducts();
>
>       // start a new Jetty server
>       startServer();
>       selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "
> http://localhost:9091/");
>   }
>
>   private void startServer() throws Exception {
>       server = new Server(9091);
>       WebAppContext webAppContext = new WebAppContext();
>
>       String warPath = "web/src/main/webapp";
>       webAppContext.setWar(warPath);
>       webAppContext.setContextPath("/");
>       webAppContext.setClassLoader(cl);
>
>       server.addHandler(webAppContext);
>       server.start();
>   }
>
>   protected void tearDown() throws Exception {
>       server.join();
>       selenium.stop();
>       server.stop();
>   }
> }
>
>
> 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
>       selenium.start();
>       selenium.open("/products.action");
>       selenium.waitForPageToLoad("30000");
>
>       assertTrue(selenium.isTextPresent(DUMMY_PRODUCT_NAME));
>   }
> }
>
> 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:
>
> http://www.nabble.com/Jetty-detection-to14604829.html#a14604829
>
> http://www.nabble.com/Embedding-Jetty-into-OpenEJB3.0-to15286978.html#a15286978
>
> 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.
>
> Cheers
>
> Jon
>
>
>


-- 
Karan Singh Malhi

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