Search in sources :

Example 6 with DiscoveryStringId

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

the class BaseTestNoAutoInc_3_ITER method testIterLotsOfEntitiesStatefulMixed2.

public void testIterLotsOfEntitiesStatefulMixed2() {
    DiscoveryStringId[] discs = new DiscoveryStringId[150];
    for (int i = 0; i < 150; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
    Iterable<DiscoveryStringId> iter = query.paginate(50).iter();
    Iterator<DiscoveryStringId> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(50, i);
    iter = query.iter(50, 50);
    it = iter.iterator();
    i = 50;
    while (it.hasNext()) {
        DiscoveryStringId disc = it.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 7 with DiscoveryStringId

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

the class BaseTestNoAutoInc_5_PAGINATE method testIterPaginateStatelessPreviouPageSeveralTimes.

public void testIterPaginateStatelessPreviouPageSeveralTimes() {
    DiscoveryStringId[] discs = new DiscoveryStringId[15];
    for (int i = 0; i < 15; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%02d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).paginate(5).order("name");
    Iterable<DiscoveryStringId> iter = query.iter();
    Iterator<DiscoveryStringId> it = iter.iterator();
    int i = 0;
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(5, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(10, i);
    iter = query.nextPage().iter();
    it = iter.iterator();
    while (it.hasNext()) {
        assertEquals(discs[i++], it.next());
    }
    assertEquals(15, i);
    iter = query.previousPage().iter();
    it = iter.iterator();
    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);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 8 with DiscoveryStringId

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

the class BaseTestNoAutoInc_5_PAGINATE method testIterPaginateStatefulNextPage.

public void testIterPaginateStatefulNextPage() {
    DiscoveryStringId[] discs = new DiscoveryStringId[10];
    for (int i = 0; i < 10; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%02d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).paginate(5).stateful().order("name");
    Iterable<DiscoveryStringId> iter = query.iter();
    Iterator<DiscoveryStringId> 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);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 9 with DiscoveryStringId

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

the class BaseTestNoAutoInc_6_FETCH_ITER method testFetchIterLotsOfEntitiesStatefulMixed.

public void testFetchIterLotsOfEntitiesStatefulMixed() {
    DiscoveryStringId[] discs = new DiscoveryStringId[150];
    for (int i = 0; i < 150; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
    List<DiscoveryStringId> res = query.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    Iterable<DiscoveryStringId> res2 = query.iter(50);
    Iterator<DiscoveryStringId> it2 = res2.iterator();
    int i = 50;
    while (it2.hasNext()) {
        DiscoveryStringId disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(100, i);
    res = query.paginate(25).fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res2 = query.nextPage().iter();
    it2 = res2.iterator();
    i = 125;
    while (it2.hasNext()) {
        DiscoveryStringId disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    res = query.nextPage().fetch();
    assertEquals(0, res.size());
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 125], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 100], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 75], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 50], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i + 25], res.get(i));
    }
    res = query.previousPage().fetch();
    assertEquals(25, res.size());
    for (i = 0; i < 25; i++) {
        assertEquals(discs[i], res.get(i));
    }
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Example 10 with DiscoveryStringId

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

the class BaseTestNoAutoInc_6_FETCH_ITER method testFetchIterLotsOfEntitiesStatefulMixed3.

public void testFetchIterLotsOfEntitiesStatefulMixed3() {
    DiscoveryStringId[] discs = new DiscoveryStringId[150];
    for (int i = 0; i < 150; i++) {
        discs[i] = new DiscoveryStringId("Disc_" + String.format("%03d", i), StringID_CURIE);
    }
    pm.insert((Object[]) discs);
    Query<DiscoveryStringId> query = pm.createQuery(DiscoveryStringId.class).stateful().order("name");
    List<DiscoveryStringId> res = query.fetch(50);
    assertEquals(50, res.size());
    for (int i = 0; i < 50; i++) {
        assertEquals(discs[i], res.get(i));
    }
    Iterable<DiscoveryStringId> res2 = query.iter();
    Iterator<DiscoveryStringId> it2 = res2.iterator();
    int i = 50;
    while (it2.hasNext()) {
        DiscoveryStringId disc = it2.next();
        assertEquals(discs[i++], disc);
    }
    assertEquals(150, i);
}
Also used : DiscoveryStringId(siena.base.test.model.DiscoveryStringId)

Aggregations

DiscoveryStringId (siena.base.test.model.DiscoveryStringId)98 SienaException (siena.SienaException)9 ArrayList (java.util.ArrayList)6