On Apr 21, 2008, at 12:54 PM, Deepa Singh wrote:
> Hello All,
> I have very simple EJB3.0 session bean with no resource injection,
> no reference to other Java EE component.
> Without deploying EJB 3.0 to an appserver, I am still able to run my
> JUnit test case for that session bean. I thought that until I deploy
> that bean, call it using its JNDI reference name, I should not be
> able to access it. But test is still working without deployment.
>
> Can some one give an explanation what is going on?
Hi Deepa,
Your test is using new() to explicitly instantiate the bean class so
the container isn't involved at all. You won't be getting any of the
EJB semantics.
Some vendors support 1st class EJB component execution within a Java
SE client but there are no EJB 3.0 requirements in that area. It's
something we're planning to address within the EJB 3.1 spec.
--ken
>
>
> EJB 3.0 session bean
> import javax.ejb.Stateless;
> import javax.ejb.*;
>
>
> @Stateless
> @Remote({CompanySessionLocal.class})
> public class CompanySessionBean implements CompanySessionLocal {
>
> public String helloWorld() {
> String helloworld="Hello World";
> return helloworld;
> }
>
> }
>
> JUnit Test Case:
> public class CompanySessionBeanTest {
>
> public CompanySessionBeanTest() { }
>
> @Test
> public void helloWorld() {
> System.out.println("helloWorld");
> CompanySessionBean instance = new CompanySessionBean();
> String expResult = "Hello World";
> System.out.println("From bean-"+expResult);
> String result = instance.helloWorld();
> assertEquals(expResult, result);
>
> }
>
>
> Thanks,
> Deepa
>
>