我有包含PicketLink的应用程序作为maven依赖项。我编写了不涉及PicketLink的Arquillian测试用例,但是由于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应该从我的其余应用程序中分离测试用例。而且,我排除了包含在WebArchive中的beans.xml中的picketlink:
<?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。变量(使用托管Wildfly时)。可以在IDE中添加环境变量以更改运行配置。