[ajug-members] Opinions on a project re-write - To EJB3 or Not

SilverAnvil silveranvil at gmail.com
Fri May 30 08:00:53 EDT 2008


Barry,
I've heard that you can't unit test EJBs out of the container, but I
disagree. Here's proof. Let's start with a simple stateless session bean:
package com.testejbs;

import javax.ejb.Stateless;

@Stateless
public class SimpleStatelessSessionBean implements
SimpleStatelessSessionRemote {
    public int add(int first, int second) {
        return first + second;
    }
}

As you can see it has a public method that adds two integers. So here's the
unit test using JUnit 3.8:
package com.cp.testejbs;

import junit.framework.TestCase;

public class SimpleSessionTest extends TestCase {
    public SimpleSessionTest(String testName) {
        super(testName);
    }

    public void  testAdd() {
        int first = 2;
        int second = 3;
        int expectedAnswer = first + second;

        SimpleStatelessSessionBean simpleBean = new
SimpleStatelessSessionBean();
        int answer = simpleBean.add(first, second);
        assertEquals(answer, expectedAnswer);
    }
}

If you compile the code and run the test you'll see it works. BTW, you can
do the same thing with an EJB 2.0 bean as well.

Burk


On Thu, May 29, 2008 at 5:34 PM, Barry Hawkins <barry at alltc.com> wrote:

> The ones who are truly Agile tend to use Spring, since they are
> *actually doing* out-of-container unit and integration testing.  If
> they are using EJB3 and they want to do this, they have to use
> Pitchfork -- which is a joint Open Source project between SpringSource
> and BEA.  If anyone wants to find out how much cruft EJB3 still has,
> try doing out-of-container testing with EJB3 and don't use Pitchfork.
> Your stack traces will tell the story.
>
> The lack of out-of-the-box testing facilities for EJB3 implementations
> leaves me speechless, and I think it reflects just how much of the
> boat has been missed.
>
> Barry
>
> On May 29, 2008, at 1:24 PM, Thomas, Dave wrote:
>
> >>> I think it's mostly a matter of religious preference.  IMHO Spring
> >>> has had inroads with the agile folks, EJB with the enterprise folks.
> >> So which one do the agile, enterprise folks use?
> >> </tongue-in-cheek>
> >
> > Exactly!!  That's really the question.  I knew if I threw in a
> > buzzword like 'enterprise' I'd get into trouble.  Really, it's all
> > J2EE, I guess I meant to say people who are doing more enterprise/
> > legacy integration, web services, JMS, that kind of stuff versus the
> > web+rdbms world.
> >
> > Anyone else want to weigh in?
> [...]
>
>
> --
> Barry Hawkins
> All Things Computed
> site: http://www.alltc.com
> weblog: http://www.yepthatsme.com
>
>
>
>
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>



-- 
"The only rules that really matter are these: what a man can do and what a
man can't do." Captain Jack Sparrow
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.ajug.org/pipermail/ajug-members/attachments/20080530/81700d3d/attachment.html 


More information about the ajug-members mailing list