我们正在使用DB Unit测试我们的一些课程。我们的主数据库是Oracle,但对于DB Unit,我们使用HSQLDB。
我们有一个类有两个属性,如:
def binary_search(func, segment, group, min_x, max_x, target_y):
while max_x - min_x > 1:
midpoint = (min_x + max_x) / 2
if func(segment, group, midpoint) < target_y:
max_x = midpoint
else:
min_x = midpoint
return min_x
这是我们的测试上下文配置类:
@Column(columnDefinition="NUMBER(6,2)")
private Double height;
@Column(columnDefinition="NUMBER(6,2)")
private Double weight;
这是其中一项测试:
@Configuration
@EnableJpaRepositories(basePackages = {"com.mycompany"})
@ComponentScan(basePackages = "com.mycompany")
public class TestContextConfiguration {
private final String DB_DRIVER = "org.hsqldb.jdbcDriver";
private final String DB_URL = "jdbc:hsqldb:mem:test;sql.syntax_ora=true";
private final String DB_USER = "sa";
private final String DB_PASS = "";
private final String PACKAGES = "com.mycompany.myapp.domain";
private final String PERSISTENCE_UNIT_NAME = "testDatabase";
private final String PERSISTENCE_UNIT_LOCATION = "classpath:META-INF/persistence.xml";
@Bean
public DataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(DB_DRIVER);
ds.setUrl(DB_URL);
ds.setUsername(DB_USER);
ds.setPassword(DB_PASS);
return ds;
}
@Bean
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setJpaDialect(new HibernateJpaDialect());
em.setPackagesToScan(PACKAGES);
em.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
em.setPersistenceXmlLocation(PERSISTENCE_UNIT_LOCATION);
em.setJpaProperties(jpaProperties());
em.afterPropertiesSet();
return em.getObject();
}
@Bean
public JpaTransactionManager transactionManager() {
JpaTransactionManager tm = new JpaTransactionManager();
tm.setEntityManagerFactory(entityManagerFactory());
return tm;
}
public Properties jpaProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
properties.setProperty("hibernate.hbm2ddl.auto", "update");
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
return properties;
}
}
当我们运行它时,我们收到以下错误:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestContextConfiguration.class})
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class,
TransactionalTestExecutionListener.class })
public class GestionUsuarioServiceDbunitTest {
@Autowired
private UserServiceImpl userService;
@Test
@DatabaseSetup("/META-INF/dataset-test.xml")
public void testFindByLogin() throws Exception {
User user = userService.findByLogin("admin");
assertEquals("Admin", user.getNombre());
}
}
请注意,我已经告诉过DB sql.syntax _ora = true
这里发生了什么?