I tried to write Unit tests for my database Services according to this example (https://github.com/21decemb/spring-boot-dbunit-example). I created dataset and test example. After I run the test I recived: org.dbunit.dataset.NoSuchTableException: orders
dataset.xml:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<!-- CUSTOMER DATA -->
<customers id="1" name="Customer" active="1"/>
<!-- POSITION DATA -->
<positions id="1" name="POSITION1"/>
<positions id="2" name="POSITION2"/>
<positions id="3" name="POSITION3"/>
<!-- ORDER DATA -->
<orders id="1" name="order1" color="RED" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" parent_id="1" active="1"/>
<!--<orders id="2" name="order2" color="WHITE" customer_id="1" position_id="1" express="0" date="2016-12-11 19:47:39" last_update="2016-12-11 19:47:39" active="0"/>-->
</dataset>
The second Order Row is commented becacuse I was testing two possibilities. I know that this is because of joins. When I test only 'positions' and 'customers' (simple entities without joins) it works correctly.
My "Order" entity:
@Entity
@Table(name = "orders", schema = Config.dbSchema)
public class Order implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="POSITION_ID")
private Position position;
private short express;
private Date date;
@Column(name="LAST_UPDATE")
private Date lastUpdate;
@Column(name="parent_id")
private Long parentId;
private short active;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="CUSTOMER_ID")
private Customer customer;
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY)
private List<Component> components;
//getters and setters
}
Have anyone any idea on how to fix it?
Thanks in advance.
You have to add this property in the override method setUpDatabaseConfig:
In addition probably you need to add the schema name like this: