Search in sources :

Example 56 with Discovery

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

the class BaseTest method testOffsetLimitStatefulPaginate2Iter.

public void testOffsetLimitStatefulPaginate2Iter() {
    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).stateful().order("id");
    Iterable<Discovery> iter = query.limit(50).offset(12).iter();
    Iterator<Discovery> it = iter.iterator();
    int i = 12;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(62, i);
    iter = query.offset(13).limit(30).iter();
    it = iter.iterator();
    i = 75;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(105, i);
    iter = query.offset(10).limit(30).iter(15);
    it = iter.iterator();
    i = 115;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(130, i);
    iter = query.paginate(6).iter();
    it = iter.iterator();
    i = 130;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(136, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 136;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(142, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    i = 142;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(148, i);
    iter = query.previousPage().iter();
    it = iter.iterator();
    i = 136;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(142, i);
    iter = query.offset(10).iter(10);
    it = iter.iterator();
    i = 146;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(156, i);
    try {
        iter = query.nextPage().iter();
    } catch (SienaException ex) {
        iter = query.paginate(8).iter();
        it = iter.iterator();
        i = 156;
        while (it.hasNext()) {
            Discovery disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(164, i);
        iter = query.nextPage().iter();
        it = iter.iterator();
        i = 164;
        while (it.hasNext()) {
            Discovery disc = it.next();
            assertEquals(discs[i++], disc);
        }
        assertEquals(172, i);
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 57 with Discovery

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

the class BaseTest method testFetchIterLotsOfEntitiesStatefulMixed.

public void testFetchIterLotsOfEntitiesStatefulMixed() {
    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.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    Iterable<Discovery> res2 = query.iter(50);
    Iterator<Discovery> it2 = res2.iterator();
    int i = 50;
    while (it2.hasNext()) {
        Discovery disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    res = query.paginate(25).fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res2 = query.nextPage().iter();
    it2 = res2.iterator();
    i = 125;
    while (it2.hasNext()) {
        Discovery disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(0, res.size());
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 25], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 58 with Discovery

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

the class BaseTest method testOffsetLimitStatefulIter.

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

Example 59 with Discovery

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

the class BaseTest method testFetchKeysPaginateStatefulPreviousPageFromScratch.

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

Example 60 with Discovery

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

the class BaseTest method testFetchKeysPaginateStatelessPreviouPageSeveralTimes.

public void testFetchKeysPaginateStatelessPreviouPageSeveralTimes() {
    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");
    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.nextPage().fetchKeys();
    assertEquals(5, res.size());
    for (int i = 0; i < 5; i++) {
        assertEquals(discs[i + 10].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 + 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)

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