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); } }
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)); }
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 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)); }
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); }
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); }
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); } }
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); } }
/** * 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()); }
public void testGetName() { StoredClass itemClass = itemStoredClass(); Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName()); }
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)); }
public void testGetIds() { StoredClass itemClass = itemStoredClass(); long[] ids = itemClass.getIDs(); Assert.areEqual(1, ids.length); Assert.areEqual(_id, ids[0]); }
public void testStoredClassImpl() { Assert.isInstanceOf(StoredClassImpl.class, itemStoredClass()); }
public void testUnknownStoredClass() { Assert.isNull(storedClass(this.getClass())); }
public void testEqualsAndHashCode() { StoredClass clazz = itemStoredClass(); StoredClass same = itemStoredClass(); StoredClass other = db().storedClass(ItemParent.class); Assert.equalsAndHashcode(clazz, same, other); }
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)); }