• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB 3 and test-driven development

 
author
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious about the relationship between EJB 3 and the test-driven development community, or even the lightweight Java community, in general. It looks like EJB 3 was influenced to a degree by the ideas coming out of those communities, so if the authors have any story they'd care to share about that, I'd like to read it, positive or negative.

Also, I'm curious about the odd style of dependency injection that EJB 3 appears to have adopted. I admit that I've only looked at it briefly, but it appears not to have what I consider the true benefit of dependency injection, and that is an easy way to substitute test doubles for EJB dependencies to make testing easier. I can see that the annotation-style injection removes the need for duplicating all the JNDI lookup code, but is that all it does?

Thanks. After years of telling people how to work around EJB, it's nice to see the potential for not having to give out that advice any more.

Take care.
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We absolutely were influenced by TDD, and I even did some presentations some time ago on how EJB 3.0 allowed and promoted TDD. We do mention TDD in the book (have an entire chapter on testing) and discuss unit tests and integration tests, in addition to functional and acceptance tests.

When it comes to injection in EJB 3 I don't belive that there is any real loss of substitutability as a result of using annotations. An EJB is injected into a member that is defined to be of some type of business interface. The implementation of that business interface may be whatever class is supplied as the deployed impl class, so it may change without any change to the class being injected. A typical case, though, may be that in TDD you may not even be running in the EJB container, so you create a test injection method to do the injection for you, and again, you need not change the injected class. EJB 3 allows both annotation and XML injection, anyway, though, so if none of this makes any sense to somebody then they can alsways just resort to using XML, like Spring and others have traditionally done. Annotations are helpful not only for removing the lookup code, but also for being able to define the dependencies locally in the code, ie, where the dependency actually exists. Thre are a number of advantages to being able to do this, not the least of which is to be able to define it in Java and not have to go into XML.

Thanks. After years of telling people how to work around EJB, it's nice to see the potential for not having to give out that advice any more.



That was the goal :-)

-Mike
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In TDD, how do I inject the dependency object ? If I am testing outside the EJB container who will provide the persistence service.
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pradeep,

You might want to take a look at this.

From the conclusion of the article of Lucas Jellema:

It turns out to be very straightforward to get EJB 3.0 Persikstence to work, outside of a container. The concepts are - not surprisingly- pretty familiar: you create POJO Domain Objects, you specify how they map to table and columns and you make use of some sort of session or service or manager object to invoke persistency services. This is no different from frameworks like Hibernate or Toplink. From what I have seen already from the more advanced mapping facilities in EJB 3.0, I am pretty sure we can most of the persistency functionality we need. Not all of it, but then again, no framework provides all I need or desire.



Kind regards,

Gian
[ August 16, 2006: Message edited by: Gian Franco Casula ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic