Search in sources :

Example 76 with Discovery

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

the class BaseTest method testIterPaginateStatefulPreviousPageFromScratch.

public void testIterPaginateStatefulPreviousPageFromScratch() {
    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.previousPage().iter();
    Iterator<Discovery> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(0, i);
    it = iter.iterator();
    i = 0;
    while (it.hasNext()) {
        Discovery disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(0, i);
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 77 with Discovery

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

the class BaseTest method testDumpRestoreQueryJoin.

public void testDumpRestoreQueryJoin() {
    Query<Discovery> query = pm.createQuery(Discovery.class).join("discoverer", "firstName");
    QueryJoin qj = (QueryJoin) query.getJoins().get(0);
    String str = JsonSerializer.serialize(qj).toString();
    assertNotNull(str);
    QueryJoin qjRes = (QueryJoin) JsonSerializer.deserialize(QueryJoin.class, Json.loads(str));
    assertNotNull(qjRes);
    assertEquals(qj.field.getName(), qjRes.field.getName());
    for (int i = 0; i < qjRes.sortFields.length; i++) {
        assertEquals(qj.sortFields[i], qjRes.sortFields[i]);
    }
}
Also used : Discovery(siena.base.test.model.Discovery) QueryJoin(siena.QueryJoin)

Example 78 with Discovery

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

the class BaseTest method testBatchInsertList.

public void testBatchInsertList() {
    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());
    int i = 0;
    for (Discovery disc : res) {
        assertEquals(discs.get(i++), disc);
    }
}
Also used : ArrayList(java.util.ArrayList) Discovery(siena.base.test.model.Discovery)

Example 79 with Discovery

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

the class BaseTest method testQueryDeleteFiltered.

public void testQueryDeleteFiltered() {
    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);
    int n = pm.createQuery(Discovery.class).filter("discoverer", LongAutoID_EINSTEIN).delete();
    assertEquals(2, n);
    List<Discovery> res = pm.createQuery(Discovery.class).order("name").fetch();
    assertEquals(2, res.size());
    assertEquals(radioactivity, res.get(0));
    assertEquals(teslaCoil, res.get(1));
}
Also used : Discovery(siena.base.test.model.Discovery)

Example 80 with Discovery

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

the class BaseTest method testOffsetLimitStatelessIter.

public void testOffsetLimitStatelessIter() {
    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.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)

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