Search in sources :

Example 81 with Discovery

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

the class BaseTest method testOffsetLimitStatelessPaginateKeys.

public void testOffsetLimitStatelessPaginateKeys() {
    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).order("id");
    List<Discovery> res = query.paginate(50).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.limit(50).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(50).fetchKeys();
    assertEquals(100, res.size());
    for (int i = 0; i < 100; i++) {
        assertEquals(discs[i + 50].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(50).limit(50).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 50].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 82 with Discovery

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

the class BaseTest method testFetchKeysPaginateStatefulSeveralTimes.

public void testFetchKeysPaginateStatefulSeveralTimes() {
    Discovery[] discs = new Discovery[15];
    for (int i = 0; i < 15; 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);
    }
    res = query.nextPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5].id, res.get(i).id);
    }
    res = query.nextPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 10].id, res.get(i).id);
    }
    res = query.previousPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 5].id, res.get(i).id);
    }
    res = query.previousPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i].id, res.get(i).id);
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 83 with Discovery

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

the class BaseTest method testFetchPaginateStatefulTwice.

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

Example 84 with Discovery

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

the class BaseTest method testLimitStatelessIter.

public void testLimitStatelessIter() {
    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).stateless().order("id");
    Iterable<Discovery> iter = query.limit(50).iter();
    Iterator<Discovery> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.limit(50).iter();
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.iter(50);
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.paginate(50).iter();
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 85 with Discovery

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

the class BaseTest method testJoin.

public void testJoin() {
    Discovery radioactivity = new Discovery("Radioactivity", LongAutoID_CURIE);
    Discovery relativity = new Discovery("Relativity", LongAutoID_EINSTEIN);
    Discovery foo = new Discovery("Foo", LongAutoID_EINSTEIN);
    Discovery teslaCoil = new Discovery("Tesla Coil", LongAutoID_TESLA);
    pm.insert(radioactivity);
    pm.insert(relativity);
    pm.insert(foo);
    pm.insert(teslaCoil);
    List<Discovery> res = pm.createQuery(Discovery.class).join("discoverer").order("name").fetch();
    assertEquals(4, res.size());
    assertEquals(foo, res.get(0));
    assertEquals(radioactivity, res.get(1));
    assertEquals(relativity, res.get(2));
    assertEquals(teslaCoil, res.get(3));
    assertEquals(LongAutoID_EINSTEIN, res.get(0).discoverer);
    assertEquals(LongAutoID_CURIE, res.get(1).discoverer);
    assertEquals(LongAutoID_EINSTEIN, res.get(2).discoverer);
    assertEquals(LongAutoID_TESLA, res.get(3).discoverer);
}
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