1 Reply Latest reply on May 16, 2012 5:03 PM by robert ritchie

    Migrating Seam2 tests to Arquillian

    Dan Allen Master

      The following question was raised recently by someone who wants to migrate a Seam 2 application to AS 7 and eventually Java EE 6:


      "Is there any guidance for how to migrate a library of SeamTest-based integration tests to Arquillian?"


      The first answer, of course, is that you don't have to. You can still use SeamTest-based tests in AS 7. Of course, we recommend switching to Arquillian in the long run, in which case you'll be interested in reading on.


      There is promising news regarding the question of migration. Work on the technology needed for this migration is currently in progress. We will be working from two ends, Seam 2 and Arquillian. The Seam 2 part mostly involves the input and expertise of our QE team. The Arquillian part is technical.


      As it stands today, a (straightforward)* migration is not feasible because the functionality in SeamTest does not yet have a suitable match in Arquillian. There are two requirements for this match:


      1. An extension that packages the Seam 2 jars and starts Seam 2 in the container
      2. A JSF lifecycle controller inside the test


      Arquillian does have #1, an extension for packaging the Seam 2 jars and starting Seam 2 in the container [1]. That can be used for testing Seam components directly (meaning testing POJO classes and EJBs). Testing outjection is tricky still.


      Arquillian currently does not have #2, an extension which supports the request lifecycle control that most SeamTest cases make use of. Here's an example of the type of test I'm talking about [2].


      We were going to recommend the use of Arquillian + JSFUnit, an integration that has been in place for more than a year. However, we discovered a major deficiency that can only be solved by redesigning JSFUnit. The deficiency is that the JSF request lifecycle execution in JSFUnit isn't the same as the manual control w/ callbacks in SeamTest. It's not a 1-to-1 mapping.


      The good news is that we have a prototype which is very promising [3]. We are currently working out the name, but it's likely going to be called Arquillian Warp. As soon as we get a first preview release of Warp out, QE is going to work on converting the tests in Seam 2.3. If that goes well, a guide will follow based on that experience. That guide will appear on http://arquillian.org/guides/


      It may take a couple of months to get there, but that is where we are headed.


      To end on a positive note, the Arquillian-based tests are going to be significantly more accurate and valuable than tests written with SeamTest. We aren't just changing the platform, we are changing the philosophy to one which is much more sound.


      If you are a Seam 2 user looking to migrate to AS 7 and are holding off for the following reason:


      "It's a non-starter to have our test environment differ from our runtime."


      I hate to break it to you, but SeamTest *always* used a test environment that differed from the runtime. That's why we are so adamant about running Arquillian tests in a *real* container. We want to end the mockery.


      * I say straightforward because there is always a workaround, but the requirements of a migration in my definition is having a straightforward path.


      [1] https://github.com/arquillian/arquillian-extension-seam2

      [2] https://github.com/mareknovotny/Seam_2_3/blob/master/examples/todo/todo-tests/src/test/java/org/jboss/seam/example/todo/test/TodoTest.java

      [3] https://community.jboss.org/message/734599

        • 1. Re: Migrating Seam2 tests to Arquillian
          robert ritchie Newbie



          Thanks so much for your post.  The project I work on is eager to see and try out the guidance that comes from the migration experiment of SeamTest in 2.3 to Arquillian.


          Our biggest issue with upgrading to a new JBoss AS (namely 6.1.0.Final) was that it seemed to require upgrading our hibernate version to the version packaged with the particular AS.  For example, we succesfully migrated to hibernate 3.6.6 (and the compatible envers, search, lucene, and spatial add-ons) and were excited to see that using Seam 2.2.2.Final we were able to run our application in AS 6.  This required "some" code changes in order to do geospatial queries using CustomType (the constructor for CustomType changed between 3.3 and 3.6) as well as a change in how envers determines auditable fields for an entity (the older envers would automatically audit mappedsuperclass fields even if not annotated with @Audited).


          The non-starter aspect/environment mismatch with upgrading to hibernate 3.6 was that in order to successfully bootstrap our SeamTest-based suite we needed to use the jboss-embedded-all.jar and hibernate-all.jar that shipped with Seam 2.2.2 (which still had the old constructor for CustomType and not only conflicted with our code, but with the class files in hibernate-spatial that we upgraded to).  Therefore in order for us to proceed down that avenue we would have to maintain a hibernate 3.3. "flavor" of code for our tests and a 3.6 production codebase (that was our non-starter issue).


          In any event, based on this post [1] it seems it is somewhat trivial to "turn off" the hibernate module that ships with EAP 6 (~AS 7) and run Seam 2.2.X with hibernate 3.3.  As of now we are planning on proceeding with migrating to AS 7 and keeping SeamTest as is for now, but as you point out, ideally all integration tests would be run using Arquillian to run in the real container instance (your guys' tutorial sold me instantly) and it is certainly in our project's long term plan.


          [1] http://docs.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/6/html/Beta_Documentation/Migrate_Seam_22_Archives_to_JBoss_Enterprise_Application_Platform_6.html