public void testAllThere() throws Exception {
   for (int i = 0; i < FOOS.length; i++) {
     Query q = createQuery(FOOS[i]);
     ObjectSet objectSet = q.execute();
     Assert.areEqual(1, objectSet.size());
     FieldIndexItem fii = (FieldIndexItem) objectSet.next();
     Assert.areEqual(FOOS[i], fii.foo);
   }
 }
 public void testUpdate() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   // Db4oUtil.dump(oc);
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   Query q = oc.query();
   q.constrain(rc);
   ObjectSet results = q.execute();
   // Db4oUtil.dumpResults(oc, results);
   Assert.isTrue(results.size() == 1);
 }
  public void testDelete() {
    ExtObjectContainer oc = fixture().db();
    initGenericObjects();
    ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
    Assert.isNotNull(rc);
    Query q = oc.query();
    q.constrain(rc);
    ObjectSet results = q.execute();
    while (results.hasNext()) {
      Object o = results.next();
      oc.delete(o);
    }
    oc.commit();

    // now query to make sure there are none left
    q = oc.query();
    q.constrain(rc);
    q.descend("surname").constrain("John");
    results = q.execute();
    Assert.isTrue(results.size() == 0);
  }
  public void testCreate() throws Exception {

    initGenericObjects();
    // fixture().reopen();
    ExtObjectContainer oc = fixture().db();
    // now check to see if person was saved
    ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
    Assert.isNotNull(rc);
    Query q = oc.query();
    q.constrain(rc);
    ObjectSet results = q.execute();
    Assert.isTrue(results.size() == 1);
    // Db4oUtil.dumpResults(fixture().db(), results);

  }
示例#5
0
 private void expect(Query query, Object[] results, boolean ordered) {
   testCases++;
   ObjectSet set = query.execute();
   if (results == null || results.length == 0) {
     if (set.size() > 0) {
       error("No content expected.");
     }
     return;
   }
   int j = 0;
   if (set.size() == results.length) {
     while (set.hasNext()) {
       Object obj = set.next();
       boolean found = false;
       if (ordered) {
         if (comparer.isEqual(results[j], obj)) {
           results[j] = null;
           found = true;
         }
         j++;
       } else {
         for (int i = 0; i < results.length; i++) {
           if (results[i] != null) {
             if (comparer.isEqual(results[i], obj)) {
               results[i] = null;
               found = true;
               break;
             }
           }
         }
       }
       if (!found) {
         error("Object not expected: " + obj);
       }
     }
     for (int i = 0; i < results.length; i++) {
       if (results[i] != null) {
         error("Expected object not returned: " + results[i]);
       }
     }
   } else {
     error("Unexpected size returned.\nExpected: " + results.length + " Returned: " + set.size());
   }
 }
示例#6
0
 public void log(Query query) {
   ObjectSet set = query.execute();
   while (set.hasNext()) {
     TLogger.log(set.next());
   }
 }