tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Functional testing with OpenEJB + Jetty + Selenium
Date Thu, 21 Aug 2008 01:52:39 GMT

On Aug 20, 2008, at 2:41 PM, Karan Malhi wrote:

> Would be cool if this would turn into an article for infoQ or TSS

Incredibly large thumbs up to that suggestion!

Happy to make introductions.  Ping me offline if you'd like to publish  
it.

-David


> On Wed, Aug 20, 2008 at 5:40 PM, Karan Malhi <karan.malhi@gmail.com>  
> wrote:
>
>> What a beautiful piece of documentation and such a cool idea.  
>> Awesome.
>>
>>
>> On Wed, Aug 20, 2008 at 5:06 PM, Jonathan Gallimore <
>> jonathan.gallimore@gmail.com> wrote:
>>
>>> I've had a go at writing this up here:
>>> http://cwiki.apache.org/confluence/display/OPENEJB/Functional+testing+with+OpenEJB%2C+Jetty+and+Selenium(I

>>>  think it'll sync to the main site automatically after a few  
>>> hours), and
>>> added a really basic sample app too.
>>>
>>> Jon
>>>
>>>
>>>
>>> Karan Malhi wrote:
>>>
>>>> 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
>>
>
>
>
> -- 
> Karan Singh Malhi


Mime
View raw message