我的应用程序包含 PicketLink 作为 Maven 依赖项。我编写了 arquillian 测试用例,不以任何方式涉及 PicketLink,但由于 picketlink 中的 CDI,测试失败。
@RunWith(Arquillian.class)
public class WebServiceTest {
@Deployment
public static WebArchive deployment() {
return ShrinkWrap.create(WebArchive.class, "test.war")
.addAsManifestResource(new File("test/beans.xml"));
}
@Test
public void testMath() {
Assert.assertEquals(2, 1+1);
}
}
当我运行 JUnit 测试时,出现此错误:
Unsatisfied dependencies for type [DefaultLoginCredentials] with qualifiers [@Default]
at injection point [[field] @Inject private org.picketlink.internal.AbstractIdentity.loginCredential]
这很奇怪,考虑到我根本没有将 picketlink 包含到 WebArchive 中。我认为 arquillian 应该将测试用例与我的应用程序的其余部分隔离。此外,我排除了 beans.xml 中的 picketlink,并将其包含到 WebArchive 中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<scan>
<exclude name="org.picketlink.**" />
</scan>
</beans>
类似的问题还有reported on developer.jboss ,但没有任何解决方案。任何帮助将不胜感激。
最佳答案
替换焊接依赖
<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.5.Final</version>
<scope>test</scope>
</dependency>
与管理野蝇
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>${wildfly.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
解决了我的问题。请注意,您必须添加 JBOSS_HOME
env。变量,当使用托管野蝇时。可以在IDE中添加环境变量更改运行配置。
关于java - 纠察线中 Arquillian 未满足的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27865241/