By the way, I have used EasyGloss with EasyMock to write unit tests for
Stateless and Statefull session beans which use EJBs.

The thing to remember is that they are unit tests!

So I injected a mock EntityManager and other mock @Resource and @EJB
references and I verify that the EJB under unit test calls interfaces with
these mocks according to the contract.

The functional tests tend to require some real objects, not just everything
else is a mock, but again I found EasyGloss useful for these as at some
point you need to push in Mocks, etc to force boundary tests.

My integration tests always involve being deployed to a container, so at
that point EasyGloss is not really useful (classloader rules and securtity
permissions can get in the way)

-Stephen

On Wed, Mar 5, 2008 at 10:41 AM, Stephen Connolly <
[EMAIL PROTECTED]> wrote:

> There I go reading things too fast!
>
> I thought you said EasyMock!
>
> I'm always glad to hear when somebody is using something I wrote!
>
> There is nothing stopping you from using it for more than just
> Entity/JPA/Hibernate
>
> OK, so the examples could do with some more work, but have a look at
> JavaEEGloss (If I recall correctly) It will call the @PostConstruct,
> @PreDestroy, etc. It also allows invoking the @AroundInvoke stuff though you
> do need to call them yourself. I should look at extending it to return a
> Proxy which calles the method interceptors for you!
>
> -Stephen
>
>
> On Wed, Mar 5, 2008 at 8:54 AM, Andrew Hughes <[EMAIL PROTECTED]> wrote:
>
> > Thanks David and Stephen....
> >
> > Stephen, I am currently using EasyGloss, as noted in the review it works
> > very well!!!! But I believe it is limited to Entity/JPA/Hibernate eta
> > testing.
> >
> > David, cheers... tommorow I will give it a bash...
> >
> > night.
> >
> >
> > On Wed, Mar 5, 2008 at 7:19 PM, Stephen Connolly <
> > [EMAIL PROTECTED]> wrote:
> >
> > > Another unit test helper that you might find useful is
> > >
> > > https://easygloss.dev.java.net
> > >
> > > This is lightweight framework for injecting values into JavaEE
> > annotated
> > > classes. It is not a replacement for the integration tests that you
> > will
> > > be
> > > doing using OpenJPA, etc, but it can be useful for testing some of the
> > > more
> > > Unit Test type things that need to be tested.
> > >
> > > -Stephen
> > >
> > > On Wed, Mar 5, 2008 at 5:59 AM, David Blevins <[EMAIL PROTECTED]>
> > > wrote:
> > >
> > > > Hi Andrew,
> > > >
> > > > Here is an example using OpenJPA/Entities/EJB3/EE.  Specifically, an
> > > > @Stateful, injected EntityManager with EXTENDED persistence context,
> > > > and a JUnit TestCase.
> > > >
> > > >
> > > >
> > >
> > http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/injection-of-entitymanager/
> > > >
> > > > This one is identical to the above but uses Hibernate instead of
> > > > OpenJPA:
> > > >
> > > >
> > > >
> > >
> > http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/jpa-hibernate/
> > > >
> > > > This example is similar to the above two but uses an EntityManager
> > > > with TRANSACTION persistence context and shows how to run your test
> > > > code in a container controlled transaction.  Could easily be updated
> > > > to use Hibernate instead (just switch the pom.xml with the above one
> > > > and swap the persistence.xml files).
> > > >
> > > >
> > > >
> > >
> > http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/testing-transactions/
> > > >
> > > > I'm not really a believer in fake environments, especially when you
> > > > can get an equally lightweight, fast and easy to use EJB container
> > > > that's actually been incorporated in a Java EE 5 certified platform.
> > > >
> > > > Hope this helps!
> > > >
> > > > -David
> > > >
> > > >
> > > > On Mar 4, 2008, at 4:41 PM, Andrew Hughes wrote:
> > > >
> > > > > Hi All,
> > > > >
> > > > > This seems to be a hot topic at the moment, but there is very
> > little
> > > > > documentation and references I can find... and so I'm asking for
> > > > > your help.
> > > > >
> > > > > *Background:*
> > > > >
> > > > > One of Maven's most brilliant functions is it's lifecycle's
> > ability
> > > > > to slip
> > > > > straight into agile+continuous integration development (kudo's to
> > > > > maven).
> > > > > It's a wonderful thing that when you write your code and its unit
> > > > > tests
> > > > > today, that maven in many future versions and with countless
> > changes
> > > > > will
> > > > > ensure your tests still work! If they don't maven will fail the
> > > > > build (I
> > > > > could go on but I wont)! So, the reason I'm really on this mailing
> > > > > list is
> > > > > because I want to utilize this wonderful practice! Manually unit
> > > > > testing and
> > > > > manually notifying people about error's is unreliable and so 2004!
> > > > >
> > > > >
> > > > > *So what do I want to test:*
> > > > >
> > > > > *Hibernate Entities:*
> > > > >
> > > > > I have an Entity data model that is provided by Hibernate maven
> > > > > modules.
> > > > > Each modules entities need to be unit tested. From what I have
> > > > > read.. the
> > > > > options available to perform this are Easygloss/mock, ejb3unit,
> > > > > OpenJPA, and
> > > > > TestNG.
> > > > >
> > > > > What I found so far (and don't take this as definitive):
> > > > >
> > > > > Easygloss/mock: This works a treat! Within my unit test's I can
> > > > > setup() an
> > > > > instance of a (Hibernate) entity manager and thus my Entities do
> > > > > persist.
> > > > > The unit tests are a little "cut and paste" the setup() into all
> > of
> > > > > them,
> > > > > but as a whole you can't complain too much if it works.
> > > > >
> > > > > ebj3unit: This I found to be both brilliant and also non
> > functional.
> > > > > I hope
> > > > > I am wrong, but I can't get this working with Hibernate. When I do
> > > > > run it
> > > > > against my entities I get all sorts of "Use of @OneToMany or
> > > > > @ManyToMany
> > > > > targeting an unmapped class" exceptions and problems with
> > > > > "@Embbeded" eta
> > > > > eta eta. Something which does not occur in easygloss, or when
> > > > > running the
> > > > > tests with ithin the JunitEE on the Application Server. What I can
> > > > > say is
> > > > > this is quite cool! The test classes you extent have some very
> > neat
> > > > > default
> > > > > tests you should have run over your entity beans. Example would
> > be,
> > > > > read a
> > > > > record x2 and see if both objects are .equals(). Other than the
> > fact
> > > > > I can't
> > > > > get it working, it's greatest downfall is that I can't find a
> > > > > mailing list
> > > > > or irc channel or blog or wiki or anything to figure out what/if I
> > > > > am doing
> > > > > something wrong. From what I can see, it's brilliant... but I
> > really
> > > > > need it
> > > > > working.
> > > > >
> > > > > OpenJPA: I am yet to use... but I can only assume this is pure JPA
> > > > > and not
> > > > > hibernate? Don't take my word for it though.
> > > > >
> > > > > TestNG : I am reading up on now, which looks good... but because
> > Im
> > > > > greedy I
> > > > > do like the ejb3unit "default" tests and it will be hard to
> > discard
> > > > > them.
> > > > >
> > > > >
> > > > > *EJB3:*
> > > > > As common moden architecture, you wrap your Entitie's with
> > sensible
> > > > > "real
> > > > > world" operations on your data model (Entities). So lets say
> > someone
> > > > > changes
> > > > > the @bean*, you want to make sure you don't effect anything else
> > and
> > > > > you
> > > > > want to test it does persist and comes back out the other side.
> > Now
> > > > > it gets
> > > > > a little complex, because not only do you need to mock the EJB*
> > > > > container
> > > > > for your session* beans. Because the beans depend on Entities, you
> > > > > will also
> > > > > need an entity manager. So... you need the out of container
> > entitiy
> > > > > manager
> > > > > above to work at the same test phase as we have here to test your
> > > > > EJB3 @bean
> > > > > 's.
> > > > >
> > > > > Because I have not solved the above adequately, I have not looked
> > at
> > > > > this
> > > > > yet. In an ideal world, the ejb3unit would be working and I could
> > > > > build on
> > > > > this... or if I get TestNG working it should do both... or if
> > > > > OpenJPA does
> > > > > support hibernate I should be able to use it with OpenEJB.
> > > > >
> > > > >
> > > > > To cut a long story short, it will be excellent when this is all
> > > > > running and
> > > > > I will spread my knowledge if some smarter people than me read
> > then
> > > > > and help
> > > > > me out.
> > > > >
> > > > > Cheers.
> > > >
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> >
>
>

Reply via email to