4

When I configure test with @ApplicationComposer It doesn't create SessionContext inside my enterprise beans with proper properties. It always uses PropertiesLogin no matter what I put in configuration.

I am allways getting

javax.ejb.EJBException: User not found for login guest

Exception. Here is my junit test class and example bean.

@RunWith(ApplicationComposer.class)
public class OpenEJBTest {
  @EJB
  UserUtil uu;

   @Configuration
   public Properties properties() {
    Properties p=new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    p.put(Context.SECURITY_PRINCIPAL, "test");
    p.put(Context.SECURITY_CREDENTIALS, "test");
    p.put("openejb.authentication.realmName", "mylogmodule");
    return p;
   }
   @Test
   public void testSth() {
    uu.getUserlogin();
   }

}

@Stateless
public class UserUtilBean implements UserUtil {
    @Resource
    private SessionContext ctx;

    public String getUserLogin() {
        return ctx.getCallerPrincipal().getName();
    }
}

I've tried using custom LogModule (mylogmodule defined in login.config), default module (PropertiesLogin), starting InitialContext with Properties inside test method, but without success. Thanks for any suggestions.

vinga
  • 1,912
  • 20
  • 33

0 Answers0