use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testIterPerPageStateless3.
public void testIterPerPageStateless3() {
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.offset(25).iterPerPage(50);
Iterator<Discovery> it = iter.iterator();
int i = 25;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(500, i);
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testFetchPaginateStatelessPreviousPage.
public void testFetchPaginateStatelessPreviousPage() {
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");
List<Discovery> 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));
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testOffsetLimitStatefulPaginateKeys.
public void testOffsetLimitStatefulPaginateKeys() {
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.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 + 50].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).fetchKeys();
assertEquals(50, res.size());
for (int i = 0; i < 50; i++) {
assertEquals(discs[i + 150].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
res = query.offset(50).limit(25).fetchKeys();
assertEquals(25, res.size());
for (int i = 0; i < 25; i++) {
assertEquals(discs[i + 250].id, res.get(i).id);
assertTrue(res.get(i).isOnlyIdFilled());
}
try {
res = query.previousPage().fetch();
} catch (SienaException ex) {
return;
}
fail();
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testFetchPaginateStatefulPreviouPageSeveralTimes.
public void testFetchPaginateStatefulPreviouPageSeveralTimes() {
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.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.nextPage().fetch();
assertEquals(5, res.size());
for (int i = 0; i < 5; i++) {
assertEquals(discs[i + 10], res.get(i));
}
res = query.previousPage().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));
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testIterLotsOfEntitiesStatefulMixed.
public void testIterLotsOfEntitiesStatefulMixed() {
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> res = query.iter(50);
Iterator<Discovery> it = res.iterator();
int i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
res = query.iter(50, 50);
it = res.iterator();
i = 100;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(150, i);
res = query.iter(50, 100);
it = res.iterator();
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(150, i);
}
Aggregations