我试图使用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>