如何使用 Arquillian Weld EE Embedded 测试 EJB 方法调用

2024-04-25

我想测试 EJB,并且想使用 Weld EE Embedded 来测试它,因为我不想为此部署应用程序服务器。

这是我的课程:

@RunWith(Arquillian.class)
public class EJBTest {
    @Deployment
    public static JavaArchive createTestArchive() {
        return ShrinkWrap
                .create(JavaArchive.class, "test.jar")
                .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
    }

    @Stateless
    public static class SomeService {
        public String someMethod() {
            return "test";
        }
    }

    @Inject
    SomeService someService;

    @Test
    public void testStatelessCall() {
        Assert.assertEquals("test", someService.someMethod());
    }
}

这是我的pom.xml依赖项:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.junit</groupId>
    <artifactId>arquillian-junit-container</artifactId>
    <version>1.0.0.CR6</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
    <version>1.0.0.CR3</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-core</artifactId>
    <version>1.1.2.Final</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-api</artifactId>
    <version>1.1.2.Final</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.weld</groupId>
    <artifactId>weld-spi</artifactId>
    <scope>test</scope>
    <version>1.1.2.Final</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <!-- version imported with org.jboss.weld:weld-core-bom:1.1.2.Final -->
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-container-test-spi</artifactId>
    <version>1.0.0.CR6</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-container-spi</artifactId>
    <version>1.0.0.CR6</version>
    <scope>test</scope>
</dependency>

在测试我的课程时,我得到了 NPE :

java.lang.RuntimeException: java.lang.NullPointerException
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:195)
    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
    at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125)
    at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
    at com.mycompany.SomeService$Proxy$_$$_Weld$Proxy$.someMethod(SomeService$Proxy$_$$_Weld$Proxy$.java)
    at com.mycompany.EJBTest.testStatelessCall(EJBTest.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.jboss.arquillian.junit.Arquillian$6$1.invoke(Arquillian.java:267)
    at org.jboss.arquillian.container.test.impl.execution.LocalTestExecuter.execute(LocalTestExecuter.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
    at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
    at org.jboss.arquillian.container.test.impl.client.protocol.local.LocalContainerMethodExecutor.invoke(LocalContainerMethodExecutor.java:50)
    at org.jboss.arquillian.container.test.impl.execution.RemoteTestExecuter.execute(RemoteTestExecuter.java:120)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
    at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
    at org.jboss.arquillian.container.test.impl.execution.ClientTestExecuter.execute(ClientTestExecuter.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
    at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createContext(ContainerEventController.java:142)
    at org.jboss.arquillian.container.test.impl.client.ContainerEventController.createTestContext(ContainerEventController.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    at org.jboss.arquillian.test.impl.TestContextHandler.createTestContext(TestContextHandler.java:89)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:90)
    at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
    at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:134)
    at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.test(EventTestRunnerAdaptor.java:111)
    at org.jboss.arquillian.junit.Arquillian$6.evaluate(Arquillian.java:260)
    at org.jboss.arquillian.junit.Arquillian$4.evaluate(Arquillian.java:223)
    at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:311)
    at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
    at org.jboss.arquillian.junit.Arquillian$5.evaluate(Arquillian.java:237)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
    at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:311)
    at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
    at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:196)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:144)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
    ... 101 more

有人有解决办法吗?


这似乎是 Weld EE 的一个错误。

参见对应的Arquillian 论坛帖子 https://community.jboss.org/message/723563 and 焊接问题跟踪器上的相关问题 https://issues.jboss.org/browse/WELD-1086.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Arquillian Weld EE Embedded 测试 EJB 方法调用 的相关文章

  • 在RequiredFieldValidator 触发后调用JavaScript 方法?

    表单元素被视为无效后是否可以触发 JavaScript 方法 这是我的场景 ASPX 页面上有 2 个选项卡 用户必须在两个选项卡上填写信息 用户在选项卡 2 上单击提交按钮 但是 第一个选项卡上有一个必填字段需要注意 我是否需要创建自定义

随机推荐

  • 无法使用 conda 安装 mpi4py 并指定预安装的 mpicc 路径

    我已经尝试安装mpi4py with env MPICC path to openmpi bin mpicc conda install c anaconda mpi4py 但我收到这样的消息 The following NEW packa
  • 无法播种用户和角色

    我正在尝试将用户和角色植入我的数据库中 目前在 C MVC4 中使用具有自动迁移功能的 Code First 实体框架 每当我打电话 更新数据库 强制 我收到以下错误 运行种子方法 System InvalidOperationExcept
  • B 样条线混淆

    我意识到这个板上有关于 B 样条主题的帖子 但这些帖子实际上让我更加困惑 所以我想有人可能能够帮助我 我有 x 值范围从 0 到 1 的模拟数据 我想用三次样条拟合我的数据 degree 3 结为 0 0 1 0 2 0 9 1 我还想使用
  • 从日期选择器小部件中隐藏年份

    我试图从日期选择器小部件中隐藏年份字段 这可能看起来像一个重复的问题 但之前问题给出的答案并不能帮助我隐藏年份字段 这是我的代码 Override protected void onCreate Bundle savedInstanceSt
  • 为什么没有像 ruby​​ 的 capybara for java 这样的无头 BDD 测试引擎?

    为什么没有 java 版本的 ruby capybara https github com jnicklas capybara https github com jnicklas capybara 这可以与 tomcat 或其他东西一起使用
  • 如何在 PyGame 中加载多个图像?

    我需要在 pygame 中加载大约 200 个图像 以便在游戏中的各个点进行位块传输 我尝试为此编写一个函数 但总是回来NameError name tomato is not defined 所有图像名称都是加载图像的变量存储的名称 to
  • 设置分组条形图之间的间距

    我正在尝试按照图库中的示例在 matplotlib 中制作分组条形图 我使用以下内容 import matplotlib pyplot as plt plt figure figsize 7 7 dpi 300 xticks 0 1 1 1
  • 本地播放 mp3 时 Android MediaPlayer 错误(1, -2147483648)

    Android 4 4 发布后不久 我的代码自 2 2 以来一直正常工作 突然出现了错误 我的代码将查询音乐数据库中给定的音乐文件 该路径在查询中返回 然后该路径被传递到 MediaPlayer Code String uri conten
  • 在reactjs中以编程方式取消选中复选框

    我正在弄乱复选框 我想知道有没有一种方法可以通过调用函数来取消选中单击按钮时的复选框 如果是这样 我怎样才能做到这一点
  • 实现类 Markdown 语言的解析器

    我有类似于 markdown 和 SO 使用的标记语言 遗留解析器基于正则表达式 维护起来简直是噩梦 因此我提出了自己的基于 EBNF 语法的解决方案 并通过 mxTextTools SimpleParse 实现 但是 某些令牌可能存在相互
  • CMake 64 位和 SFML 64 位

    我正在尝试使用适用于 Windows 的 CMake 64 位和 SFML 2 5 1 64 位构建 C 项目 当我在项目上运行 cmake 时 我收到一条错误消息 我能让它工作的唯一方法是改变CMAKE PREFIX PATH指向 SFM
  • 读取请求正文两次

    我试图读取中间件中的主体以进行身份 验证 但是当请求到达 api 控制器时 对象为空 因为主体已被读取 有没有办法解决 我在中间件中像这样读取正文 var buffer new byte Convert ToInt32 context Re
  • 如果图像比其容器宽,如何将图像居中?

    通常 您将图像居中display block margin auto 但如果图像比容器大 则会向右溢出 如何使其均匀地向两侧溢出 容器的宽度是固定且已知的 图像的宽度未知 纯CSS解决方案 需要一个额外的包装器 在 FireFox IE8
  • 不同数据类型的内存对齐方式是否不同

    在C中执行不同的数据类型 例如char short int long float double有不同的内存对齐边界吗 在 32 位字对齐字节可寻址操作系统中 如何访问char or short与访问不同int or float 在这两种情况
  • html5在移动设备中自动播放视频

    Auto play is not working without muted attribute when I try to open url in mobile device How to play video without using
  • PreLoader 的多线程 - JavaFX

    我正在开发一个 JavaFX 应用程序 需要在启动主应用程序阶段之前从文件中加载资源 我完成此任务的解决方案是使用 PreLoader 以便用户在加载资源之前无法与应用程序交互 非常标准的东西 我有一个扩展 PreLoader 类的类 该类
  • 有没有办法从 VS2010 中的建模项目生成代码?

    有没有办法从 VS2010 中的建模项目生成代码 看来这个功能即将到来 但 Beta2 中还没有 微软的拉梅什 拉贾戈帕尔回答类似的问题 http social msdn microsoft com Forums en US vstspre
  • 如何将回车符作为字符添加到文件中?

    我想要一个像这样的字符串 blablbabla
  • Flexbox,保持纵横比的方形 div 的响应式网格

    我正在尝试用 div 创建一个 2x2 网格 某些 div 可能包含图像 但它可能会被设置为背景 并带有选项background size cover 这是我创建的笔 http codepen io qarlo pen vLEprq htt
  • 如何使用 Arquillian Weld EE Embedded 测试 EJB 方法调用

    我想测试 EJB 并且想使用 Weld EE Embedded 来测试它 因为我不想为此部署应用程序服务器 这是我的课程 RunWith Arquillian class public class EJBTest Deployment pu