Ejemplo n.º 1
0
 public void testNewInstance() {
   String[][] a23 = newStringMatrix(2, 3);
   Assert.areEqual(2, a23.length);
   for (int i = 0; i < a23.length; ++i) {
     Assert.areEqual(3, a23[i].length);
   }
 }
Ejemplo n.º 2
0
  public void testIsNDimensional() {
    ReflectClass arrayOfArrayOfString = reflectClass(String[][].class);
    Assert.isTrue(arrayOfArrayOfString.isArray());

    final ReflectClass arrayOfString = reflectClass(String[].class);
    Assert.areSame(arrayOfString, arrayOfArrayOfString.getComponentType());
    Assert.isTrue(arrayReflector().isNDimensional(arrayOfArrayOfString));
    Assert.isFalse(arrayReflector().isNDimensional(arrayOfString));
  }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
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));
  }
Ejemplo n.º 5
0
 public void testQuery() {
   ExtObjectContainer oc = fixture().db();
   initGenericObjects();
   ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME);
   Assert.isNotNull(rc);
   // now query to make sure there are none left
   Query q = oc.query();
   q.constrain(rc);
   q.descend("surname").constrain("John");
   ObjectSet results = q.execute();
   Assert.isTrue(results.size() == 1);
 }
Ejemplo n.º 6
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);

  }
Ejemplo n.º 7
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);
    }
  }
Ejemplo n.º 8
0
 protected void assertNullItem(Object obj) throws Exception {
   ReflectClass claxx = reflector().forObject(obj);
   ReflectField[] fields = claxx.getDeclaredFields();
   for (int i = 0; i < fields.length; ++i) {
     ReflectField field = fields[i];
     if (field.isStatic() || field.isTransient()) {
       continue;
     }
     ReflectClass type = field.getFieldType();
     if (container().classMetadataForReflectClass(type).isValueType()) {
       continue;
     }
     Object value = field.get(obj);
     Assert.isNull(value);
   }
 }
Ejemplo n.º 9
0
  /**
   * This is to ensure that reflector.forObject(GenericArray) returns an instance of
   * GenericArrayClass instead of GenericClass http://tracker.db4o.com/jira/browse/COR-376
   */
  public void testGenericArrayClass() {
    ExtObjectContainer oc = fixture().db();
    initGenericObjects();
    ReflectClass elementType = oc.reflector().forName(PERSON_CLASSNAME);

    Object array = reflector().array().newInstance(elementType, 5);

    ReflectClass arrayClass = oc.reflector().forObject(array);
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forName(array.getClass().getName());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forClass(array.getClass());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    Assert.areEqual(arrayClass.getName(), ReflectPlatform.fullyQualifiedName(array.getClass()));

    Assert.areEqual("(GA) " + elementType.getName(), array.toString());
  }
Ejemplo n.º 10
0
 public void testGetName() {
   StoredClass itemClass = itemStoredClass();
   Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName());
 }
Ejemplo n.º 11
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));
 }
Ejemplo n.º 12
0
 public void testGetIds() {
   StoredClass itemClass = itemStoredClass();
   long[] ids = itemClass.getIDs();
   Assert.areEqual(1, ids.length);
   Assert.areEqual(_id, ids[0]);
 }
Ejemplo n.º 13
0
 public void testStoredClassImpl() {
   Assert.isInstanceOf(StoredClassImpl.class, itemStoredClass());
 }
Ejemplo n.º 14
0
 public void testUnknownStoredClass() {
   Assert.isNull(storedClass(this.getClass()));
 }
Ejemplo n.º 15
0
 public void testEqualsAndHashCode() {
   StoredClass clazz = itemStoredClass();
   StoredClass same = itemStoredClass();
   StoredClass other = db().storedClass(ItemParent.class);
   Assert.equalsAndHashcode(clazz, same, other);
 }
Ejemplo n.º 16
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));
  }