This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 191590 - Testing EJBs in Java EE 6 Maven projects does not work out of the box
Summary: Testing EJBs in Java EE 6 Maven projects does not work out of the box
Status: RESOLVED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.0
Hardware: All All
: P3 normal (vote)
Assignee: David Konecny
URL:
Keywords:
Depends on: 151760
Blocks:
  Show dependency tree
 
Reported: 2010-11-03 10:10 UTC by Petr Jiricka
Modified: 2011-01-25 06:07 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Jiricka 2010-11-03 10:10:50 UTC
Follow-up on bug 190670.

1. Create a Java EE 6 Maven Web application
2. Set target server to e.g. GlassFish 3.1
3. Create an EJB and add a business method
4. Generate JUnit tests for this EJB using the action on the class' popup menu
5. Run the tests

Running tests will fail with the notorious 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)

The steps to amend this are described in bug 190670, but the IDE should really do the setup out of the box, when the target server is set. Note that it is still not completely clear how the setup should be done cleanly, as there are several conflicting ways to do it, see:

- Arun's blog on the subject http://blogs.sun.com/arungupta/entry/totd_133_jpa2_jpql_criteria
- GlassFish bug https://glassfish.dev.java.net/issues/show_bug.cgi?id=13865
- discussion in bug 190670
- Arquillian approach: http://community.jboss.org/en/arquillian/blog/2010/10/04/the-perfect-recipe-for-testing-jpa-2-revisited
Comment 1 Petr Jiricka 2010-11-12 13:53:17 UTC
Another blog on this subject: http://blog.eisele.net/2010/11/arquillian-test-in-container-with.html
Comment 2 Petr Jiricka 2010-12-17 11:14:46 UTC
According to an off-line discussion, using the system scope dependency as suggested in GlassFish bug 13865 is the correct approach. 

The one remaining question is *when* to add this dependency - adding it to all projects by default after the user sets the server seems too intrusive. A compromise approach could be to add the code to the pom file at this time, but make it commented out.
Comment 3 David Konecny 2011-01-20 01:22:35 UTC
I decided to try to fix this via editor hint. "EJBContainer.createEJBContainer" method call will be underlined as error if its EXECUTE classpath does not contain class "javax.ejb.embeddable.EJBContainer" which can be instantiated. EJBContainer class is stripped of its body in official Java EE APIs and therefore unless user added to runtime classpath some server jars with EE APIs the hint will be shown. The hint says "Implementation of EJBContainer is missing on project's classpath" and the hint has also Fix action. Fix action depends on server registered in IDE and at the moment ignores all other servers than GlassFish. For each GF version 3.* an Fix action is added and labeled as "Use EJBContainer from installation of {ServerDisplayName}". Triggering fix adds "glassfish-embedded-static-shell" artifact to pom.xml in system scope with properly initialized systemPath. If Maven project has GlassFish as associated server only Fix action for that server is shown.

Let's test this and see how well it works.

dff771970c69
Comment 4 Petr Jiricka 2011-01-21 12:47:41 UTC
Thanks, works well for me, although I think several improvements still could be done:
- would it be possible to display an error badge of the test file in the explorer (and all ancestors of this node), so it is more discoverable?
- would it be possible to also display this error in the task list?
- after applying the hint, GlassFish location is hardcoded in pom.xml. Jesse suggested a better approach in comment 190670#c23 (this is also displayed as a warning in Maven output).
Comment 5 Jesse Glick 2011-01-21 14:43:56 UTC
(In reply to comment #4)
> - would it be possible to display an error badge of the test file in the
> explorer (and all ancestors of this node), so it is more discoverable?
> - would it be possible to also display this error in the task list?

I guess this depends on bug #151760?

> comment 190670#c23

I guess you mean: bug #190670 comment #23
Comment 6 Quality Engineering 2011-01-22 06:16:09 UTC
Integrated into 'main-golden', will be available in build *201101220001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/dff771970c69
User: David Konecny <dkonecny@netbeans.org>
Log: #191590 - Testing EJBs in Java EE 6 Maven projects does not work out of the box
Comment 7 David Konecny 2011-01-23 19:37:49 UTC
(In reply to comment #4)
> - after applying the hint, GlassFish location is hardcoded in pom.xml.

fixed as cfce248f035f
Comment 8 Quality Engineering 2011-01-24 06:04:47 UTC
Integrated into 'main-golden', will be available in build *201101240001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/bc9d94357e80
User: David Konecny <dkonecny@netbeans.org>
Log: #191590 - limit the hint to Maven projects only
Comment 9 Quality Engineering 2011-01-25 06:07:04 UTC
Integrated into 'main-golden', will be available in build *201101250001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/cfce248f035f
User: David Konecny <dkonecny@netbeans.org>
Log: #191590 - store local path as a property