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 172634 - no support for unit testing of EJBs
Summary: no support for unit testing of EJBs
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: JUnit (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Andrey Yamkovoy
URL:
Keywords:
: 172633 (view as bug list)
Depends on: 172723
Blocks:
  Show dependency tree
 
Reported: 2009-09-21 00:08 UTC by David Konecny
Modified: 2009-09-22 21:40 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
patch (7.92 KB, patch)
2009-09-21 00:12 UTC, David Konecny
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Konecny 2009-09-21 00:08:10 UTC
While looking at big picture of EJB 3.1 support in NB6.8 I found that lack of generation of unit tests for EJBs is
visible drawback. EJB 3.1 introduces concept of embeddable container which is supported by NetBeans Web Project and
which primary purpose is to simplify unit testing of EJBs. What does not work right now is that a unit test generated
for a class creates testable class via constructor instead of via lookup in case of EJB, that is

  SinBean instance = new SinBean();

instead of expected

  SinBean instance =
(SinBean)javax.ejb.embeddable.EJBContainer.createEJBContainer().getContext().lookup("java:global/classes/SinBean");

When we tried to resolve this for NB6.8 we discovered that it is quite a lot of work to make unit tests generation
pluggable. I tried an alternative to just hardcode the change in JUnit module and attached is patch doing that. I think
the patch is quite reasonable to be included in JUnit module and in future it could be refactored when JUnit module is
more pluggable.

What's your opinion Andrey?
Comment 1 David Konecny 2009-09-21 00:09:26 UTC
*** Issue 172633 has been marked as a duplicate of this issue. ***
Comment 2 David Konecny 2009-09-21 00:12:40 UTC
Created attachment 87980 [details]
patch
Comment 3 Andrey Yamkovoy 2009-09-21 12:27:28 UTC
In general I don't like such a solutions because usually the temporary solutions like this lives for years (or forever)
and code becomes harder to support. But probably for this particular case it make sense to do it the way you suggested
because it's important feature of EE6 and it would be very nice to support it. 

Just note that "embeddable container" and "global lookup" are supported only by EE6 servers.
Comment 4 David Konecny 2009-09-22 00:08:12 UTC
I pushed the patch - d649ec71f25f. I changed it to test for presence of "javax.ejb.embeddable.EJBContainer" on classpath
and generate EJB lookup code only if EJBContainer is reachable. That should avoid generation of lookup code in
non-EJB3.1 projects.

While testing this I filed issue 172723 - unit test should not be generated for an interface. In an EJB has local/remote
interface then issue 172723 occurs.
Comment 5 Quality Engineering 2009-09-22 21:40:01 UTC
Integrated into 'main-golden', will be available in build *200909221401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/d649ec71f25f
User: David Konecny <dkonecny@netbeans.org>
Log: #172634 - no support for unit testing of EJBs