package pl.srw.billcalculator.test.db;

import java.util.List;

import de.greenrobot.dao.test.AbstractDaoSessionTest;
import pl.srw.billcalculator.BillCalculator;
import pl.srw.billcalculator.db.PgeBill;
import pl.srw.billcalculator.db.PgeG12Bill;
import pl.srw.billcalculator.db.PgeG12Prices;
import pl.srw.billcalculator.db.PgePrices;
import pl.srw.billcalculator.db.dao.DaoMaster;
import pl.srw.billcalculator.db.dao.DaoSession;

/**
 * Created by Kamil Seweryn.
 */
public class DatabaseTest extends AbstractDaoSessionTest<BillCalculator, DaoMaster, DaoSession> {

    public DatabaseTest() {
        super(DaoMaster.class);
    }

    public void testBillSavedWithPrices() {
        final PgePrices prices = new PgePrices();
        daoSession.insert(prices);

        final PgeBill bill = new PgeBill();
        bill.setPgePrices(prices);
        daoSession.insert(bill);

        assertTrue(bill.getId() > 0);
        final PgeBill billFromDb = daoSession.getPgeBillDao().load(bill.getId());
        assertNotNull(billFromDb.getPgePrices());
        assertTrue(billFromDb.getPricesId() > 0);
        assertTrue(billFromDb.getPgePrices().getId() > 0);
        assertSame(prices, billFromDb.getPgePrices());
    }

    public void testBillListRetrievedWithPrices() {
        final PgeG12Prices prices = new PgeG12Prices();
        daoSession.insert(prices);

        final PgeG12Bill bill = new PgeG12Bill();
        bill.setPgeG12Prices(prices);
        daoSession.insert(bill);

        final List<PgeG12Bill> billsFromDb = daoSession.getPgeG12BillDao().loadAll();
        assertEquals(1, billsFromDb.size());
        assertNotNull(billsFromDb.get(0));
        assertNotNull(billsFromDb.get(0).getPgeG12Prices());
    }
}

@@ -57,16 +57,102 @@
 .List;%0A%0A
+import de.greenrobot.dao.query.LazyList;%0Aimport de.greenrobot.dao.query.QueryBuilder;%0A
 import d
@@ -193,24 +193,24 @@
 essionTest;%0A
-
 import pl.sr
@@ -408,32 +408,120 @@
 r.db.PgePrices;%0A
+import pl.srw.billcalculator.db.PgnigBill;%0Aimport pl.srw.billcalculator.db.PgnigPrices;%0A
 import pl.srw.bi
@@ -795,32 +795,182 @@
 .class);%0A    %7D%0A%0A
+    @Override%0A    protected void setUp() %7B%0A        super.setUp();%0A        QueryBuilder.LOG_SQL = true;%0A        QueryBuilder.LOG_VALUES = true;%0A    %7D%0A%0A
     public void 
@@ -1973,24 +1973,24 @@
 Db.get(0));%0A
-
         asse
@@ -2043,11 +2043,579 @@
 );%0A    %7D
+%0A%0A    public void testBillLazyListRetrievedWithPrices() %7B%0A        final PgnigPrices prices = new PgnigPrices();%0A        daoSession.insert(prices);%0A%0A        final PgnigBill bill = new PgnigBill();%0A        bill.setPgnigPrices(prices);%0A        daoSession.insert(bill);%0A%0A        final LazyList%3CPgnigBill%3E billsFromDb = daoSession.getPgnigBillDao().queryBuilder().listLazy();%0A        assertEquals(1, billsFromDb.size());%0A        assertNotNull(billsFromDb.get(0));%0A        assertNotNull(billsFromDb.get(0).getPgnigPrices());%0A        assertTrue(billsFromDb.isClosed());%0A    %7D
 %0A%7D%0A

test db lazy load