我正在尝试使用arquillian-persistence-dbunit
,我必须使用数据为数据库播种,但我的解决方案都不起作用。我的项目基于Spring,我们正在使用JavaConfig。
在我的POM中,我有arquillian罐子:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.10.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Arquillian dependencies -->
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-dbunit</artifactId>
<version>1.0.0.Alpha7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-service-integration-spring-inject</artifactId>
<version>1.1.0.Alpha1</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-service-integration-spring-javaconfig</artifactId>
<version>1.1.0.Alpha1</version>
</dependency>
我的测试班:
@RunWith(Arquillian.class)
@Transactional(PersistanceTestConfig.TRANSACTION_NAME)
@SpringAnnotationConfiguration(classes = {ArquillianConfiguration.class})
@DataSource(PersistanceTestConfig.MY_DATASOURCE)
@UsingDataSet({"database/myDataset.yml"})
public class MyTestClass{
@Deployment(testable = false)
public static WebArchive createArchive(){
//returns a webArchive
}
@Test
public void myTestMethod(){
//do something
}
}
我的配置类:
@Configuration
@Import({PersistanceTestConfig.class})
@ComponentScan(basePackages = {"com.myapp.dao", ""com.myapp.services"})
@EnableCaching
@EnableTransactionManagement
public class ArquillianConfiguration {}
PersistenceTestConfig:
public class PersistanceTestConfig {
public static final String TRANSACTION_NAME = "transaction";
public static final String MY_DATASOURCE = "datasource";
private Properties getJPAProperties() {
final Properties jpaProperties = new Properties();
jpaProperties.setProperty("hibernate.hbm2ddl.auto", "create");
jpaProperties.setProperty("hibernate.show_sql", "true");
jpaProperties.setProperty("hibernate.format_sql", "true");
jpaProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
return jpaProperties;
}
@Bean(name = MY_DATASOURCE)
public DataSource getDataSource(){
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.continueOnError(false).ignoreFailedDrops(true).build();
}
@Bean
@Autowired
public LocalContainerEntityManagerFactoryBean getEntityManagerREFCS( DataSource dataSource) {
final LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(dataSource);
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
localContainerEntityManagerFactoryBean.setPackagesToScan("com.myapp.dao.beans");
localContainerEntityManagerFactoryBean.setPersistenceUnitName("pUnitName");
localContainerEntityManagerFactoryBean.setJpaProperties(getJPAProperties());
return localContainerEntityManagerFactoryBean;
}
}
我尝试了很多解决方案,但我仍然遇到同样的错误:
org.jboss.arquillian.transaction.impl.lifecycle.TransactionProviderNotFoundException: Transaction provider for given test case has not been found.
令我困扰的是,关于如何在JavaConfig中使用arquillian-persistence-dbunit
的文档并不多。我看到的唯一例子仅在xml配置上有缺陷。例如,在此project。
是否有人使用arquillian-persistence-dbunit
与JavaConfig。