Search in sources :

Example 51 with Discovery

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

the class BaseTest method testOffsetLimitStatelessPaginate2.

public void testOffsetLimitStatelessPaginate2() {
    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");
    List<Discovery> res = query.limit(50).offset(12).fetch();
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i + 12], res.get(i));
    }
    res = query.offset(13).limit(30).fetch();
    assertEquals(30, res.size());
    for (int i = 0; i < 30; i++) {
        assertEquals(discs[i + 13], res.get(i));
    }
    res = query.offset(10).limit(30).fetch(15);
    assertEquals(15, res.size());
    for (int i = 0; i < 15; i++) {
        assertEquals(discs[i + 10], res.get(i));
    }
    res = query.paginate(6).fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 12], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(6, res.size());
    for (int i = 0; i < 6; i++) {
        assertEquals(discs[i + 6], res.get(i));
    }
    res = query.offset(10).fetch(10);
    assertEquals(10, res.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(discs[i + 10], res.get(i));
    }
    try {
        res = query.nextPage().fetch();
    } catch (SienaException ex) {
        res = query.paginate(8).fetch();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i], res.get(i));
        }
        res = query.nextPage().fetch();
        assertEquals(8, res.size());
        for (int i = 0; i < 8; i++) {
            assertEquals(discs[i + 8], res.get(i));
        }
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 52 with Discovery

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

the class BaseTest method testIterPaginateStatelessPreviousPageFromScratch.

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

Example 53 with Discovery

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

the class BaseTest method testFetchKeysPaginateStatefulPreviousPage.

public void testFetchKeysPaginateStatefulPreviousPage() {
    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.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());
    }
    res = query.previousPage().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());
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 54 with Discovery

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

the class BaseTest method testBatchInsert.

public void testBatchInsert() {
    Object[] discs = new Discovery[100];
    for (int i = 0; i < 100; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    int nb = pm.insert(discs);
    assertEquals(discs.length, nb);
    List<Discovery> res = pm.createQuery(Discovery.class).fetch();
    assertEquals(discs.length, res.size());
    int i = 0;
    for (Discovery disc : res) {
        assertEquals(discs[i++], disc);
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 55 with Discovery

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

the class BaseTest method testOffsetLimitStatelessPaginate.

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