diff options
Diffstat (limited to 'myapp/src')
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/AddressBookDirect.java | 13 | ||||
-rw-r--r-- | myapp/src/test/java/io/trygvis/container/myapp/AddressBookTest.java | 26 |
2 files changed, 31 insertions, 8 deletions
diff --git a/myapp/src/main/java/io/trygvis/container/myapp/AddressBookDirect.java b/myapp/src/main/java/io/trygvis/container/myapp/AddressBookDirect.java index 7cb6b54..cd76c84 100644 --- a/myapp/src/main/java/io/trygvis/container/myapp/AddressBookDirect.java +++ b/myapp/src/main/java/io/trygvis/container/myapp/AddressBookDirect.java @@ -23,6 +23,7 @@ public class AddressBookDirect { sessionFactory = new MyAppSqlSessionFactory(new DriverManagerDataSource(jdbcUrl)); new AddressBookDirect().work(); } catch (EOFException ignore) { + // Happens when the user closes stdin. } } @@ -89,19 +90,15 @@ public class AddressBookDirect { } public void create() throws SQLException { - session.executeUpdate(CompanyDao.createTableSql); - session.executeUpdate(ContactDao.createTableSql); - for (String sql : Sequences.createSequences) { - session.executeUpdate(sql); + for (String s : sessionFactory.getUnit().create()) { + session.executeUpdate(s); } } public void drop() throws SQLException { - for (String sql : Sequences.dropSequences) { - session.executeUpdate(sql); + for (String s : sessionFactory.getUnit().drop()) { + session.executeUpdate(s); } - session.executeUpdate(ContactDao.dropTableSql); - session.executeUpdate(CompanyDao.dropTableSql); } // ----------------------------------------------------------------------- diff --git a/myapp/src/test/java/io/trygvis/container/myapp/AddressBookTest.java b/myapp/src/test/java/io/trygvis/container/myapp/AddressBookTest.java new file mode 100644 index 0000000..4757b54 --- /dev/null +++ b/myapp/src/test/java/io/trygvis/container/myapp/AddressBookTest.java @@ -0,0 +1,26 @@ +package io.trygvis.container.myapp; + +import org.testng.annotations.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class AddressBookTest { + @Test + public void testBasic() throws Exception { + String jdbcUrl = "jdbc:h2:mem:address-book;DB_CLOSE_DELAY=-1"; + MyAppSqlSessionFactory sessionFactory = new MyAppSqlSessionFactory(new DriverManagerDataSource(jdbcUrl)); + + MyAppSqlSession session = sessionFactory.newSession(); + + for (String s : sessionFactory.getUnit().create()) { + session.executeUpdate(s); + } + session.close(); + + session = sessionFactory.newSession(); + session.company.insert(new Company("My Company")); + + Company company = session.company.selectById(1l); + assertThat(company.name).isEqualTo("My Company"); + } +} |