Search in sources :

Example 66 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseTest method testFetchLimitOffsetReal.

public void testFetchLimitOffsetReal() {
    Discovery[] discs = new Discovery[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
        pm.insert(discs[i]);
    }
    List<Discovery> res = pm.createQuery(Discovery.class).order("name").fetch(3, 5);
    assertNotNull(res);
    assertEquals(3, res.size());
    assertEquals(discs[5], res.get(0));
    assertEquals(discs[6], res.get(1));
    assertEquals(discs[7], res.get(2));
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 67 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseTest method testLimitStateful.

public void testLimitStateful() {
    Discovery[] discs = new Discovery[150];
    for (int i = 0; i < 150; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    List<Discovery> res = query.limit(50).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.paginate(50).fetch(25);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 68 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseTest method testIterPerPageStateless2.

public void testIterPerPageStateless2() {
    Discovery[] discs = new Discovery[500];
    for (int i = 0; i < 500; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<Discovery> query = pm.createQuery(Discovery.class).order("id");
    Iterable<Discovery> iter = query.iterPerPage(50);
    Iterator<Discovery> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(500, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 69 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseTest method testRelationship.

public void testRelationship() {
    Discovery radioactivity = new Discovery("Radioactivity", LongAutoID_CURIE);
    Discovery relativity = new Discovery("Relativity", LongAutoID_EINSTEIN);
    Discovery teslaCoil = new Discovery("Tesla Coil", LongAutoID_TESLA);
    Discovery foo = new Discovery(null, LongAutoID_TESLA);
    pm.insert(radioactivity);
    pm.insert(relativity);
    pm.insert(teslaCoil);
    pm.insert(foo);
    Discovery relativity2 = pm.createQuery(Discovery.class).filter("discoverer", LongAutoID_EINSTEIN).get();
    assertTrue(relativity.name.equals(relativity2.name));
    Discovery foo2 = pm.createQuery(Discovery.class).filter("name", null).get();
    assertTrue(foo.id.equals(foo2.id));
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 70 with Discovery

use of siena.base.test.model.Discovery in project siena by mandubian.

the class BaseTest method testFetchKeysPaginateStatefulNextPage.

public void testFetchKeysPaginateStatefulNextPage() {
    Discovery[] discs = new Discovery[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<Discovery> query = pm.createQuery(Discovery.class).paginate(5).stateful().order("id");
    List<Discovery> res = query.fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Aggregations

Discovery (siena.base.test.model.Discovery)212 ArrayList (java.util.ArrayList)71 List (java.util.List)68 SienaException (siena.SienaException)18 QueryOptionGaeContext (siena.gae.QueryOptionGaeContext)10 EnumLong (siena.base.test.model.DataTypes.EnumLong)2 QueryJoin (siena.QueryJoin)1