1 Reply Latest reply on Aug 17, 2011 9:38 AM by vineet.reynolds

    WELD-001308 on running JUnit4 tests using JSFUnit 2.0.0.Beta1 in Embedded Glassfish 3.1

    vineet.reynolds

      I've written a very trivial example to examine JSFUnit's capabilities in embedded Glassfish 3.1. It is quite similar to the one posted in the Getting Started page for version 2.0.0.Beta1. I've removed quite a few dependencies from the "Getting Started" example, while adding the ones indicated necessary, in the Arquillian documentation.

       

      The project POM looks like the following:

       

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>jsfunit-samples</groupId>
          <artifactId>jsfunit-glassfish-embedded</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <packaging>war</packaging>
          <properties>
              <arquillian.version>1.0.0.Alpha5</arquillian.version>
              <jsfunit.version>2.0.0.Beta1</jsfunit.version>
          </properties>
          <dependencies>
              <dependency>
                  <groupId>org.jboss.arquillian</groupId>
                  <artifactId>arquillian-junit</artifactId>
                  <version>${arquillian.version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.jsfunit</groupId>
                  <artifactId>jsfunit-arquillian</artifactId>
                  <version>${jsfunit.version}</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.8.2</version>
                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>com.sun.faces</groupId>
                  <artifactId>jsf-api</artifactId>
                  <version>2.1.0-b11</version>
                  <scope>provided</scope>
              </dependency>
          </dependencies>
          <build>
              <plugins>
                  <plugin>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>2.3.2</version>
                      <configuration>
                          <target>1.6</target>
                          <source>1.6</source>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
          <repositories>
              <repository>
                  <id>Java.net</id>
                  <url>http://download.java.net/maven/2</url>
              </repository>
              <repository>
                  <id>jboss-public-repository-group</id>
                  <name>JBoss Public Maven Repository Group</name>
                  <url>https://repository.jboss.org/nexus/content/groups/public</url>
                  <layout>default</layout>
                  <releases>
                      <enabled>true</enabled>
                      <updatePolicy>never</updatePolicy>
                  </releases>
                  <snapshots>
                      <enabled>true</enabled>
                      <updatePolicy>never</updatePolicy>
                  </snapshots>
              </repository>
              <repository>
                  <id>repository.jboss.org</id>
                  <url>http://repository.jboss.org/maven2</url>
                  <releases>
                  </releases>
                  <snapshots>
                      <enabled>false</enabled>
                  </snapshots>
              </repository>
          </repositories>
          <profiles>
              <profile>
                  <id>glassfish-embedded-3.1</id>
                  <dependencies>
                      <dependency>
                          <groupId>org.jboss.arquillian.container</groupId>
                          <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                          <version>${arquillian.version}</version>
                          <scope>test</scope>
                      </dependency>
                      <dependency>
                          <groupId>org.glassfish.extras</groupId>
                          <artifactId>glassfish-embedded-all</artifactId>
                          <version>3.1</version>
                          <scope>test</scope>
                      </dependency>
                  </dependencies>
              </profile>
          </profiles>
      </project>
      

      and the test case is quite similar to the Getting Started example:

       

      package info.example;
      
      import java.io.*;
      
      import javax.faces.component.UIComponent;
      
      import junit.framework.Assert;
      
      import org.jboss.arquillian.api.Deployment;
      import org.jboss.arquillian.junit.Arquillian;
      import org.jboss.jsfunit.cdi.InitialPage;
      import org.jboss.jsfunit.jsfsession.*;
      import org.jboss.shrinkwrap.api.ShrinkWrap;
      import org.jboss.shrinkwrap.api.asset.EmptyAsset;
      import org.jboss.shrinkwrap.api.spec.WebArchive;
      import org.junit.Test;
      import org.junit.runner.RunWith;
      
      @RunWith(Arquillian.class)
      public class HelloJSFTest
      {
          @Deployment
          public static WebArchive createDeployment()
          {
              WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                      .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
                      .addPackage(Package.getPackage("info.example"))
                      // my test package
                      .addAsWebResource(new File("src/main/webapp", "Index.xhtml"))
                      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                      .addAsWebInfResource(new File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml");
      
              // System.out.println(war.toString(true)); // for debugging
              return war;
          }
      
          @Test
          @InitialPage("/Index.xhtml")
          public void testInitialPage(JSFServerSession server, JSFClientSession client) throws IOException
          {
              // Test navigation to initial viewID
              Assert.assertEquals("/Index.xhtml", server.getCurrentViewID());
      
              // Set the param and submit
              client.click("login");
      
              // Assert that the login form and constituent components are in the
              // component tree and
              // rendered
              UIComponent loginForm = server.findComponent("LoginForm");
              Assert.assertTrue(loginForm.isRendered());
      
              UIComponent userIdPrompt = server.findComponent("LoginForm:userid");
              Assert.assertTrue(userIdPrompt.isRendered());
      
              UIComponent passwordPrompt = server.findComponent("LoginForm:password");
              Assert.assertTrue(passwordPrompt.isRendered());
      
              UIComponent submitBtn = server.findComponent("LoginForm:submit");
              Assert.assertTrue(submitBtn.isRendered());
          }
      
      }
      

      Running the above example, results in the following exception reported:

       

      -------------------------------------------------------------------------------
      Test set: info.example.HelloJSFTest
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 33.9 sec <<< FAILURE!
      testInitialPage(info.example.HelloJSFTest)  Time elapsed: 1.275 sec  <<< ERROR!
      org.jboss.arquillian.spi.ArquillianProxyException: org.jboss.weld.exceptions.UnsatisfiedResolutionException : WELD-001308 Unable to resolve any beans for Types: [class org.jboss.jsfunit.jsfsession.JSFServerSession]; Bindings: [@javax.enterprise.inject.Default()] [Proxied because : Could not find suitable constructor]
          at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:809)
          at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
          at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.getInstanceByType(CDIInjectionEnricher.java:81)
          at org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.resolve(CDIInjectionEnricher.java:71)
          at org.jboss.arquillian.impl.execution.LocalTestExecuter.enrichArguments(LocalTestExecuter.java:98)
          at org.jboss.arquillian.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:63)
          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.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
          at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)
          at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)
          at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)
          at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:106)
          at org.jboss.arquillian.impl.core.EventImpl.fire(EventImpl.java:67)
          at org.jboss.arquillian.impl.execution.ContainerTestExecuter.execute(ContainerTestExecuter.java:38)
          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.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
          at org.jboss.arquillian.impl.core.EventContextImpl.invokeObservers(EventContextImpl.java:98)
          at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:80)
          at org.jboss.arquillian.impl.TestContextHandler.createTestContext(TestContextHandler.java:82)
          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.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
          at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
          at org.jboss.arquillian.impl.TestContextHandler.createClassContext(TestContextHandler.java:68)
          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.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
          at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
          at org.jboss.arquillian.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:54)
          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.jboss.arquillian.impl.core.ObserverImpl.invoke(ObserverImpl.java:90)
          at org.jboss.arquillian.impl.core.EventContextImpl.proceed(EventContextImpl.java:87)
          at org.jboss.arquillian.impl.core.ManagerImpl.fire(ManagerImpl.java:126)
          at org.jboss.arquillian.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:101)
          at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:251)
          at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:214)
          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)
          at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)
          at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:228)
          at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
          at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
          at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:173)
          at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:303)
          at org.jboss.arquillian.junit.Arquillian.access$300(Arquillian.java:45)
          at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:187)
          at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
          at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:127)
          at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
          at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
          at org.jboss.arquillian.junit.JUnitTestRunner.execute(JUnitTestRunner.java:69)
          at org.jboss.arquillian.protocol.servlet.runner.ServletTestRunner.doGet(ServletTestRunner.java:84)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
          at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
          at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
          at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
          at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
          at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
          at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
          at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
          at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
          at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
          at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
          at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
          at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
          at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
          at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
          at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
          at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
          at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
          at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
          at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
          at java.lang.Thread.run(Thread.java:662)
      

       

       

      which is quite puzzling, as I've noticed that this could occur on containers where CDI is not available. Does anybody here have an idea as to what could be causing this issue?

       

      The complete source code of the application, can be checked out from this Bitbucket repo, in case it is needed as a test case; the value for configurationXml in arquillian.xml needs to be modfiied, as the path is not portable.