使用 Arquillian 测试有状态会话 Bean (arq-jbossas-remote)
我有几个 @Stateful
SessionBeans 注释如下:
@Stateful
@Remote(AdminFacade.class)
public class TAdminFacadeBean implements TgAdminFacade,Serializable
{
...
}
现在我想用 Arquillian (1.0.0.Alpha5) 测试它们,但是会出现很多不同的错误,如果注释是 ,消息也会有所不同@Stateful
或 @Stateless
,如果添加了 @Named
或没有 @Remote(以及 implements
接口)。
重现步骤:
- 创建新的 Maven 项目 archetype org.jboss.weld.archetypes: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 to 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
Bean?
I have several @Stateful
SessionBeans annotated like this:
@Stateful
@Remote(AdminFacade.class)
public class TAdminFacadeBean implements TgAdminFacade,Serializable
{
...
}
Now I want to test them with Arquillian (1.0.0.Alpha5), but get lot's of different errors, messages vary either if the annotations are @Stateful
or @Stateless
, if a @Named
is added or if there is no @Remote (and implements
Interface).
Steps to reproduce:
- Create new maven project with
archetype org.jboss.weld.archetypes:jboss-javaee6-webapp:1.0.1.CR2 - You might need to set jboss.home (see
readme.txt) - Modify pom.xml and set profiles.profile[id=default].build.plugins.plugin[artifactId=maven-surefire-plugin].configuration.skip
to false - Start JBoss-6.0.0.Final
- Execute test (should pass):
mvn test -Parq-jbossas-remote
The bean tested here ist MemberRegistration
:
@Model
public class MemberRegistration
{
...
}
If you now change @Model
to @Stateful
, JBoss loops with stacktraces, with @Named @Stateful
this error:
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!
How can I test my @Stateful
Beans with Arquillian?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一遍又一遍地研究这个问题,我找到了解决方案。即使我讨厌回答自己的问题,我也希望这可以帮助将来的人。
@Stateful
会话 bean 的注释(位于问题顶部)是正确的并且保持不变。在 Arquillian 测试用例中,bean 最初是使用@Model
beans 工作的,但不适用于@Stateful
会话 bean 和@Remote
接口。看来这种bean必须注入参见@Inject和@EJB有什么区别
Over and over again working in this issue I figured out the solution. Even I hate answering my own question I hope this can help somebody in the future.
The annotation for the
@Stateful
session bean (at the top of the question) are correct and stay the same. In the Arquillian test case the bean was originally injected withThis works with
@Model
beans but not with@Stateful
session beans and a@Remote
interface. It seems this kind of beans must be injected withSee What is the difference between @Inject and @EJB