Search in sources :

Example 31 with Discovery

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

the class BaseAsyncTest method testJoin.

public void testJoin() {
    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, relativity, foo, teslaCoil).get();
    SienaFuture<List<Discovery>> future = pm.createQuery(Discovery.class).join("discoverer").order("name").fetch();
    List<Discovery> res = future.get();
    assertEquals(4, res.size());
    assertEquals(foo, res.get(0));
    assertEquals(radioactivity, res.get(1));
    assertEquals(relativity, res.get(2));
    assertEquals(teslaCoil, res.get(3));
    assertEquals(LongAutoID_EINSTEIN, res.get(0).discoverer);
    assertEquals(LongAutoID_CURIE, res.get(1).discoverer);
    assertEquals(LongAutoID_EINSTEIN, res.get(2).discoverer);
    assertEquals(LongAutoID_TESLA, res.get(3).discoverer);
}
Also used : Discovery(siena.base.test.model.Discovery) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 with Discovery

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

the class BaseAsyncTest method testOffsetLimitStatefulPaginateIter.

public void testOffsetLimitStatefulPaginateIter() {
    Discovery[] discs = new Discovery[300];
    for (int i = 0; i < 300; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    SienaFuture<Iterable<Discovery>> future = query.paginate(50).iter();
    Iterable<Discovery> iter = future.get();
    Iterator<Discovery> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    future = query.nextPage().iter();
    iter = future.get();
    it = iter.iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.limit(50).iter();
    iter = future.get();
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    future = query.offset(50).iter();
    iter = future.get();
    it = iter.iterator();
    i = 150;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(200, i);
    future = query.offset(50).limit(25).iter();
    iter = future.get();
    it = iter.iterator();
    i = 250;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(275, i);
    try {
        future = query.previousPage().iter();
    } catch (SienaException ex) {
        return;
    }
    fail();
}
Also used : Discovery(siena.base.test.model.Discovery) SienaException(siena.SienaException)

Example 33 with Discovery

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

the class BaseAsyncTest 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).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).order("id");
    SienaFuture<Iterable<Discovery>> iter = query.offset(25).iterPerPage(50);
    Iterator<Discovery> it = iter.get().iterator();
    int i = 25;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(500, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 34 with Discovery

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

the class BaseAsyncTest method testIterPaginateStatefulSeveralTimesRealAsync.

public void testIterPaginateStatefulSeveralTimesRealAsync() {
    Discovery[] discs = new Discovery[15];
    for (int i = 0; i < 15; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).paginate(5).stateful().order("id");
    SienaFuture<Iterable<Discovery>> future = query.iter();
    SienaFuture<Iterable<Discovery>> future2 = query.nextPage().iter();
    SienaFuture<Iterable<Discovery>> future3 = query.nextPage().iter();
    SienaFuture<Iterable<Discovery>> future4 = query.previousPage().iter();
    SienaFuture<Iterable<Discovery>> future5 = query.previousPage().iter();
    Iterator<Discovery> it = future.get().iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(5, i);
    it = future2.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(10, i);
    it = future3.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(15, i);
    i = 5;
    it = future4.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(10, i);
    i = 0;
    it = future5.get().iterator();
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(5, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 35 with Discovery

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

the class BaseAsyncTest method testIterPerPageStateful2.

public void testIterPerPageStateful2() {
    Discovery[] discs = new Discovery[500];
    for (int i = 0; i < 500; i++) {
        discs[i] = new Discovery("Disc_" + i, LongAutoID_CURIE);
    }
    pm.insert((Object[]) discs).get();
    QueryAsync<Discovery> query = pm.createQuery(Discovery.class).stateful().order("id");
    SienaFuture<Iterable<Discovery>> iter = query.iterPerPage(50);
    Iterator<Discovery> it = iter.get().iterator();
    int i = 0;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(500, 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