addressalign-toparrow-leftarrow-leftarrow-right-10x10arrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblightning-boltlinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstar-shapestartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

Re: [ljc] Spring to compliment EJB 3.x

From: Jon H.
Sent on: Monday, June 3, 2013, 5:43 PM
Thanks for the replies on this one too! Stephen, if you don't mind elaborating, you say this:

"My tip for mixing it with EJB hosts and the like would be to use functionality which is already there. 

org.springframework.mock.jndi makes it easy to set up JNDI resources at test time. These could be mocks or connections to test databases."

Is something already available in spring / spring with junit to integration test (not mock) EJBs, by JNDI? Or only a mock of an EJB?

I suppose a restful service could be developed to test EJBs, callable from spring junit tests, as another possibility.

Regards,
Jon

Sent from my HTC

----- Reply message -----
From: "Stephen Masters" <[address removed]>
Date: Mon, Jun 3,[masked]:38
Subject: [ljc] Spring to compliment EJB 3.x
To: <[address removed]>

I just double-checked the original post, and I'm unable to find any mention of 'unit testing'. Best not to tell people off for saying things they didn't say. ;)

The Spring test framework is a wonderfully useful library for performing integration tests for Spring based integration tests, exactly as Jon describes.

Personally it has made it impossible for me to consider container-based EJB for a long time. CDI and Arquillian are just about making that  an acceptable (less unacceptable) option more recently.

My tip for mixing it with EJB hosts and the like would be to use functionality which is already there. 

org.springframework.mock.jndi makes it easy to set up JNDI resources at test time. These could be mocks or connections to test databases.

Something that can be very handy on that front is to configure an in memory DB such as hypersonic to test your transactional stuff. It my not be exactly the same DBA you're deploying to, but 99% (guessing from personal experience without real statistical evidence) of your DB access / transaction bugs should be caught by it.

For JMS I quite like to use a simple Camel config to provide queues that my app can be configured to listen to in a test context in a 'real' style.

Steve





Kevin Wright <[address removed]> wrote:
Is it truly unit testing that you're after?

Spring's own guidelines state that you should never have any spring-specific constructs in your own code, that it sits on the outside and injects references.

You can (and should) create your own instances in unit testing and manually inject the minimal number of dependencies to get the thing tested.  Constructor-injection is good here, as it allows you to create immutable objects, which scale better and are far easier to test.  Having too many such dependencies to inject is a code smell, and you have a bigger problem on your hands.

What you're asking sounds a lot more like integration testing to me





On 31 May[masked]:10, Jon Hatfield <[address removed]> wrote:
Hi all,

The debate between spring and EJB continues but I would like to combine them. I like spring bean testing because it is simple and does not require mocking or elaborate config like arquillian. However, for an enterprise system I prefer to use a 'complete' app server like jboss because to me it is cleaner than bolting on jms, transaction managers etc. onto tomcat so that spring can be enterprise.

I have got 2 questions here:

1. Does anyone know how to use spring (or similar) for full junit coverage whilst using EJB and jboss on the back end? Perhaps a separate instance of jboss, just for junit, that has to be running when you run the tests?

2. Has anyone tried other combinations of spring with EJB together? My last company used spring MVC with EJB back end, for example.

Another strength of spring is its simple CDI, but ee 6 looks to have caught up (and you can write annotations yourself to do CDI). However I think there is a gap regarding testing in java ee, so I basically want to leverage testing from spring, but I am also interested in other ways to combine the strengths of both frameworks.

Regards,
Jon

Sent from my HTC





--
Please Note: If you hit "REPLY", your message will be sent

People in this
group are also in: