use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testIterPaginateStatelessPreviousPage.
public void testIterPaginateStatelessPreviousPage() {
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.nextPage().iter();
Iterator<Discovery> it = iter.iterator();
int i = 5;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(10, i);
iter = query.previousPage().iter();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(5, i);
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testFetchPaginateStatelessSeveralTimes.
public void testFetchPaginateStatelessSeveralTimes() {
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.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 testJoinSortFields.
public void testJoinSortFields() {
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", "firstName").order("name").fetch();
assertEquals(4, res.size());
assertEquals(foo, res.get(0));
assertEquals(relativity, res.get(1));
assertEquals(radioactivity, res.get(2));
assertEquals(teslaCoil, res.get(3));
assertEquals(LongAutoID_EINSTEIN, res.get(0).discoverer);
assertEquals(LongAutoID_EINSTEIN, res.get(1).discoverer);
assertEquals(LongAutoID_CURIE, res.get(2).discoverer);
assertEquals(LongAutoID_TESLA, res.get(3).discoverer);
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testFetchKeysPaginateStatelessPreviousPage.
public void testFetchKeysPaginateStatelessPreviousPage() {
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().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());
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testIterPaginateStatefulNextPage.
public void testIterPaginateStatefulNextPage() {
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("id");
Iterable<Discovery> iter = query.iter();
Iterator<Discovery> it = iter.iterator();
int i = 0;
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
iter = query.nextPage().iter();
it = iter.iterator();
while (it.hasNext()) {
assertEquals(discs[i++], it.next());
}
assertEquals(10, i);
}
Aggregations