use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testBatchUpdateList.
public void testBatchUpdateList() {
List<Discovery> discs = new ArrayList<Discovery>();
for (int i = 0; i < 100; i++) {
discs.add(new Discovery("Disc_" + i, LongAutoID_CURIE));
}
int nb = pm.insert(discs);
assertEquals(discs.size(), nb);
List<Discovery> res = pm.createQuery(Discovery.class).fetch();
assertEquals(discs.size(), res.size());
for (Discovery d : discs) {
d.discoverer = LongAutoID_EINSTEIN;
}
nb = pm.update(discs);
assertEquals(discs.size(), nb);
res = pm.createQuery(Discovery.class).fetch();
int i = 0;
for (Discovery disc : res) {
assertEquals(discs.get(i++), disc);
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testIterPaginateStatefulPreviousPage.
public void testIterPaginateStatefulPreviousPage() {
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");
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();
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(10, i);
iter = query.previousPage().iter();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(5, i);
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testBatchSave.
public void testBatchSave() {
Object[] discs = new Discovery[100];
for (int i = 0; i < 100; i++) {
discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
}
pm.save(discs);
List<Discovery> res = pm.createQuery(Discovery.class).fetch();
assertEquals(discs.length, res.size());
int i = 0;
for (Discovery disc : res) {
assertEquals(discs[i++], disc);
}
for (i = 0; i < 100; i++) {
((Discovery) discs[i]).name += "UPD";
((Discovery) discs[i]).discoverer = LongAutoID_EINSTEIN;
}
int nb = pm.save(discs);
assertEquals(discs.length, nb);
res = pm.createQuery(Discovery.class).fetch();
i = 0;
for (Discovery disc : res) {
assertEquals(discs[i++], disc);
}
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testOffsetLimitStatelessPaginateIter.
public void testOffsetLimitStatelessPaginateIter() {
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");
Iterable<Discovery> iter = query.paginate(50).iter();
Iterator<Discovery> it = iter.iterator();
int i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
iter = query.nextPage().iter();
it = iter.iterator();
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
iter = query.limit(50).iter();
it = iter.iterator();
i = 0;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(50, i);
iter = query.offset(50).iter();
it = iter.iterator();
i = 50;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(150, i);
iter = query.offset(50).limit(50).iter();
it = iter.iterator();
i = 50;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(100, i);
}
use of siena.base.test.model.Discovery in project siena by mandubian.
the class BaseTest method testOffsetStatefulIter.
public void testOffsetStatefulIter() {
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).iter();
Iterator<Discovery> it = iter.iterator();
int i = 50;
while (it.hasNext()) {
Discovery disc = it.next();
assertEquals(discs[i++], disc);
}
assertEquals(150, i);
}
Aggregations