1 2 3 Previous Next 33 Replies Latest reply on Feb 12, 2012 5:46 PM by aslak

    Arquillian + seam 2.2.0

    tagnegilles

      Hi Guys,

       

      first of all thanks for the great job you did. I just want to ask, whether it's possible to use Arquillian with Seam 2.2.0?

        • 1. Re: Arquillian + seam 2.2.0
          allanjun

          That's also my question.

          Thanks.

          • 2. Re: Arquillian + seam 2.2.0
            aslak

            Yes and No..

             

            While Arquillian 'Core' does support it in the sense it could deploy a Seam application to a container, there is nothing in place in Alpha-1 that actually does it.

             

            We're still working on getting the different Packaging styles working correctly, war / ear etc..

             

            In Alpha-1, EJB 3.0 / CDI jars are pretty much the only testable deployments.

             

            How would you like to test Seam 2.2.0?

             

             

             

            We havn't discussed Seam 2.2.0 support in Arquillian yet. Not sure if we're going to put any effort into making it testable or just wait for Seam 3 so you can test your 2.2.0 components in the compatibility layer.

             

            • 3. Re: Arquillian + seam 2.2.0
              allanjun

              Thanks for the replay Aslak.

               

              We'd love to see Arquillian works with Seam 2.2.0 because the project we're working on use java6, therefore can't use SeamTest with TestNG. We end up have to inject all dependencies manually and do mockups for intergration testing which is a pain to write and can't do the level of test we want, such as transaction and conversation related tests.

               

              Just had a look at Seam roadmap, it seems that Seam 3 is the next major release, not sure about the date when it will be available. But it took over 7 months for a rc1 release for 2.2.0. Seam's developing doesn't seem to be very active these days IMO, is everyone moving into CDI?

               

              How long will it take for Arquillian to support Seam 3 once it's out? Hopefully not another 6 months.

               

              I'm not sure if there are any fundamental changes from Seam 2.2 to Seam 3, given that Arquillian will eventually support seam (true?) I would think the earlier the better. I also believe there are more seam users out there than CDI adopters.

              • 4. Re: Arquillian + seam 2.2.0
                aslak

                allanjun wrote:

                 

                Just had a look at Seam roadmap, it seems that Seam 3 is the next major release, not sure about the date when it will be available. But it took over 7 months for a rc1 release for 2.2.0. Seam's developing doesn't seem to be very active these days IMO, is everyone moving into CDI?

                 

                How long will it take for Arquillian to support Seam 3 once it's out? Hopefully not another 6 months.

                 

                I'm not sure if there are any fundamental changes from Seam 2.2 to Seam 3, given that Arquillian will eventually support seam (true?) I would think the earlier the better.

                The Seam dev team has been hard at work with Weld (CDI EE6 ref impl). Seam 3 is in dev as we speak and will use Weld (CDI) as core. Seam 3 is essential a set of CDI components/extensions.

                 

                Arquillian support CDI in Alpha-1, so we support Seam 3 already. 

                 

                In fact, Arquillian is being used as the test framework to test Seam 3 today(http://community.jboss.org/wiki/Seam3JMSModuleTestingwithArquillian), and will be the recommended way to test Seam by the dev team.

                 

                I'll have a look at how much is needed to get Seam 2.2.0 running in Arquillian.

                • 5. Re: Arquillian + seam 2.2.0
                  allanjun
                  Thanks for clarify a few things here. Looking forward to the analysis of getting Seam 2.2.0 running in Arquillian.
                  • 6. Re: Arquillian + seam 2.2.0
                    allanjun

                    Any progress on this?

                    • 7. Re: Arquillian + seam 2.2.0
                      michaelschuetz

                      Hi to all,

                       

                      I have arquillian running for Seam 2.2 on JBossAS5.1 container now. (Should be work just fine for AS4.2* as long there is an appropriate container implementation provided)

                       

                      My usecase is to integration test EJBs, which itselfes have Seam dependencies, going through all layers and get some persistent data.

                      I do use IDEA and can easily run my tests within ide really fast (no maven projects needs to be build) against remote container.

                       

                      Example Code:

                       

                      @RunWith(Arquillian.class)
                      public class MyServiceIntegrationTest {
                      
                          @EJB
                          private MyService myService;
                          
                          @Deployment
                          public static Archive<?> getTestArchive() {
                      
                              // WAR
                              final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                                      .setWebXML("web.xml")
                                      .addResource("components.xml", "WEB-INF/components.xml");
                      
                              // EJB-JAR
                              final JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "test.jar")
                                      .addClasses(
                                              MyServiceIntegrationTest.class,
                                              MyService.class, MyServiceBean.class,
                                              MyServiceDao.class, MyDaoBean.class, My.class,
                                              AbstractEntity.class, SeamUtil.class)
                      
                                      .addResource("seam.properties", "seam.properties")
                                      .addResource("components.properties", "components.properties")
                                      .addResource("ejb-jar.xml", "META-INF/ejb-jar.xml")
                                      .addResource("persistence.xml", "META-INF/persistence.xml");
                      
                              // EAR
                              final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,
                                      "test.ear")
                                      .addModule(ejb)
                                      .addModule(war)
                                      .addModule(ArtifactResolver.resolve("org.jboss.seam:jboss-seam:2.2.0.GA"))
                                      .addLibrary(ArtifactResolver.resolve("org.jboss.el:jboss-el:1.0_02.CR4"));
                      
                              return ear;
                          }
                      
                          @Test
                          public void testIfSeamIsInitialized() {
                              SeamUtil.initializeSeam();
                          }
                      
                          @Test
                          public void testGetAll() {
                              List<My> results = myService.getAll();
                      
                              assertEquals(3, results.size());
                          }
                      
                      }
                      

                       

                      I could push a complete example to arquillian github sandbox, if requested.

                       

                      regards

                      Michael

                      • 8. Re: Arquillian + seam 2.2.0
                        michaelschuetz

                        Hi,

                         

                        You could get this even shorter a bit.

                        // WAR

                        For

                          .addResource("components.xml", "WEB-INF/components.xml");


                        you could write

                         

                          .addWebResource("components.xml");
                         

                        // EJB-JAR

                        For
                          .addResource("ejb-jar.xml", "META-INF/ejb-jar.xml")

                         

                        you could write

                         

                          .addManifestResource("ejb-jar.xml"); 

                         

                        Regards
                        Michael

                        • 9. Re: Arquillian + seam 2.2.0
                          alartin

                          This definitely not what this post means. @EJB annotation can only inject EJB session bean. The question should be equal to: how can test seam component using @In. Seam component can be POJO and EJB, while if it is EJB, it can be treated as EJB test. But how about POJO?

                          • 10. Re: Arquillian + seam 2.2.0
                            martin.ball

                            Michael, thanks for the post, I've just started looking at using Arquillian to test our Seam 2.2 projects and it's useful to know that it is possible. I am curious to know where the class SeamUtil originates, is this your own class that is initialising things or is it in some lib somewhere? I know JSFUnit has a SeamUtil class with isSeamInitialized() to test that it is, but not come across SeamUtil.initializeSeam()?

                             

                            A complete example would be great.

                             

                            Thanks.

                             

                            Martin.

                            • 11. Re: Arquillian + seam 2.2.0
                              dan.j.allen

                              Great job Michael! As I said in the Seam talk at JBoss World, the person who works out how to test Seam 2 apps using Arquillian will get a lot of hits on his/her blog Looks like you are off to the races.

                               

                              In order to inject a POJO, you will need to do one of two things. The easy way is to lookup the Seam component using the static getInstance() method.

                               

                              Component.getInstance("myService")
                              

                               

                              Once Seam is initialized, you can get a handle on any Seam component via its name in this way.

                               

                              The more complete approach would be to support injection into the test case. For this, you would need to add an Arquillian test enricher. You can reference the EJBInjectionEnricher for ideas. It's just a matter of grabbing the field name (or explicit value of @In) and looking up the instance using Component.getInstance().

                              • 12. Re: Arquillian + seam 2.2.0
                                michaelschuetz

                                Hi Dan,

                                thanks a lot.

                                 

                                Hm, the Seam2 Enricher approach really attracts me. So, if I would want to write an enricher for @In, I wonder what's the right place for the code base:

                                - Arquillian Core?

                                - Arquillian Framework?

                                - Seam Core?

                                - my own code base?

                                 

                                And than all containers would need to *implement* this enricher?

                                 

                                 

                                Thanks ans regards

                                Michael

                                • 13. Re: Arquillian + seam 2.2.0
                                  aslak

                                  You can start work on it in  http://github.com/arquillian/arquillian-extensions

                                   

                                  Basically make a Seam 2 extension.

                                   

                                  Implement the SPI org.jboss.arquillian.spi.TestEnricher

                                  - use reflection to find fields / methods that has the @In annotations on the TestCase Object and look them up in the Container context

                                   

                                  Implement the SPI org.jboss.arquillian.spi.AuxiliaryArchiveAppender

                                  - create a ShrinkWrap JavaArchive that package up your TestEnricher extension so that it can be deployed along side the rest of the deployment.

                                   

                                  e.g.

                                  return ShrinkWrap.create(JavaArchive.class, "arquillian-seam-enricher.jar")

                                                              .addClass(SeamInjectionEnricher.class)

                                                              .addServiceProvicder(TestEnricher.class, SeamInjectionEnricher.class)

                                   

                                   

                                  With this all you need is to add the Seam 2 Enricher extension to the Classpath and it will do it's magic.

                                  • 14. Re: Arquillian + seam 2.2.0
                                    blabno

                                    What is the progress in this topic?

                                    Michael, have you created Seam enricher? What version of servlet-api do you use, 2.5 or 3.0?

                                    Anybody successfull of running arquillian against Seam packaged as WAR?

                                    1 2 3 Previous Next