private void checkRemove() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(ArrayList4Asserter.CAPACITY - 1, list.size());
   for (int i = 0; i < ArrayList4Asserter.CAPACITY - 1; ++i) {
     Assert.areEqual(new Integer(i + 1), list.get(i));
   }
 }
 private void checkListSizeAndContents(int expectedSize) throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(expectedSize, list.size());
   for (int i = 0; i < expectedSize; ++i) {
     Assert.areEqual(new Integer(i), list.get(i));
   }
 }
  public void test() throws Exception {

    store(new Original("original"));

    db().commit();

    Assert.areEqual(1, countOccurences(Original.class));

    // Rename messages are visible at level 1
    // fixture().config().messageLevel(1);

    ObjectClass oc = fixture().config().objectClass(Original.class);

    // allways rename fields first
    oc.objectField("originalName").rename("changedName");
    // we must use ReflectPlatform here as the string must include
    // the assembly name in .net
    oc.rename(CrossPlatformServices.fullyQualifiedName(Changed.class));

    reopen();

    Assert.areEqual(0, countOccurences(Original.class));
    Assert.areEqual(1, countOccurences(Changed.class));

    Changed changed = (Changed) retrieveOnlyInstance(Changed.class);

    Assert.areEqual("original", changed.changedName);
  }
 public void testObjectReferenceCount() {
   int objectCount = 10;
   Item[] items = new Item[objectCount];
   for (int i = 0; i < objectCount; i++) {
     Assert.areEqual(referenceCountForDb4oDatabase() + i, objectReferenceCount());
     items[i] = new Item();
     store(items[i]);
   }
   db().purge(items[0]);
   Assert.areEqual(referenceCountForDb4oDatabase() + objectCount - 1, objectReferenceCount());
 }
 private void assertDescendingRange(int startingValue, TAItem item) {
   TAItem current = item;
   while (current != null) {
     Assert.areEqual(startingValue, current.value());
     current = current.next();
     startingValue--;
   }
 }
Пример #6
0
  private void assertHandlerComparison(Comparable4 handler, Object smaller, Object greater) {
    PreparedComparison comparable = handler.prepareComparison(context(), smaller);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(smaller));
    Assert.isSmaller(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), greater);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(greater));
    Assert.isGreater(0, comparable.compareTo(smaller));
    Assert.isGreater(0, comparable.compareTo(null));

    comparable = handler.prepareComparison(context(), null);
    Assert.isNotNull(comparable);
    Assert.areEqual(0, comparable.compareTo(null));
    Assert.isSmaller(0, comparable.compareTo(smaller));
  }
Пример #7
0
  public void _testKillingClients() throws InterruptedException {

    final int CLIENT_COUNT = 3;

    final StringBuffer results = new StringBuffer();

    ThreadServices.spawnAndJoin(
        "ClientProcessesTestCase.testKillingClients",
        CLIENT_COUNT,
        new CodeBlock() {
          public void run() throws Throwable {
            results.append(
                JavaServices.startAndKillJavaProcess(
                    clientRunnerCommand(), CLIENT_STARTED_OK, 10000));
          }
        });

    Assert.areEqual(1, connectedClients());
    System.out.println(results);
  }
Пример #8
0
 private void assertData() {
   Holder holder = (Holder) retrieveOnlyInstance(Holder.class);
   Assert.isNotNull(holder._item);
   Assert.areEqual(NAME, holder._item._name);
 }
Пример #9
0
 private void assertNoItemFoundByQuery() {
   Query q = db().query();
   q.constrain(Item.class);
   Assert.areEqual(0, q.execute().size());
 }
Пример #10
0
 private void assertInstanceOK(ABar bar) {
   Assert.areEqual("foo", bar.foo);
   Assert.areEqual("bar", bar.bar);
 }
  public void testRefresh() {
    ExtObjectContainer client1 = openNewSession();
    ExtObjectContainer client2 = openNewSession();
    TAItem item1 = (TAItem) retrieveInstance(client1);
    TAItem item2 = (TAItem) retrieveInstance(client2);

    assertDescendingRange(10, item1);

    assertDescendingRange(10, item2);

    item1.value(100);
    item1.next().value(200);
    client1.store(item1, 2);
    client1.commit();

    Assert.areEqual(100, item1.value());
    Assert.areEqual(200, item1.next().value());

    Assert.areEqual(10, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 0
    client2.refresh(item2, 0);
    Assert.areEqual(10, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 1
    client2.refresh(item2, 1);
    Assert.areEqual(100, item2.value());
    Assert.areEqual(9, item2.next().value());

    // refresh 2
    client2.refresh(item2, 2);
    Assert.areEqual(100, item2.value());
    Assert.areEqual(200, item2.next().value());

    updateAscendingWithRange(item1, 1000);
    client1.store(item1, 5);
    client1.commit();

    client2.refresh(item2, 5);
    TAItem next2 = item2;
    for (int i = 1000; i < 1005; i++) {
      Assert.areEqual(i, next2.value());
      next2 = next2.next();
    }
    client1.close();
    client2.close();
  }
Пример #12
0
 private void asserItemCount(final int expectedCount) {
   Query query = db().query();
   query.constrain(Item.class);
   int itemCount = query.execute().size();
   Assert.areEqual(expectedCount, itemCount);
 }
  public void testRefresh() {
    ExtObjectContainer client1 = openNewSession();
    ExtObjectContainer client2 = openNewSession();
    Item item1 = retrieveInstance(client1);
    Item item2 = retrieveInstance(client2);

    Item next1 = item1;
    int value = 10;
    while (next1 != null) {
      Assert.areEqual(value, next1.getValue());
      next1 = next1.next();
      value--;
    }

    Item next2 = item2;
    value = 10;
    while (next2 != null) {
      Assert.areEqual(value, next2.getValue());
      next2 = next2.next();
      value--;
    }

    item1.setValue(100);
    item1.next().setValue(200);
    client1.store(item1, 2);
    client1.commit();

    Assert.areEqual(100, item1.getValue());
    Assert.areEqual(200, item1.next().getValue());

    Assert.areEqual(10, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 0
    client2.refresh(item2, 0);
    Assert.areEqual(10, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 1
    client2.refresh(item2, 1);
    Assert.areEqual(100, item2.getValue());
    Assert.areEqual(9, item2.next().getValue());

    // refresh 2
    client2.refresh(item2, 2);
    Assert.areEqual(100, item2.getValue());
    // FIXME: maybe a bug
    // Assert.areEqual(200, item2.next().getValue());

    next1 = item1;
    value = 1000;
    while (next1 != null) {
      next1.setValue(value);
      next1 = next1.next();
      value++;
    }
    client1.store(item1, 5);
    client1.commit();

    client2.refresh(item2, 5);
    next2 = item2;
    for (int i = 1000; i < 1005; i++) {
      Assert.areEqual(i, next2.getValue());
      next2 = next2.next();
    }

    client1.close();
    client2.close();
  }
 private void checkClear() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   Assert.areEqual(0, list.size());
 }
 private void checkAddAll() throws Exception {
   ArrayList4<Integer> list = retrieveAndAssertNullArrayList4();
   for (int i = 0; i < ArrayList4Asserter.CAPACITY * 2; ++i) {
     Assert.areEqual(new Integer(i), list.get(i));
   }
 }