package javango.contrib.hibernate;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import com.google.inject.Guice;
import com.google.inject.Injector;
import javango.contrib.hibernate.tests.Poll;
import javango.db.Managers;
import javango.db.QuerySet;
import javango.test.Client;
import junit.framework.TestCase;
public class HibernateQuerySetTest extends TestCase {
public void testToString() throws Exception {
Injector injector = Guice.createInjector(new HibernateModule());
Managers managers = injector.getInstance(Managers.class);
QuerySet<Poll> pollQs = managers.forClass(Poll.class).all();
pollQs = pollQs.filter("WHAT", "EVER");
pollQs = pollQs.filter("never", "ending");
pollQs = pollQs.filterByProperty("hello", "world");
pollQs = pollQs.filterByProperty("code", "support");
pollQs = pollQs.orderBy("fieldA", "fieldB");
pollQs = pollQs.limit(100, 200);
assertEquals(
"HibernateQuerySet [valueFilters={WHAT=EVER, never=ending}, propertyFilters={hello=world, code=support}, orderbys=[fieldA, fieldB], first=100, last=200]",
pollQs.toString());
}
public void testIteratorNoResults() throws Exception {
Injector injector = Guice.createInjector(new HibernateModule());
Configuration cfg = injector.getInstance(HibernateUtil.class).getConfiguration();
new SchemaExport(cfg).drop(false, true);
new SchemaExport(cfg).create(false, true);
Managers managers = injector.getInstance(Managers.class);
QuerySet<Poll> pollQs = managers.forClass(Poll.class).all();
for (Poll p : pollQs) {
fail(String.format("Should never get here %s", p));
}
}
}