8 Replies Latest reply on Apr 24, 2009 6:55 AM by Stan Silvert

    Unable to execute JSFUnit test with maven2

    Umesh Sehgal Newbie

      Hi,

      While looking around over the web for a good unit testing framework for JSF, I came across JSFUnit test framework and found it cool and useful. I tried with a sample example and was able to sucessfully launch it using browser but now as I was trying to integrate it with maven2 (using the existing example (jboss-jsfunit-examples-hellojsf-jsfunit-1.0.0.GA) available on JBoss repo), I ran in to following exceptions:



      Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.02 sec <<< FAILURE!
      testBasicAuth(org.jboss.jsfunit.jsfsession.hellojsf.BasicAuthenticationTest) Time elapsed: 0 sec <<< ERROR!
      org.apache.cactus.util.ChainedRuntimeException: Missing Cactus property [cactus.contextURL]
      at org.apache.cactus.internal.configuration.BaseConfiguration.getContextURL(BaseConfiguration.java:59)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL_aroundBody0(AbstractWebConfiguration.java:46)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL_aroundBody1$advice(AbstractWebConfiguration.java:306)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL(AbstractWebConfiguration.java)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callRunTest(DefaultHttpClient.java:159)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:80)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:306)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:306)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
      at org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

      testInvalidLogin(org.jboss.jsfunit.jsfsession.hellojsf.BasicAuthenticationTest) Time elapsed: 0 sec <<< ERROR!
      org.apache.cactus.util.ChainedRuntimeException: Missing Cactus property [cactus.contextURL]
      at org.apache.cactus.internal.configuration.BaseConfiguration.getContextURL(BaseConfiguration.java:59)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL_aroundBody0(AbstractWebConfiguration.java:46)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL_aroundBody1$advice(AbstractWebConfiguration.java:306)
      at org.apache.cactus.internal.configuration.AbstractWebConfiguration.getRedirectorURL(AbstractWebConfiguration.java)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callRunTest(DefaultHttpClient.java:159)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:80)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:306)
      at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:306)
      at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
      at org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      at junit.framework.TestCase.run(TestCase.java:118)
      at junit.framework.TestSuite.runTest(TestSuite.java:208)
      at junit.framework.TestSuite.run(TestSuite.java:203)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
      at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

      I had downloaded the JSFUnitTest example provided on jboss site and was trying to first run it up before trying to integrate it with my application.

      Please suggest, what could be wrong?


      Thanks,
      Umesh

        • 1. Re: Unable to execute JSFUnit test with maven2
          Stan Silvert Master

          This page tells about running JSFUnit tests from Maven :
          http://www.jboss.org/community/docs/DOC-10977
          Note that step 6 shows how to set the cactus.contextURL property, which seems to be your problem.

          The JSFUnit project uses Maven and JSFUnit to test itself. So there are lots of examples if you want to check out the JSFUnit SVN.

          There are other ways to run JSFUnit tests with Maven but I have found that the Cargo/Surefire solution works pretty well.

          For more info on the cactus.contextURL property, see the Cactus web site. Particulary this page: http://jakarta.apache.org/cactus/integration/manual/howto_config.html

          Also, if you haven't discovered the main JSFUnit doc page, it's here: http://www.jboss.org/community/docs/DOC-10967

          Regards,

          Stan

          • 2. Re: Unable to execute JSFUnit test with maven2
            Wolfgang Knauf Master

            Hi Umesh,

            as the error message says, you have to add a java argument "-Dcactus.contextURL=http://myhost/mywebapp".

            The info in this document might help (though it applies to eclipse): http://www.jboss.org/community/docs/DOC-13427

            Wolfgang

            • 3. Re: Unable to execute JSFUnit test with maven2
              Umesh Sehgal Newbie

              Hi Stan,

              Can you please confirm the command that we need to execute after performing all the steps listed on http://www.jboss.org/community/docs/DOC-10977 , as I had followed the same steps and executed "mvn install" and landed up in the error I posted about.


              Thanks,
              Umesh

              • 4. Re: Unable to execute JSFUnit test with maven2
                Stan Silvert Master

                mvn install is what you need. If you put any of the configuration under profiles then, of course, you need to activate those profiles.

                If you set the System property under Surfire then you should not see that error. Perhaps you misspelled "cactus.contextURL"?

                You could also try setting the System property in the constructor of the test just to make sure it is there.

                Stan

                • 5. Re: Unable to execute JSFUnit test with maven2
                  Umesh Sehgal Newbie

                  Thanks Stan,

                  I just again looked at pom.xml closely and found that the system property I had was under profile tag but not under build tag, putting it there got rid of the missing cactus property problem, But now Its displaying the connect exception, I wonder if it's not able to launch the container, which it should be as I have cargo configuration inside pom.xml. The stack trace that I'm getting is:

                  Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 8.022 sec <<< FAILURE!
                  testBasicAuth(org.jboss.jsfunit.jsfsession.hellojsf.BasicAuthenticationTest) Time elapsed: 4.006 sec <<< ERROR!
                  java.net.ConnectException: Connection refused: connect
                  at java.net.PlainSocketImpl.socketConnect(Native Method)
                  at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
                  at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
                  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
                  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
                  at java.net.Socket.connect(Socket.java:519)
                  at java.net.Socket.connect(Socket.java:469)
                  at java.net.Socket.(Socket.java:366)
                  at java.net.Socket.(Socket.java:240)
                  at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
                  at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
                  at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
                  at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
                  at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
                  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
                  at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
                  at org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect_aroundBody0(HttpClientConnectionHelper.java:142)
                  at org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect_aroundBody1$advice(HttpClientConnectionHelper.java:306)
                  at org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper.connect(HttpClientConnectionHelper.java)
                  at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.callRunTest(DefaultHttpClient.java:162)
                  at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:80)
                  at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:306)
                  at org.apache.cactus.internal.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
                  at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runWebTest(HttpProtocolHandler.java:159)
                  at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody0(HttpProtocolHandler.java:80)
                  at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest_aroundBody1$advice(HttpProtocolHandler.java:306)
                  at org.apache.cactus.internal.client.connector.http.HttpProtocolHandler.runTest(HttpProtocolHandler.java)
                  at org.apache.cactus.internal.client.ClientTestCaseCaller.runTest(ClientTestCaseCaller.java:144)
                  at org.apache.cactus.internal.AbstractCactusTestCase.runBareClient(AbstractCactusTestCase.java:215)
                  at org.apache.cactus.internal.AbstractCactusTestCase.runBare(AbstractCactusTestCase.java:133)
                  at junit.framework.TestResult$1.protect(TestResult.java:106)
                  at junit.framework.TestResult.runProtected(TestResult.java:124)
                  at junit.framework.TestResult.run(TestResult.java:109)
                  at junit.framework.TestCase.run(TestCase.java:118)
                  at junit.framework.TestSuite.runTest(TestSuite.java:208)
                  at junit.framework.TestSuite.run(TestSuite.java:203)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  at java.lang.reflect.Method.invoke(Method.java:597)
                  at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
                  at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
                  at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
                  at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                  at java.lang.reflect.Method.invoke(Method.java:597)
                  at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
                  at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

                  • 6. Re: Unable to execute JSFUnit test with maven2
                    Stan Silvert Master

                    You should see:

                    [INFO] [surefire:test]
                    [INFO] Tests are skipped.

                    Then later you should see this before your tests execute:
                    [INFO] [cargo:start {execution: start-container}]


                    Make sure you have this so that tests are not executed before the container starts. Surefire should only run during integration-test phase:
                    <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-surefire-plugin</artifactId>
                     <configuration>
                     <skip>true</skip>
                     </configuration>
                    
                     <executions>
                     <execution>
                     <id>surefire-it</id>
                     <phase>integration-test</phase>
                     <goals>
                     <goal>test</goal>
                     </goals>
                     <configuration>
                     <skip>false</skip>
                     <systemProperties>
                     <property>
                     <name>cactus.contextURL</name>
                     <value>http://localhost:8080/${artifactId}</value>
                     </property>
                     </systemProperties>
                     </configuration>
                     </execution>
                     </executions>
                     </plugin>


                    Please let me know if that fixes your problem. It looks like I left that out of the documentation. I do things a little different in the JSFUnit tests because I have so many profiles.

                    Stan

                    • 7. Re: Unable to execute JSFUnit test with maven2
                      Umesh Sehgal Newbie

                      Hi Stan,

                      Using the above configuration worked for me. Now I see as you mentioned,
                      first tests get skipped and then container starts and only after that tests get executed.

                      One more thing to point here that the maven integration doesn't seem to work with tomcat 6.0.18, I had to switch to 6.0.14 before I could see it successful.

                      Thanks for your help,
                      Umesh



                      • 8. Re: Unable to execute JSFUnit test with maven2
                        Stan Silvert Master

                        Hmm. FWIW, I tried Tomcat 6.0.18 and it worked fine.

                        Stan