Search in sources :

Example 1 with HibernateTransaction

use of com.peterphi.std.guice.hibernate.module.HibernateTransaction in project stdlib by petergeneric.

the class DbunitModuleTest method test.

@Test
public void test() throws Exception {
    // DB is initially empty
    new DbUnitAssert().assertEquals(new FlatXmlDataSetBuilder().build(new StringReader("<dataset><SimpleEntity/><GroupEntity/><simple_entity_join_table/></dataset>")), dataset.get());
    // Add some db contents
    try (HibernateTransaction tx = txutils.start().withAutoCommit()) {
        dao.save(new SimpleEntity(1, "alice", new GroupEntity(1), new GroupEntity(2)));
        dao.save(new SimpleEntity(2, "bob"));
        dao.save(new SimpleEntity(3, "carol"));
        dao.save(new SimpleEntity(4, "dave"));
    }
    // DB should now have 4 rows
    FlatXmlDataSet expected = new FlatXmlDataSetBuilder().build(this.getClass().getResourceAsStream("/com/peterphi/std/guice/hibernatetest/alice-bob-carol-dave-dataset.xml"));
    new DbUnitAssert().assertEquals(expected, dataset.get());
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) DbUnitAssert(org.dbunit.assertion.DbUnitAssert) HibernateTransaction(com.peterphi.std.guice.hibernate.module.HibernateTransaction) StringReader(java.io.StringReader) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) Test(org.junit.Test)

Aggregations

HibernateTransaction (com.peterphi.std.guice.hibernate.module.HibernateTransaction)1 StringReader (java.io.StringReader)1 DbUnitAssert (org.dbunit.assertion.DbUnitAssert)1 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)1 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)1 Test (org.junit.Test)1