当我使用 @ApplicationComposer 配置测试时,它不会在我的企业 bean 中创建具有适当属性的 SessionContext。无论我在配置中添加什么,它总是使用 PropertiesLogin。
我总是得到
javax.ejb.EJBException: User not found for login guest
例外。这是我的 junit 测试类和示例 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();
}
}
我尝试使用自定义 LogModule(在 login.config 中定义的 mylogmodule)、默认模块(PropertiesLogin)、在测试方法中使用 Properties 启动 InitialContext,但没有成功。感谢您的任何建议。