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

发布于 2024-11-16 04:30:36 字数 1486 浏览 4 评论 0原文

我有几个 @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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黒涩兲箜 2024-11-23 04:30:36

一遍又一遍地研究这个问题,我找到了解决方案。即使我讨厌回答自己的问题,我也希望这可以帮助将来的人。

@Stateful 会话 bean 的注释(位于问题顶部)是正确的并且保持不变。在 Arquillian 测试用例中,bean 最初是使用

@Inject MemberRegistration memberRegistration;

@Model beans 工作的,但不适用于 @Stateful 会话 bean 和 @Remote 接口。看来这种bean必须注入

@EJB private AdminFacade adminBean;

参见@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 with

@Inject MemberRegistration memberRegistration;

This works with @Model beans but not with @Stateful session beans and a @Remote interface. It seems this kind of beans must be injected with

@EJB private AdminFacade adminBean;

See What is the difference between @Inject and @EJB

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文