aslak

EJBContainer Embedded with Injection support

Jun 11th, 2010
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package com.acme.ejb;
  2.  
  3. import javax.ejb.EJB;
  4. import javax.ejb.EJBContainer;
  5. import javax.ejb.Stateless;
  6.  
  7. import org.junit.After;
  8. import org.junit.Assert;
  9. import org.junit.Before;
  10. import org.junit.Test;
  11.  
  12. public class EJBContainerTestCase
  13. {
  14.    private EJBContainer container;
  15.    
  16.    @Before
  17.    public void create() throws Exception
  18.    {
  19.       container = EJBContainer.createEJBContainer();
  20.       container.inject(this);
  21.    }
  22.    
  23.    @After
  24.    public void destroy() throws Exception
  25.    {
  26.       container.close();
  27.    }
  28.    
  29.    @EJB
  30.    private SimpleBean bean;
  31.    
  32.    @Test
  33.    public void shouldBeAbleToInjectIntoTestClass() throws Exception
  34.    {
  35.       Assert.assertNotNull(bean);
  36.       Assert.assertEquals("This should work", bean.getName());
  37.    }
  38.    
  39.    @Stateless
  40.    public static class SimpleBean
  41.    {
  42.       public String getName()
  43.       {
  44.          return "This should work";
  45.       }
  46.    }
  47. }
Add Comment
Please, Sign In to add comment