我正在尝试使用 Arquillian 编写一些 EJB 接口的集成测试,但由于某种原因,我收到一条错误消息,提示它找不到某些注入点的限定符。(每次运行测试时都是任意一个)我使用 dbunit 在 junit 规则中设置 hsqldb。
Caused by: org.apache.openejb.OpenEJBRuntimeException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [no.driw.kraft.ejb.uttrans.mapping.DepartureMapper] is not found with the qualifiers
Qualifiers: [@javax.enterprise.inject.Default()]
在我的Pom
我有以下内容:
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.0.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<scope>provided</scope>
</dependency>
...
在测试课我有这个:
@RunWith(Arquillian.class)
@CreateSchema("sql/transportationplanCreateTables.sql")
public class TransportationplanManagerBeanDbIT {
@Rule//junit rule for setting up persistence, creating schema and inserting dataset using dbunit
public PersistenceUnitRule rule = new PersistenceUnitRule();
@Inject//the ejb to be tested.
private TransportationplanManager instance;
@Deployment
public static WebArchive createDeployment() throws Exception {
return ShrinkWrap.create(WebArchive.class, "driwkraft-ejb-integration-tests.war")
.addPackages(true, TransportationplanManagerBean.class.getPackage())
.addClasses(PersistenceHandler.class, JtaPersistenceProducer.class)
.addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
.addAsManifestResource("persistence.xml", "persistence.xml");
}
@Test
@UsingDataSet("/data/integration/uttrans/transportationplan/validData_dbInput.xml")
public void getDepartures_givenValidDataset_expectsCorrectResult() {
.....
}
}
它抱怨它没有找到的所有类都放在发送到WebArchive.addPackages
上面调用的包的子包中。与文件一起persistence.xml
放在下面。src/test/resources
arquillian.xml
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomee-embedded" default="true">
<configuration>
<property name="httpPort">-1</property>
<property name="stopPort">-1</property>
<property name="dir">target/tomee-embedded</property>
<property name="appWorkingDir">target/arquillian-embedded-working-dir</property>
<property name="portRange">20001-30000</property>
<property name="properties">
dapsysReader = new://Resource?type=DataSource
dapsysReader.JdbcDriver = org.hsqldb.jdbcDriver
dapsysReader.JdbcUrl = jdbc:hsqldb:mem:db
dapsysReader.JtaManaged = true
</property>
</configuration>
</container>
</arquillian>