title: Unit testing EJB and remote interface with EjbEmbedded Conatiner
body: <p>I have this EJB</p>
  
  <pre><code>@Stateless
  public class HelloBean{
  
  
      public String sayHello(){
          return "hello";
      } 
  
  }
  </code></pre>
  
  <p>When I test with this unit test: </p>
  
  <pre><code>    @Test
      public void testEmbeddedPersistence() throws NamingException {
          assertTrue(true);
  
  
  
          Map&lt;String, Object&gt; props = new HashMap&lt;String, Object&gt;();
  
          props.put(EJBContainer.MODULES,  new File("target/classes"));
          props.put("org.glassfish.ejb.embedded.glassfish.instance.root",    "./src/test/resources/glassfish-testing-domain");
  
      ec = EJBContainer.createEJBContainer(props);
      ctx = ec.getContext();
  
  
      String s = "java:global/classes/HelloBean";
      HelloBean helloBean = (HelloBean) ctx.lookup(s);
      assertNotNull(helloBean);
  
      assertABunchOfStuff();        
  
      ec.close();
  }
  </code></pre>
  
  <p>everything works fine.</p>
  
  <p>But when I change it to </p>
  
  <pre><code>@Stateless
  public class HelloBean implements RemoteHello{
  
  
      public String sayHello(){
              return "hello";
      }
  }
  
  @Remote
  public interface RemoteHello{
      public String sayHello();
  }
  
  
  
  
  
  @Test
      public void testEmbeddedPersistence() throws NamingException {
          assertTrue(true);
  
  
  
          Map&lt;String, Object&gt; props = new HashMap&lt;String, Object&gt;();
  
          props.put(EJBContainer.MODULES,  new File("target/classes"));
          props.put("org.glassfish.ejb.embedded.glassfish.instance.root", "./src/test/resources/glassfish-testing-domain");
  
          ec = EJBContainer.createEJBContainer(props);
          ctx = ec.getContext();
  
  
          String s = "java:global/classes/HelloBean!com.mycompany.remoteInterface.RemoteHello";
          RemoteHello remoteHello = (RemoteHello) ctx.lookup(s);
          assertNotNull(remoteHello);
  
          assertABunchOfStuff();        
  
          ec.close();
      }
  </code></pre>
  
  <p>I get a javax.naming.NamingException</p>
  
  <p>the weirdest thing is, When the EJBContainer is intializing it says:</p>
  
  <p>INFO: EJB5181:Portable JNDI names for EJB HelloBean: [java:global/classes/HelloBean!com.mycompany.remoteInterface.RemoteHello, java:global/classes/HelloBean]
  Feb 10, 2012 3:55:22 PM com.sun.ejb.containers.BaseContainer initializeHome</p>
  
  <p>followed shortly after: </p>
  
  <p>Tests in error: 
    testEmbeddedPersistence(com.mycompaony.HelloBean): Lookup failed for 'java:global/classes/HelloBean!com.mycompany.remoteInterface.RemoteHello' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}</p>
  
  <p>How can I get a successful jndi lookup with a remote interface.</p>
  
  <p>Thanks</p>