Search in sources :

Example 96 with Discovery

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

the class BaseTest method testIterPaginateStatelessNextPage.

public void testIterPaginateStatelessNextPage() {
    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).order("name");
    try {
        Iterable<Discovery> res = query.iter();
        Iterator<Discovery> it = res.iterator();
        int i = 0;
        while (it.hasNext()) {
            assertEquals(discs[i++], it.next());
        }
        assertEquals(5, i);
        res = query.nextPage().iter();
        it = res.iterator();
        while (it.hasNext()) {
            assertEquals(discs[i++], it.next());
        }
        assertEquals(10, i);
    } finally {
        query.release();
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 97 with Discovery

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

the class BaseTest method testFetchPaginateStatefulPreviousPage.

public void testFetchPaginateStatefulPreviousPage() {
    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("name");
    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.previousPage().fetch();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 98 with Discovery

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

the class BaseTest method testFetchPaginateStatelessTwiceIter.

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

Example 99 with Discovery

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

the class BaseTest method testOffsetLimitStatefulPaginate2Keys.

public void testOffsetLimitStatefulPaginate2Keys() {
    Discovery[] discs = new Discovery[300];
    for (int i = 0; i < 300; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<Discovery> query = pm.createQuery(Discovery.class).order("id").stateful();
    List<Discovery> res = query.limit(50).offset(12).fetchKeys();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 12].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(13).limit(30).fetchKeys();
    assertEquals(30, res.size());
    for (int i = 0; i < 30; i++) {
        assertEquals(discs[i + 75].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).limit(30).fetchKeys(15);
    assertEquals(15, res.size());
    for (int i = 0; i < 15; i++) {
        assertEquals(discs[i + 115].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.paginate(6).fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 130].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 136].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.nextPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 142].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.previousPage().fetchKeys();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 136].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    res = query.offset(10).fetchKeys(10);
    assertEquals(10, res.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(discs[i + 146].id, res.get(i).id);
        assertTrue(res.get(i).isOnlyIdFilled());
    }
    try {
        res = query.nextPage().fetchKeys();
    } catch (SienaException ex) {
        res = query.paginate(8).fetchKeys();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 156].id, res.get(i).id);
            assertTrue(res.get(i).isOnlyIdFilled());
        }
        res = query.nextPage().fetchKeys();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 164].id, res.get(i).id);
            assertTrue(res.get(i).isOnlyIdFilled());
        }
    }
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 100 with Discovery

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

the class BaseTest method testOffsetStateless.

public void testOffsetStateless() {
    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.offset(50).fetch();
    assertEquals(100, res.size());
    for (int i = 0; i < 100; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
}
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