use of sqlite.feature.custombean.case2.DataSourcePopulator in project kripton by xcesco.
the class TestCustomBeanRuntime2 method testCompile.
@Test
public void testCompile() throws InterruptedException {
BindAppDataSource dataSource = BindAppDataSource.build(DataSourceOptions.builder().inMemory(true).populator(new DataSourcePopulator()).build());
dataSource.execute(new Transaction() {
@Override
public TransactionResult onExecute(BindAppDaoFactory daoFactory) {
User user = createUser(daoFactory);
Book book = createBook(daoFactory);
insertLoan(daoFactory, user, book);
// insertLoan(daoFactory, user, book);
return TransactionResult.COMMIT;
}
private void insertLoan(BindAppDaoFactory daoFactory, User user, Book book) {
Loan loan = new Loan();
loan.id = UUID.randomUUID().toString();
loan.bookId = book.id;
loan.userId = user.id;
loan.startTime = new Date();
daoFactory.getLoanDao().insertLoan(loan);
}
private Book createBook(BindAppDaoFactory daoFactory) {
Book book = new Book();
book.id = UUID.randomUUID().toString();
book.title = "Never Ending Story #" + (counter++);
daoFactory.getBookDao().insertBook(book);
return book;
}
private User createUser(BindAppDaoFactory daoFactory) {
User user = new User();
user.id = UUID.randomUUID().toString();
user.age = 24;
user.name = "Fox";
user.lastName = "Mulder";
daoFactory.getUserDao().insertUser(user);
return user;
}
});
dataSource.getLoanDao().findAllWithUserAndBook().observeForever(new Observer<List<LoanWithUserAndBook>>() {
@Override
public void onChanged(List<LoanWithUserAndBook> t) {
assertTrue(t.size() > 0);
LoanWithUserAndBook bean = t.get(0);
log("Found %s elements", t.size());
assertTrue(bean.bookTitle != null);
assertTrue(bean.userName != null);
assertTrue(bean.startTime != null);
assertTrue(bean.id != null);
}
});
KriptonLibrary.getExecutorService().awaitTermination(4, TimeUnit.SECONDS);
}
Aggregations