12 Replies Latest reply on Sep 5, 2007 8:27 AM by Stan Silvert

    Getting Started Problem

    Stan Silvert Master

      I moved this into its own thread -Stan


      I'm in need of a framework that tests jsf web pages. I've found JSFUnit but it doesn't work.

      Can you help me? Please!

      My Stack Trace

      11:44:40,439 ERROR [[ServletTestRunner]] Servlet.service() for servlet ServletTestRunner threw exception
      java.lang.NoClassDefFoundError: br/com/riskoffice/htmlunit/admin/JSFUnitAreaPageTest : junit/framework/TestCase
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:675)
      at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:655)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:193)
      at org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:131)
      at org.jboss.mx.loading.LoadMgr3.nextTask(LoadMgr3.java:399)
      at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:520)
      at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:408)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
      at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:580)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1345)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:242)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody2(ClassLoaderUtils.java:78)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody3$advice(ClassLoaderUtils.java:264)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader(ClassLoaderUtils.java)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody0(ClassLoaderUtils.java:61)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody1$advice(ClassLoaderUtils.java:264)
      at org.apache.cactus.internal.util.ClassLoaderUtils.loadClass(ClassLoaderUtils.java)

      My java Class

      public class JSFUnitAreaPageTest extends TestCase {

      public static Test suite() {
      return new TestSuite(JSFUnitAreaPageTest.class);
      }

      public void testInitialPage() throws IOException, SAXException {
      // Send an HTTP request for the initial page
      ClientFacade client = new ClientFacade("/login.seam");

      // A ServerFacade gives you access to JSF state
      ServerFacade server = new ServerFacade(client);

      // Test navigation to initial viewID
      assertEquals("/login.xhtml", server.getCurrentViewId());

      // Assert that the prompt component is in the component tree and
      // rendered
      UIComponent prompt = server.findComponent("prompt");
      assertTrue(prompt.isRendered());

      // Test a managed bean
      assertEquals("Stan", server.getManagedBeanValue("#{foo.text}"));
      }
      }

        • 1. Re: Getting Started Problem
          Stan Silvert Master

          Did you package your test class inside the WAR? Also, it is probably better to extend org.apache.cactus.ServletTestCase. If you only extend TestCase then you will not be able to run your tests using the junit command line. I should probably change the getting started guide to show that.

          Did you add the JSFUnitFilter to your web.xml as shown in the Getting Started Guide?

          See the Getting Started Guide here:
          http://labs.jboss.com/jsfunit/gettingstarted.html

          For packaging your WAR, this page from the Cactus web site is also helpful:
          http://jakarta.apache.org/cactus/integration/manual/index.html

          If you want to use Ant to package your WAR for you, then check out the new Ant task we talk about in this thread:
          http://www.jboss.com/index.html?module=bb&op=viewtopic&t=115623

          Regards,

          Stan
          http://www.jsfunit.org

          • 2. Re: Getting Started Problem
            Alexander Blöss Newbie

            Stan it is possible to make a Continuous Integration between this tests or this tests can only be runned with a browser?

            My Web.xml

            <!-- Evitar exceções 'Cannot destroy component' -->
            <session-config>
            <session-timeout>15</session-timeout>
            </session-config>
            <!-- Seam -->

            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>


            <listener-class>com.sun.faces.config.ConfigureListener</listener-class>


            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.web.SeamFilter</filter-class>

            <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>*.seam</url-pattern>
            </filter-mapping>

            <servlet-name>Document Store Servlet</servlet-name>
            <servlet-class>org.jboss.seam.pdf.DocumentStoreServlet</servlet-class>

            <!-- 300 second conversation timeout -->
            <context-param>
            <param-name>org.jboss.seam.core.manager.conversationTimeout</param-name>
            <param-value>300000</param-value>
            </context-param>
            <context-param>
            <param-name>org.jboss.seam.core.init.debug</param-name>
            <param-value>true</param-value>
            </context-param>
            <!-- Seam Remoting -->

            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet-class>

            <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
            </servlet-mapping>
            <context-param>
            <param-name>facelets.DEVELOPMENT</param-name>
            <param-value>true</param-value>
            </context-param>
            <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
            </context-param>
            <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>client</param-value>
            </context-param>

            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>

            <!-- Facelets tag libraries -->
            <context-param>
            <param-name>facelets.LIBRARIES</param-name>
            <param-value>
            /WEB-INF/area.taglib.xml; /WEB-INF/backoffice.taglib.xml; /WEB-INF/products.taglib.xml;
            /WEB-INF/portfolio-xml.taglib.xml; /WEB-INF/reports.taglib.xml;
            /WEB-INF/risk.taglib.xml; /WEB-INF/rosys.taglib.xml; /WEB-INF/rosys-jsf.taglib.xml;
            /WEB-INF/series.taglib.xml; /WEB-INF/smarter.taglib.xml;
            </param-value>
            </context-param>
            <!-- Faces Servlet Mapping -->
            <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.seam</url-pattern>
            </servlet-mapping>
            <!-- Chart Servlets -->

            <servlet-name>Report Bar Chart Servlet</servlet-name>
            <servlet-class>br.com.riskoffice.risk.report.ui.web.BarChartView</servlet-class>

            <servlet-mapping>
            <servlet-name>Report Bar Chart Servlet</servlet-name>
            <url-pattern>/reports/chart/bar/*</url-pattern>
            </servlet-mapping>

            <servlet-name>Report Gap Chart Servlet</servlet-name>
            <servlet-class>br.com.riskoffice.risk.report.ui.web.GapChartView</servlet-class>

            <servlet-mapping>
            <servlet-name>Report Gap Chart Servlet</servlet-name>
            <url-pattern>/reports/chart/gap/*</url-pattern>
            </servlet-mapping>

            <servlet-name>Serie Chart Servlet</servlet-name>
            <servlet-class>br.com.riskoffice.risk.series.ui.web.SerieChartView</servlet-class>

            <servlet-mapping>
            <servlet-name>Serie Chart Servlet</servlet-name>
            <url-pattern>/chart/series/*</url-pattern>
            </servlet-mapping>

            <servlet-name>Curve Chart Servlet</servlet-name>
            <servlet-class>br.com.riskoffice.risk.series.ui.web.CurveChartView</servlet-class>

            <servlet-mapping>
            <servlet-name>Curve Chart Servlet</servlet-name>
            <url-pattern>/chart/curves/*</url-pattern>
            </servlet-mapping>

            <filter-name>Seam Servlet Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamServletFilter</filter-class>

            <filter-mapping>
            <filter-name>Seam Servlet Filter</filter-name>
            <url-pattern>/chart/*</url-pattern>
            </filter-mapping>
            <filter-mapping>
            <filter-name>Seam Servlet Filter</filter-name>
            <url-pattern>/reports/chart/*</url-pattern>
            </filter-mapping>

            <filter-name>JSFUnitFilter</filter-name>
            <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>

            <filter-mapping>
            <filter-name>JSFUnitFilter</filter-name>
            <servlet-name>ServletTestRunner</servlet-name>
            </filter-mapping>
            <filter-mapping>
            <filter-name>JSFUnitFilter</filter-name>
            <servlet-name>ServletRedirector</servlet-name>
            </filter-mapping>

            <servlet-name>ServletRedirector</servlet-name>
            <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>


            <servlet-name>ServletTestRunner</servlet-name>
            <servlet-class>org.apache.cactus.server.runner.ServletTestRunner</servlet-class>

            <servlet-mapping>
            <servlet-name>ServletRedirector</servlet-name>
            <url-pattern>/ServletRedirector</url-pattern>
            </servlet-mapping>
            <servlet-mapping>
            <servlet-name>ServletTestRunner</servlet-name>
            <url-pattern>/ServletTestRunner</url-pattern>
            </servlet-mapping>
            </web-app>

            I've changed my test class:

            public class JSFUnitAreaPageTest extends ServletTestCase {

            public static Test suite() {
            return new TestSuite(JSFUnitAreaPageTest.class);
            }

            public void testInitialPage() throws IOException, SAXException {
            // Send an HTTP request for the initial page
            ClientFacade client = new ClientFacade("/login.seam");

            // A ServerFacade gives you access to JSF state
            ServerFacade server = new ServerFacade(client);

            // Test navigation to initial viewID
            assertEquals("/login.xhtml", server.getCurrentViewId());

            // Assert that the prompt component is in the component tree and
            // rendered
            UIComponent prompt = server.findComponent("prompt");
            assertTrue(prompt.isRendered());

            // Test a managed bean
            assertEquals("Stan", server.getManagedBeanValue("#{foo.text}"));
            }
            }

            • 3. Re: Getting Started Problem
              Alexander Blöss Newbie

              I've tried with this configuration, but it doesn't work.

              • 4. Re: Getting Started Problem
                Stan Silvert Master

                 

                "alex_fei_202" wrote:
                Stan it is possible to make a Continuous Integration between this tests or this tests can only be runned with a browser?



                Yes, you can use continuous integration. In fact, we use JSFUnit to test JSFUnit and we run the tests from the Maven build. You can also use Ant or even just run junit from the command line.

                There are a few things for you to check:
                1) Is your test class packaged with your WAR?
                2) I don't see the JSFUnitFilter in your stack trace. Are you sure that the JSFUnitFilter is called?
                3) If you do run the tests outside of the browser you will need to set the cactus.contextURL property. You can do that in several ways shown here:
                http://jakarta.apache.org/cactus/integration/manual/howto_config.html

                Stan

                • 5. Re: Getting Started Problem
                  Alexander Blöss Newbie

                  Sorry, this is my full stack trace

                  type Exception report

                  message

                  description The server encountered an internal error () that prevented it from fulfilling this request.

                  exception

                  javax.servlet.ServletException: Servlet execution threw an exception
                  org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:88)
                  org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

                  root cause

                  java.lang.NoClassDefFoundError: br/com/riskoffice/htmlunit/admin/JSFUnitAreaPageTest : junit/framework/TestCase
                  java.lang.ClassLoader.defineClass1(Native Method)
                  java.lang.ClassLoader.defineClass(ClassLoader.java:620)
                  java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
                  java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
                  java.net.URLClassLoader.access$100(URLClassLoader.java:56)
                  java.net.URLClassLoader$1.run(URLClassLoader.java:195)
                  java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                  org.jboss.mx.loading.RepositoryClassLoader.findClassLocally(RepositoryClassLoader.java:675)
                  org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:655)
                  java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                  org.jboss.mx.loading.RepositoryClassLoader.loadClassLocally(RepositoryClassLoader.java:193)
                  org.jboss.mx.loading.ClassLoadingTask$ThreadTask.run(ClassLoadingTask.java:131)
                  org.jboss.mx.loading.LoadMgr3.nextTask(LoadMgr3.java:399)
                  org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:520)
                  org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:408)
                  java.lang.ClassLoader.loadClass(ClassLoader.java:299)
                  java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:580)
                  java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1345)
                  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
                  java.lang.Class.forName0(Native Method)
                  java.lang.Class.forName(Class.java:242)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody2(ClassLoaderUtils.java:78)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader_aroundBody3$advice(ClassLoaderUtils.java:264)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClassFromContextClassLoader(ClassLoaderUtils.java)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody0(ClassLoaderUtils.java:61)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClass_aroundBody1$advice(ClassLoaderUtils.java:264)
                  org.apache.cactus.internal.util.ClassLoaderUtils.loadClass(ClassLoaderUtils.java)

                  • 6. Re: Getting Started Problem
                    Stan Silvert Master

                    OK. So it's probably just a classloading problem. What is the URL you are using to hit the browser? I just noticed that the error says it is trying to find "br/com/riskoffice/htmlunit/admin/JSFUnitAreaPageTest". Shouldn't that just be "com/riskoffice/htmlunit/admin/JSFUnitAreaPageTest" Are you adding a "br" in there somewhere?

                    Stan

                    • 7. Re: Getting Started Problem
                      Alexander Blöss Newbie

                      This "br" is part of the package that contains my test class.

                      I hiting my broser with:

                      http://localhost:8080/rosys/ServletTestRunner?suite=br.com.riskoffice.htmlunit.admin.JSFUnitAreaPageTest&xsl=cactus-report.xsl

                      The test class:

                      package br.com.riskoffice.htmlunit.admin;

                      import java.io.IOException;

                      import javax.faces.component.UIComponent;

                      import junit.framework.Test;
                      import junit.framework.TestSuite;

                      import org.apache.cactus.ServletTestCase;
                      import org.jboss.jsfunit.facade.ClientFacade;
                      import org.jboss.jsfunit.facade.ServerFacade;
                      import org.xml.sax.SAXException;

                      /**
                      * @author alexander (Last Modified By: $Author: endo $)
                      *
                      * @version $Id: org.eclipse.jdt.ui.prefs,v 1.1 2006/05/19 21:48:04 endo Exp $
                      */
                      public class JSFUnitAreaPageTest extends ServletTestCase {

                      public static Test suite() {
                      return new TestSuite(JSFUnitAreaPageTest.class);
                      }

                      public void testInitialPage() throws IOException, SAXException {
                      // Send an HTTP request for the initial page
                      ClientFacade client = new ClientFacade("/login.seam");

                      // A ServerFacade gives you access to JSF state
                      ServerFacade server = new ServerFacade(client);

                      // Test navigation to initial viewID
                      assertEquals("/login.xhtml", server.getCurrentViewId());

                      // Assert that the prompt component is in the component tree and
                      // rendered
                      UIComponent prompt = server.findComponent("prompt");
                      assertTrue(prompt.isRendered());

                      // Test a managed bean
                      assertEquals("Stan", server.getManagedBeanValue("#{foo.text}"));
                      }
                      }

                      • 8. Re: Getting Started Problem
                        Stan Silvert Master

                        Please send me the WAR.

                        Stan

                        • 9. Re: Getting Started Problem
                          Alexander Blöss Newbie

                          It works...

                          Now it's happening:

                          type Exception report

                          message

                          description The server encountered an internal error () that prevented it from fulfilling this request.

                          exception

                          java.lang.ClassCastException: junit.framework.TestSuite
                          junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:111)
                          org.apache.cactus.server.runner.ServletTestRunner.run(ServletTestRunner.java:298)
                          org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody0(ServletTestRunner.java:186)
                          org.apache.cactus.server.runner.ServletTestRunner.doGet_aroundBody1$advice(ServletTestRunner.java:224)
                          org.apache.cactus.server.runner.ServletTestRunner.doGet(ServletTestRunner.java)
                          javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
                          javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                          org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:88)
                          org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

                          • 10. Re: Getting Started Problem
                            Stan Silvert Master

                            That's odd. What version of JUnit are you using? You should be bundling JUnit 3.8.1 with your WAR. Don't use JUnit 4.

                            Stan

                            • 11. Re: Getting Started Problem
                              Alexander Blöss Newbie

                              Hi Stan!

                              Can you show me an example how to run tests without browser...

                              Maybe with Cactus or other framework.

                              Regards.

                              Alex

                              • 12. Re: Getting Started Problem
                                Stan Silvert Master

                                Did you get it running from the browser?

                                JSFUnit runs on top of Cactus. So if you look at the instructions for Cactus you can see how to run JSFUnit. The only thing different is that you need to add the JSFUnitFilter to your web.xml.

                                If you want to run from Maven, you can also look at the JSFUnit examples in the JSFUnit build.

                                I'll be adding more documentation in the next few weeks before we try to release a beta.

                                Stan