eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
385 stars 143 forks source link

[embedded] Unable to get basic unit test working in Maven #11388

Closed glassfishrobot closed 14 years ago

glassfishrobot commented 14 years ago

I am unable to get a simple unit test working with GlassFish Embedded.

Pehaps I misunderstand, not sure. I've been going though the manual trying to replicate the ejb-embedded sample in Maven. Docs : http://docs.sun.com/app/docs/doc/821-1208/gjlde?l=en&a=view Sample : https://glassfish-samples.dev.java.net/source/browse/checkout/glassfish-samples/ws/javaee6/ejb/ejb-embedded/docs/index.html

The result of the project attached is (mvn test):

Test set: za.co.enerweb.enygma.businesslogic.staging.TestCustomerCrud

Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.124 sec <<< FAILURE! simple(za.co.enerweb.enygma.businesslogic.staging.TestCustomerCrud) Time elapsed: 0.035 sec <<< ERROR! java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) 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:303) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) at za.co.enerweb.enygma.businesslogic.staging.TestCustomerCrud.simple(TestCustomerCrud.java:34) 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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 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.junit.runners.ParentRunner.run(ParentRunner.java:236) 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)

Environment

Operating System: All Platform: Linux

Affected Versions

[V3]

glassfishrobot commented 6 years ago
glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said: Created an attachment (id=4138) Maven project that is not unit testing

glassfishrobot commented 14 years ago

@glassfishrobot Commented sirajg said: Have you tried running this straight with junit (without Maven)

glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said:

Have you tried running this straight with junit (without Maven)

Yes, I have run the Java-EE6 sample Ant app and it works correctly.

The sample seems to include all the GlassFish 3 libs and does not use the javaee-api-6.jar as per the Maven app, I am guessing this is the reason.

glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said: The sample Maven project uses

javax javaee-api 6.0 provided

From the below article you will see : 'This scope is only available on the compilation and test classpath, and is not transitive.'

So if I understand that right javaee-api is included when running the JUnit test.

From the website : http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

provided 'This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.'

So how would a Maven Embedded JUnit test work ? Maybe there is a way to put the Embedded container before the java-ee API in Maven ?

glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said: Problem solved!

What you need to do is have the embedded dep before the javaee-api-6 dep

org.glassfish.extras glassfish-embedded-all 3.0 javax javaee-api 6.0 provided

Can someone document this please.

glassfishrobot commented 14 years ago

@glassfishrobot Commented wvreeven said: I wonder if the javaeee-api-6.0.jar is needed at all. As far as I can see all the classes in the jar are available through other jars. It looks like this one only has abstract classes or something like that. I have already informed rjdkolb that I got this working without the java-ee-6.0.jar in the pom.xml.

glassfishrobot commented 14 years ago

@glassfishrobot Commented judytangs said: As Richard suggested we should doc this. I also wonder if we could put in the code to do the following 2 things:

(1) Add code to check for the required dependency order

(2) If dependency order is not correct, issue more meaningful error message

glassfishrobot commented 14 years ago

@glassfishrobot Commented judytangs said: Ludo explained my suggestion above can't be done through code. Now the only option left is to doc this issue in embedded guide and trouble shooting guide. Let me assign this bug to doc.

glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said: Hi Judy

I think this is the correct place to document : http://docs.sun.com/app/docs/doc/821-1208/gjldt?l=en&a=view, section [Using the EJB 3.1 Embeddable API with Embedded Enterprise Server]

An example pom that does not use the plugin, but rather is suited to unit testing would be nice. If you wish I can supply a clean pom.xml to the doc peoples.

regards Richard.

glassfishrobot commented 14 years ago

@glassfishrobot Commented pauldavies said: Set target milestone to 3.0.1 and reassigned to junesm

glassfishrobot commented 14 years ago

@glassfishrobot Commented pauldavies said: Approved in email by Jerome

glassfishrobot commented 14 years ago

@glassfishrobot Commented rjdkolb said: Created an attachment (id=4305) Sample pom as requested with comments in the pom. Pom based on Sun GlassFishTM Enterprise Server v3 Embedded Server Guide

glassfishrobot commented 14 years ago

@glassfishrobot Commented junesm said: Added Richard's POM to the doc and had Richard review it.

glassfishrobot commented 14 years ago

@glassfishrobot Commented File: EmbedNotWorking.zip Attached By: rjdkolb

glassfishrobot commented 14 years ago

@glassfishrobot Commented File: pom.xml Attached By: rjdkolb

glassfishrobot commented 14 years ago

@glassfishrobot Commented Was assigned to junesm

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA GLASSFISH-11388

glassfishrobot commented 14 years ago

@glassfishrobot Commented Reported by rjdkolb

glassfishrobot commented 14 years ago

@glassfishrobot Commented Marked as fixed on Thursday, April 22nd 2010, 2:17:54 am