6 Replies Latest reply on Mar 4, 2010 6:43 PM by Rafael Abreu

    Integration tests using TestNG plugin

    Piotr Sobczyk Newbie

      I'm using Seam 2.1.2 and JBossTools and I'm trying to run integration tests on Eclipse TestNG plugin.


      I sucessfully removed all classpath problems and make TestNG engine work but one exception remains so I still can't work with integration tests. On running any test exception appears:




      java.lang.NullPointerException
              at java.lang.String.startsWith(Unknown Source)
              at java.lang.String.startsWith(Unknown Source)
              at org.ajax4jsf.webapp.WebXml.getFacesResourceKey(WebXml.java:189)
              at org.ajax4jsf.webapp.WebXml.getFacesResourceKey(WebXml.java:222)
              at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:139)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:491)
              at pl.sobczyk.mitsubishi.crm.test.orderSelectorControllerTest.test_clientFinalisation(orderSelectorControllerTest.java:28)
      ... Removed 22 stack frames





      I scanned Seam Forums and found 3 topics but with unclear answers or lack of answers:





      It seems that it's quite common problem. Please help me.






        • 1. Re: Integration tests using TestNG plugin
          Paul Keogh Novice

          You will need to provide some more information;


          How did you set up the test project ? did you use seam-gen ?


          What sort of a test is it ? Does it extend SeamTest ?


          (if you did not use seam-gen, I recommend that you set up a dummy project with it and examine carefully how it constructs the xxx-test project hierarchy).

          • 2. Re: Integration tests using TestNG plugin
            Piotr Sobczyk Newbie

            Thanks for reply, Paul. As I said, I'm using JBoss Tools, so It's not seam-gen project, but specific to JBoss Tools. If user uses creator to create component classes, JBossTools autogenerates simple test classes for the component like that:




            public class WelcomeTest extends SeamTest {
            
                 @Test
                 public void test_welcome() throws Exception {
                      new FacesRequest() {
                           @Override
                           protected void updateModelValues() throws Exception {                    
                                //set form input to model attributes
                                setValue("#{welcome.value}", "seam");
                           }
                           @Override
                           protected void invokeApplication() {
                                //call action methods here
                                invokeMethod("#{welcome.welcome}");
                           }
                           @Override
                           protected void renderResponse() {
                                //check model attributes if needed
                                assert getValue("#{welcome.value}").equals("seam");
                           }
                      }.run();
                 }
            }



            In pair with simple test suite:




            <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
            
            <suite name="Welcome Tests" verbose="2" parallel="false">
               <test name="Welcome Test">
                 <classes>
                   <class name="pl.sobczyk.mitsubishi.crm.test.WelcomeTest"/>       
                 </classes>
               </test>     
            </suite>



            No matter if I try to run this generated test cases or my own that I tried to reproduce from the generated, the same error occurs that I pasted above. This is strange, because in chapter 2 of Seam official documentation it is said that tests generated by JBossTools are ready to run out of the box, the same is stated in this documentation: http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/seam/html/testNG.html. The exception that occurs is burried in RichFaces code, and it's a bit too much for a developer to debug RichFaces code just in order to run integration test :(.




            (if you did not use seam-gen, I recommend that you set up a dummy project with it and examine carefully how it constructs the xxx-test project hierarchy)

            I will try. But from what I know, JBossTools generates test cases basing on seam-gen script from Seam distribution, so It will be quite similar.




            • 3. Re: Integration tests using TestNG plugin
              Piotr Sobczyk Newbie

              Did anybody manage to solve this. It seems to be quite fundamental problem (I'm running on default settings after all) and it propagated to Seam 2.2. I still can't run integration tests from JBoss Tools project from default settings :(.

              • 4. Re: Integration tests using TestNG plugin
                Piotr Sobczyk Newbie

                I found something very strange while debugging RichFaces souce code in wchich exception occurs. In method:


                public String getFacesResourceKey(HttpServletRequest request) {
                String resourcePath = request.getRequestURI().substring(
                        request.getContextPath().length());
                return getFacesResourceKey(resourcePath);
                }



                I found out that request.principalName="gavin" and that resourcePath evaluates to: "ocalhost:8080/myproject/page.seam" (it's not a typo, there is not "localhost" but "ocalhost"). Method getFacesResourceKey invoked in last line throws the exception I pasted in first post (there is null object passed to startsWith method).


                Obviously I have no user in my test named gavin and there is no page /mypoject/page.xhtml in my project. It seems like some example test is launching along with mine but I can't find out why and from where.


                Could anybody help me?

                • 5. Re: Integration tests using TestNG plugin
                  Piotr Sobczyk Newbie

                  Allright, I've just managed to adapt a test piece of standard seam-gen build script to JBT project and launched my test - everything went allright.  Exception from RichFaces code didn't occur. My ant target took advantage of JBT test project so it seems that test project generated in JBT is allritght. However the issue seems to be related with JBoss Tools or TestNG Eclipse Plugin.


                  However I really would like to launch my tests from Eclipse. Any one faced this problem and solved it?

                  • 6. Re: Integration tests using TestNG plugin
                    Rafael Abreu Newbie

                    Hello Piotr,


                    I

                    ve the same problem than you described in this post, but i

                    m running my tests under maven. So i think the problem is not in jboss tools or testng eclipse plugin.


                    I dont know what i can do to my testng work :( i tried everything!