11 Replies Latest reply on Feb 26, 2010 6:43 AM by Marc Gemis

    Error with super simple weld arquillian test

    Steven Boscarine Apprentice

      Hello,
      I have tried to create a Hello World example using Arquillian Weld.  It worked for awhile and started failing without any changes on my part.  Does anyone have troubleshooting suggestions?  I'm building Arquillian from trunk, so I have the latest version.

       

      Thanks,
      Steven

       

      Here's my error:

       

      java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/component/UIComponent
          at java.lang.ClassLoader.defineClass1(Native Method)
          at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
          at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
          at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
          at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
          at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
          at org.jboss.weld.resources.DefaultResourceLoader.classForName(DefaultResourceLoader.java:46)
          at org.jboss.weld.util.ApiAbstraction.classForName(ApiAbstraction.java:103)
          at org.jboss.weld.jsf.JsfApiAbstraction.<init>(JsfApiAbstraction.java:43)
          at org.jboss.weld.bootstrap.WeldBootstrap.getImplementationServices(WeldBootstrap.java:305)
          at org.jboss.weld.bootstrap.WeldBootstrap.startContainer(WeldBootstrap.java:272)
          at org.jboss.arquillian.weld.WeldSEContainer.deploy(WeldSEContainer.java:99)
          at org.jboss.arquillian.impl.container.ContainerDeployer.deploy(ContainerDeployer.java:46)
          at org.jboss.arquillian.testng.Arquillian.createAndDeployArtifact(Arquillian.java:74)
          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.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:609)
          at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:421)
          at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:158)
          at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:89)
          at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:169)
          at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:106)
          at org.testng.TestRunner.runWorkers(TestRunner.java:759)
          at org.testng.TestRunner.privateRun(TestRunner.java:592)
          at org.testng.TestRunner.run(TestRunner.java:486)
          at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
          at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
          at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
          at org.testng.SuiteRunner.run(SuiteRunner.java:204)
          at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:912)
          at org.testng.TestNG.runSuitesLocally(TestNG.java:876)
          at org.testng.TestNG.run(TestNG.java:784)
          at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:62)
          at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:141)
          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)

       


      Here's my POM:

       

              <dependency>
                  <groupId>org.jboss.arquillian</groupId>
                  <artifactId>arquillian-weld-embedded</artifactId>
                  <version>1.0.0-SNAPSHOT</version>

                  <scope>test</scope>
              </dependency>
              <dependency>
                  <groupId>org.jboss.arquillian</groupId>
                  <artifactId>arquillian-testng</artifactId>
                  <version>1.0.0-SNAPSHOT</version>

                  <scope>test</scope>
              </dependency>

       

      Here's the class:
      package org.bogus;

       

      import javax.inject.Inject;
      import javax.inject.Named;

       

      @Named
      public class SimpleDIExample {
          @Inject
          private SimpleDIExChild child;

       

          public SimpleDIExChild getChild() {
              return child;
          }

       

          public void setChild(SimpleDIExChild child) {
              this.child = child;
          }

       

          @Named
          public static class SimpleDIExChild {
              private String text = "hello world";

       

              public String getText() {
                  return text;
              }
          }
      }

       

       


      Here's the test:

       

       

       

      package org.bogus;

       

      import javax.inject.Inject;

       

      import org.jboss.arquillian.api.Deployment;
      import org.jboss.arquillian.testng.Arquillian;
      import org.jboss.shrinkwrap.api.Archives;
      import org.jboss.shrinkwrap.api.Paths;
      import org.jboss.shrinkwrap.api.spec.JavaArchive;
      import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
      import org.testng.Assert;
      import org.testng.annotations.Test;

       

      public class SimpleDIExampleTest extends Arquillian {
          @Deployment
          public static JavaArchive createDeployment() {
              return Archives.create("test.jar", JavaArchive.class).addClasses(SimpleDIExample.class).addManifestResource(
                      new ByteArrayAsset("<beans/>".getBytes()), Paths.create("beans.xml"));
          }

       

          @Test(enabled = false)
          public void simpleDependencyInjectionTest() {
              SimpleDIExample constructedFromJava = new SimpleDIExample();
              // child should initialize to null if constructed directly with Java
              // constructor;
              Assert.assertNull(constructedFromJava.getChild());
              // make sure your bean was injected.
              Assert.assertNotNull(injectedFromCDI, "Is your CDI integration configured correctly?");
              // when injected, child should be populated.
              Assert.assertNotNull(injectedFromCDI.getChild(), "Was your bean constructed properly in CDI?");
              // this test is redundant.
              Assert.assertEquals(injectedFromCDI.getChild().getText(), "hello world", "");
          }

       

          @Inject
          private SimpleDIExample injectedFromCDI;
      }

       

       

      Just to confirm that I don't have a CDI error, I used the following page in Glassfish to confirm I had wired things correctly:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:h="http://java.sun.com/jsf/html">
         <h:head>
            <title>Java EE 6 Starter Application</title>
         </h:head>
         <h:body>
            <h1>Hello World!</h1>
            <p>My CDI bean says <span style="color: red;">#{simpleDIExample.child.text}</span> using the Unified EL.</p>
         </h:body>
      </html>