3 Replies Latest reply: Mar 14, 2010 1:08 PM by Aslak Knutsen RSS

Using arquillian to test in embedded gfv3

John Ament Master

I'm attempting to run a test case in the embedded glassfish v3 container.  When I execute, I get the following stack:

 

java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.jboss.arquillian.spi.util.DefaultServiceLoader.reload(DefaultServiceLoader.java:206)
        at org.jboss.arquillian.spi.util.DefaultServiceLoader.getProviders(DefaultServiceLoader.java:292)
        at org.jboss.arquillian.impl.DynamicServiceLoader.onlyOne(DynamicServiceLoader.java:48)
        at org.jboss.arquillian.impl.DeployableTestBuilder.build(DeployableTestBuilder.java:58)
        at org.jboss.arquillian.junit.Arquillian.<init>(Arquillian.java:52)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
        at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
        at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
        at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
        at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
        at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:470)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1031)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:888)
Caused by: java.lang.LinkageError: Failed to inject class com.sun.enterprise.v3.server.AppServerStartup from sun.misc.Launcher$AppClassLoader@1f7182c1
        at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:163)
        at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:170)
        at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
        at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
        at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
        at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
        at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:31)
        at junit.framework.JUnit4TestAdapter.<init>(JUnit4TestAdapter.java:24)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:470)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1031)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:888)
Caused by: java.lang.LinkageError: Failed to inject class com.sun.enterprise.v3.server.AppServerStartup from sun.misc.Launcher$AppClassLoader@1f7182c1
        at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:163)
        at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:170)
        at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
        at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
        at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:370)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:310)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:303)
        at com.sun.enterprise.glassfish.bootstrap.ASEmbedded.run(ASEmbedded.java:101)
        at com.sun.enterprise.glassfish.bootstrap.AbstractMain.start(AbstractMain.java:78)
        at org.glassfish.api.embedded.Server.<init>(Server.java:288)
        at org.glassfish.api.embedded.Server.<init>(Server.java:61)
        at org.glassfish.api.embedded.Server$Builder.build(Server.java:158)
        at org.glassfish.api.embedded.Server$Builder.build(Server.java:140)
        at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
        at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
        at org.jboss.arquillian.glassfish.GlassFishEmbeddedContainer.<init>(GlassFishEmbeddedContainer.java:55)
        ... 28 more
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/validation/constraints/Pattern$Flag
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
        at java.lang.Class.getDeclaredMethods(Class.java:1791)
        at sun.reflect.annotation.AnnotationType$1.run(AnnotationType.java:86)
        at sun.reflect.annotation.AnnotationType$1.run(AnnotationType.java:83)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:82)
        at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:66)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:202)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
        at java.lang.reflect.Method.declaredAnnotations(Method.java:693)
        at java.lang.reflect.Method.getAnnotation(Method.java:679)
        at org.jvnet.hk2.config.Dom.invoke(Dom.java:777)
        at org.glassfish.config.support.TranslatedConfigView.invoke(TranslatedConfigView.java:83)
        at $Proxy19.getName(Unknown Source)
        at com.sun.enterprise.v3.server.SystemTasks.getConfigSystemProperties(SystemTasks.java:187)
        at com.sun.enterprise.v3.server.SystemTasks.setSystemPropertiesFromDomainXml(SystemTasks.java:171)
        at com.sun.enterprise.v3.server.SystemTasks.postConstruct(SystemTasks.java:93)
        at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
        at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:370)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:310)
        at com.sun.enterprise.module.bootstrap.Main.launch(Main.java:303)
        at com.sun.enterprise.glassfish.bootstrap.ASEmbedded.run(ASEmbedded.java:101)
        at com.sun.enterprise.glassfish.bootstrap.AbstractMain.start(AbstractMain.java:78)
        at org.glassfish.api.embedded.Server.<init>(Server.java:288)
        at org.glassfish.api.embedded.Server.<init>(Server.java:61)
        at org.glassfish.api.embedded.Server$Builder.build(Server.java:158)
        at org.glassfish.api.embedded.Server$Builder.build(Server.java:140)
        at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
        at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
        at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
        at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
        at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
        at org.jvnet.hk2.component.Habitat.getBy(Habitat.java:600)
        at org.jvnet.hk2.component.Habitat.getByType(Habitat.java:581)
        at org.jboss.arquillian.glassfish.GlassFishEmbeddedContainer.<init>(GlassFishEmbeddedContainer.java:55)
        ... 28 more
        at com.sun.hk2.component.AbstractWombImpl$1.getValue(AbstractWombImpl.java:149)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/validation/constraints/Pattern$Flag
        at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:81)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        ... 46 more

 

 

Now this obviously looks like the same issue as posted a couple weeks back related to running against weld-se with java-ee in the dependency list.  is there a work around, other than forcing your project to build against weld-se rather than java-ee? i'm specifically targeting java-ee for this.

  • 1. Re: Using arquillian to test in embedded gfv3
    Aslak Knutsen Master

    It is the same problem.

     

    The solution is to not use the java-ee lib at all, use the individual projects libs directly instead. Have a look at http://anonsvn.jboss.org/repos/common/arquillian/trunk/examples/junit/pom.xml

     

     

    If you're only going to use the GlassFish Embedded container you can depend on that for the EE libs needed since they are included.

  • 2. Re: Using arquillian to test in embedded gfv3
    John Ament Master

    It seems a little counter intuitive, at least in my opinion.  I"m not sure you can always be reliant on what version of which APIs a container's going to have.

     

    I was able to get it to run at least with the following dependency config:

     

            <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>4.7</version>            <scope>test</scope>        </dependency>        <dependency>            <groupId>org.glassfish.extras</groupId>            <artifactId>glassfish-embedded-all</artifactId>            <version>3.0.1-b02</version>        </dependency>        <dependency>            <groupId>org.jboss.arquillian.container</groupId>            <artifactId>arquillian-glassfish-embedded-30</artifactId>            <version>1.0.0-SNAPSHOT</version>            <scope>test</scope>        </dependency>        <dependency>            <groupId>org.jboss.arquillian</groupId>            <artifactId>arquillian-junit</artifactId>            <version>1.0.0-SNAPSHOT</version>            <scope>test</scope>        </dependency>

     

    as I still ran into an issue just having the ee libraries as a compile scope.

    seems like a weird maven feature that "compile" is on the CP of tests as well.

     

    however, an interesting note, i did try running this against weld se embedded, tests somewhat work, some issues

    reading from a classpath.  it looks like the test.jar deployment never gets deployed on to glassfish though

     

  • 3. Re: Using arquillian to test in embedded gfv3
    Aslak Knutsen Master

    There is no way in maven to just have compile time dependencies. Provided will also be a part of test classpath.