首页 文章

使用Arquillian测试有状态会话Bean(arq-jbossas-remote)

提问于
浏览
2

我有几个 @Stateful SessionBeans注释如下:

@Stateful
@Remote(AdminFacade.class)
public class TAdminFacadeBean implements TgAdminFacade,Serializable
{
   ...
}

现在我想用Arquillian(1.0.0.Alpha5)测试它们,但是得到很多不同的错误,如果注释是 @Stateful@Stateless ,如果添加 @Named 或者没有@Remote(和 implements 接口),则消息会有所不同) .

重现步骤:

  • 使用原型org.jboss.weld.archetypes创建新的maven项目:jboss-javaee6-webapp:1.0.1.CR2

  • 您可能需要设置jboss.home(请参阅readme.txt)

  • 修改pom.xml并将profiles.profile [id = default] .build.plugins.plugin [artifactId = maven-surefire-plugin] .configuration.skip设置为false

  • 启动JBoss-6.0.0.Final

  • 执行测试(应该通过): mvn test -Parq-jbossas-remote

这里测试的bean是 MemberRegistration

@Model
public class MemberRegistration
{
   ...
}

如果您现在将 @Model 更改为 @Stateful ,JBoss将使用堆栈跟踪进行循环,并使用 @Named @Stateful 此错误:

java.lang.IllegalArgumentException: ArquillianServletRunner not found.
Could not determine ContextRoot from ProtocolMetadata, please contact
DeployableContainer developer.

@Named @Stateless

javax.transaction.NotSupportedException: BaseTransaction.checkTransactionState
- ARJUNA-16051 thread is already associated with a transaction!

如何用Arquillian测试我的 @Stateful beans ?

1 回答

  • 4

    我一遍又一遍地在这个问题上工作,我找到了解决方案 . 即使我讨厌回答我自己的问题,我希望这可以帮助将来的某些人 .

    @Stateful 会话bean的注释(在问题的顶部)是正确的并且保持不变 . 在Arquillian测试案例中, beans 最初是注入的

    @Inject MemberRegistration memberRegistration;
    

    这适用于 @Model beans但不适用于 @Stateful 会话bean和 @Remote 接口 . 似乎必须注入这种 beans 类

    @EJB private AdminFacade adminBean;
    

    What is the difference between @Inject and @EJB

相关问题