Search in sources :

Example 1 with DataSourcePopulator

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);
}
Also used : TransactionResult(com.abubusoft.kripton.android.sqlite.TransactionResult) User(sqlite.feature.custombean.case2.User) Date(java.util.Date) LoanWithUserAndBook(sqlite.feature.custombean.case2.LoanWithUserAndBook) Transaction(sqlite.feature.custombean.case2.BindAppDataSource.Transaction) Loan(sqlite.feature.custombean.case2.Loan) BindAppDataSource(sqlite.feature.custombean.case2.BindAppDataSource) LoanWithUserAndBook(sqlite.feature.custombean.case2.LoanWithUserAndBook) Book(sqlite.feature.custombean.case2.Book) BindAppDaoFactory(sqlite.feature.custombean.case2.BindAppDaoFactory) List(java.util.List) DataSourcePopulator(sqlite.feature.custombean.case2.DataSourcePopulator) BaseAndroidTest(base.BaseAndroidTest) Test(org.junit.Test)

Aggregations

BaseAndroidTest (base.BaseAndroidTest)1 TransactionResult (com.abubusoft.kripton.android.sqlite.TransactionResult)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 BindAppDaoFactory (sqlite.feature.custombean.case2.BindAppDaoFactory)1 BindAppDataSource (sqlite.feature.custombean.case2.BindAppDataSource)1 Transaction (sqlite.feature.custombean.case2.BindAppDataSource.Transaction)1 Book (sqlite.feature.custombean.case2.Book)1 DataSourcePopulator (sqlite.feature.custombean.case2.DataSourcePopulator)1 Loan (sqlite.feature.custombean.case2.Loan)1 LoanWithUserAndBook (sqlite.feature.custombean.case2.LoanWithUserAndBook)1 User (sqlite.feature.custombean.case2.User)1