I am trying to write unit tests for my Spring Boot application that uses Hibernate / JPA and DAO objects. The following are the Ive steps that have been completed so far:
1) Added the following to pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.hsqldb</groupId> <artifactId>hsqldb</artifactId> <scope>runtime</scope> </dependency>
2) In the file .. /test/resources/application.properties Ive added the following:
spring.jpa.hibernate.ddl-auto = create-drop spring.jpa.database = HSQL spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.HSQLDialect spring.datasource.driverClassName = org.hsqldb.jdbcDriver spring.datasource.url: jdbc:hsqldb:mem:scratchdb spring.datasource.username = sa spring.datasource.password =
3) In .. /test/resources/import.sql Ive added some "paste into ..." data creation scripts.
insert into groups(GROUP_NAME, THREAD_POOL_SIZE) values ("TEST GROUP 1", 5);
4) unit test is as follows:
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) public class TestGroupDao { @Autowired GroupDao groupDao; @Test public void testFindByName() { Group group = groupDao.findByName("TEST GROUP 1");
When I run this test, I get error messages, for example:
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table.. org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: user lacks privilege or object not found: PUBLIC.GROUP
5) Group person:
@Entity @javax.persistence.Table(name = "groups", uniqueConstraints = { @UniqueConstraint(columnNames = "GROUP_NAME"), }) public class Group { // ============== // PRIVATE FIELDS // ============== // An autogenerated id (unique for each group in the db) @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "GROUP_ID", unique = true, nullable = false) private long id; @Column(name = "GROUP_NAME", unique = true, nullable = false) private String name;
What am I missing?
spring spring-boot unit-testing hibernate jpa
Dilteam
source share