Пример #1
0
  public void testNoItemInIndex() {

    StoredClass storedClass = db().storedClass(Item.class);
    Assert.isFalse(storedClass.hasClassIndex());

    assertNoItemFoundByQuery();

    db().commit();
    assertNoItemFoundByQuery();
  }
Пример #2
0
  public void testGetStoredFields() {
    assertStoredField(Item.class, FIELD_NAME, ITEM_NAME, String.class, true, false);
    assertStoredField(ItemParent.class, "_array", null, String.class, false, true);

    StoredClass itemStoredClass = itemStoredClass();
    StoredField storedField = itemStoredClass.storedField(FIELD_NAME, null);
    StoredField sameStoredField = itemStoredClass.getStoredFields()[0];
    StoredField otherStoredField = storedClass(ItemParent.class).getStoredFields()[0];
    Assert.equalsAndHashcode(storedField, sameStoredField, otherStoredField);

    Assert.isNull(itemStoredClass.storedField("", null));
  }
Пример #3
0
  private void assertStoredField(
      Class objectClass,
      String fieldName,
      final Object expectedFieldValue,
      Class expectedFieldType,
      boolean hasIndex,
      boolean isArray) {
    StoredClass storedClass = storedClass(objectClass);
    StoredField[] storedFields = storedClass.getStoredFields();
    Assert.areEqual(1, storedFields.length);
    final StoredField storedField = storedFields[0];
    Assert.areEqual(fieldName, storedField.getName());
    StoredField storedFieldByName = storedClass.storedField(fieldName, expectedFieldType);
    Assert.areEqual(storedField, storedFieldByName);

    Object item = retrieveOnlyInstance(objectClass);
    Assert.areEqual(expectedFieldValue, storedField.get(item));
    ReflectClass fieldType = storedField.getStoredType();
    Assert.areEqual(reflector().forClass(expectedFieldType), fieldType);
    Assert.areEqual(isArray, storedField.isArray());

    if (isMultiSession()) {
      return;
    }

    Assert.areEqual(hasIndex, storedField.hasIndex());

    // FIXME: test rename

    if (!hasIndex) {
      Assert.expect(
          RuntimeException.class,
          new CodeBlock() {
            public void run() throws Throwable {
              storedField.traverseValues(
                  new Visitor4() {
                    public void visit(Object obj) {}
                  });
            }
          });
    } else {
      final IntByRef count = new IntByRef();
      storedField.traverseValues(
          new Visitor4() {
            public void visit(Object obj) {
              count.value++;
              Assert.areEqual(expectedFieldValue, obj);
            }
          });
      Assert.areEqual(1, count.value);
    }
  }
Пример #4
0
 public void testGetParentStoredClass() {
   StoredClass itemClass = itemStoredClass();
   StoredClass parentStoredClass = itemClass.getParentStoredClass();
   Assert.areEqual(reflector().forClass(ItemParent.class).getName(), parentStoredClass.getName());
   Assert.areEqual(parentStoredClass, db().storedClass(ItemParent.class));
 }
Пример #5
0
 public void testGetName() {
   StoredClass itemClass = itemStoredClass();
   Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName());
 }
Пример #6
0
 public void testGetIds() {
   StoredClass itemClass = itemStoredClass();
   long[] ids = itemClass.getIDs();
   Assert.areEqual(1, ids.length);
   Assert.areEqual(_id, ids[0]);
 }