users@jersey.java.net

Re: [Jersey] A blog entry on using the Jersey Test Framework

From: J Irving <j_at_lollyshouse.net>
Date: Fri, 17 Apr 2009 16:50:00 -0400

This appears to have been a problem with the j2ee API jar file I was
using to build against. I dumped it and included only the
persistence-api component, and the error disappeared. Now however, I
have another issue - a MethodNotFound (although the method appears to
be right there in the grizzly-http-1.9.8.jar file).

I'm including the trace below in case anyone has a solution.

   cheers, J

-----------------8<-----------------
java.lang.NoSuchMethodError:
com.sun.grizzly.http.embed.GrizzlyWebServer.addGrizzlyAdapter(Lcom/sun/grizzly/tcp/http11/GrizzlyAdapter;[Ljava/lang/String;)V
    at com.sun.jersey.test.framework.impl.container.grizzly.web.GrizzlyWebContainer.start(GrizzlyWebContainer.java:134)
    at com.sun.jersey.test.framework.impl.JerseyAppContainer.startServer(JerseyAppContainer.java:170)
    at com.sun.jersey.test.framework.JerseyTest.setupTestEnvironment(JerseyTest.java:254)
    at com.sun.cloud.downloads.resource.RegistrationTest.<init>(RegistrationTest.java:15)
    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.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
    at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:213)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    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)


On Fri, Apr 17, 2009 at 15:06, J Irving <j_at_lollyshouse.net> wrote:
> Hi
>
> I've been trying to write some simple unit tests using the framework
> and I have a problem.  It may be unrelated to the framework per se,
> because my application also uses JPA and spring - is this likely to
> cause problems?  Ideas about what's going on here would be most
> welcome.
>
> The error I see is a ClassFormatError, more below.  Here's the code
> for the tests:
>
> public class RegistrationTest extends JerseyTest {
>
>    public RegistrationTest() throws Exception {
>        super();
>        ApplicationDescriptor appDescriptor = new ApplicationDescriptor();
>        appDescriptor.setRootResourcePackageName("my.package.base.root");
>        setupTestEnvironment(appDescriptor);
>    }
>
>    @Test
>    public void testListUploaders() throws Exception {
>        String response = webResource.path("uploaders").get(String.class);
>        Assert.assertNotNull(response);
>        System.out.println(response);
>    }
>
>    @Test
>    public void testTestFramework() throws Exception {
>        System.out.println("done");
>    }
>
> }
>
> I run the test like this:
>
> % mvn clean test -Dcontainer.type=EmbeddedGF
>
> And the tests fail with the following errors:
>
> testListUploaders(com.sun.cloud.downloads.resource.RegistrationTest)
> Time elapsed: 0.041 sec  <<< ERROR!
> java.lang.ClassFormatError: Absent Code attribute in method that is
> not native or abstract in class file javax/servlet/http/HttpServlet
>        at java.lang.ClassLoader.defineClass1(Native Method)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
>        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:316)
>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
>        at java.lang.ClassLoader.defineClass1(Native Method)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
>        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:316)
>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:288)
>        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
>        at com.sun.jersey.test.framework.util.ApplicationDescriptor.<init>(ApplicationDescriptor.java:72)
>        at com.sun.cloud.downloads.resource.RegistrationTest.<init>(RegistrationTest.java:13)
>        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.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
>        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
>        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:213)
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
>        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
>        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
>        at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
>        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        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)
>
> testTestFramework(com.sun.cloud.downloads.resource.RegistrationTest)
> Time elapsed: 0.001 sec  <<< ERROR!
> java.lang.ClassFormatError:
> com/sun/jersey/spi/container/servlet/ServletContainer
>        at com.sun.jersey.test.framework.util.ApplicationDescriptor.<init>(ApplicationDescriptor.java:72)
>        at com.sun.cloud.downloads.resource.RegistrationTest.<init>(RegistrationTest.java:13)
>        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.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
>        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
>        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:213)
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
>        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
>        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
>        at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
>        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        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)
>
> ClassFormatError seems to be somewhat out of leftfield.
>
> Here's my pom.xml in case that helps:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <project>
>    <modelVersion>4.0.0</modelVersion>
>    <groupId>my.package.base</groupId>
>    <artifactId>dnc-jersey</artifactId>
>    <packaging>war</packaging>
>    <name>dnc-jersey Jersey Webapp</name>
>    <version>1.0-SNAPSHOT</version>
>    <build>
>        <finalName>dnc-jersey</finalName>
>        <plugins>
>            <plugin>
>                <artifactId>maven-compiler-plugin</artifactId>
>                <inherited>true</inherited>
>                <configuration>
>                    <source>1.6</source>
>                    <target>1.6</target>
>                </configuration>
>            </plugin>
>            <plugin>
>                <groupId>org.glassfish</groupId>
>                <artifactId>maven-glassfish-plugin</artifactId>
>            </plugin>
>        </plugins>
>    </build>
>    <profiles>
>        <profile>
>            <id>jdk-1.5</id>
>            <activation>
>                <jdk>1.5</jdk>
>            </activation>
>            <dependencies>
>                <dependency>
>                    <groupId>com.sun.xml.bind</groupId>
>                    <artifactId>jaxb-impl</artifactId>
>                    <version>2.1.10</version>
>                </dependency>
>            </dependencies>
>        </profile>
>    </profiles>
>    <repositories>
>        <repository>
>            <id>glassfish-maven2-repository.dev.java.net</id>
>            <name>Java.net Maven 2 Repository for GlassFish</name>
>            <url>http://download.java.net/maven/glassfish/</url>
>            <layout>default</layout>
>        </repository>
>        <repository>
>            <id>maven2-repository.dev.java.net</id>
>            <name>Java.net Maven 2 Repository</name>
>            <url>http://download.java.net/maven/2/</url>
>        </repository>
>        <repository>
>            <id>maven-repository.dev.java.net</id>
>            <name>Java.net Maven 1 Repository (legacy)</name>
>            <url>http://download.java.net/maven/1</url>
>            <layout>legacy</layout>
>        </repository>
>    </repositories>
>    <pluginRepositories>
>        <pluginRepository>
>            <id>maven2-repository.dev.java.net</id>
>            <name>Java.net Repository for Maven</name>
>            <url>http://download.java.net/maven/2/</url>
>        </pluginRepository>
>        <pluginRepository>
>            <id>maven-repository.dev.java.net</id>
>            <name>Java.net Maven 1 Repository (legacy)</name>
>            <url>http://download.java.net/maven/1</url>
>            <layout>legacy</layout>
>        </pluginRepository>
>    </pluginRepositories>
>    <dependencies>
>        <dependency>
>            <groupId>com.sun.jersey</groupId>
>            <artifactId>jersey-server</artifactId>
>            <version>${jersey-version}</version>
>        </dependency>
>        <dependency>
>            <groupId>com.sun.jersey</groupId>
>            <artifactId>jersey-json</artifactId>
>            <version>${jersey-version}</version>
>        </dependency>
>        <dependency>
>            <groupId>com.sun.jersey.contribs</groupId>
>            <artifactId>jersey-spring</artifactId>
>            <version>${jersey-version}</version>
>        </dependency>
>        <dependency>
>            <groupId>com.sun.jersey</groupId>
>            <artifactId>jersey-client</artifactId>
>            <version>${jersey-version}</version>
>        </dependency>
>        <dependency>
>            <groupId>javaee</groupId>
>            <artifactId>javaee-api</artifactId>
>            <version>5</version>
>            <scope>provided</scope>
>        </dependency>
>        <dependency>
>            <groupId>org.slf4j</groupId>
>            <artifactId>slf4j-api</artifactId>
>            <version>1.5.6</version>
>        </dependency>
>        <dependency>
>            <groupId>org.slf4j</groupId>
>            <artifactId>slf4j-jdk14</artifactId>
>            <version>1.5.6</version>
>        </dependency>
>        <dependency>
>            <groupId>org.json</groupId>
>            <artifactId>json</artifactId>
>            <version>20090211</version>
>        </dependency>
>        <dependency>
>            <groupId>hibernate</groupId>
>            <artifactId>hibernate-entitymanager</artifactId>
>            <version>3.4.0.GA</version>
>        </dependency>
>        <dependency>
>            <groupId>cglib</groupId>
>            <artifactId>cglib-nodep</artifactId>
>            <version>2.2</version>
>        </dependency>
>        <dependency>
>            <groupId>commons-codec</groupId>
>            <artifactId>commons-codec</artifactId>
>            <version>1.3</version>
>        </dependency>
>        <dependency>
>            <groupId>com.sun.jersey.test.framework</groupId>
>            <artifactId>jersey-test-framework</artifactId>
>            <version>1.0.3</version>
>            <scope>test</scope>
>        </dependency>
>    </dependencies>
>    <properties>
>        <jersey-version>1.0.3</jersey-version>
>    </properties>
> </project>
>
>
>
>
> On Fri, Apr 17, 2009 at 09:13, Naresh <bsnaresh_at_sun.com> wrote:
>> Hi,
>>
>>   I have just written a blog entry [1] which describes how to use the
>> Jersey Test Framework, which is part of the Jersey 1.0.3 release.
>>
>> [1] http://blogs.sun.com/naresh/entry/jersey_test_framework_makes_it
>>
>> Thanks,
>> Naresh
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>