public void testNoItemInIndex() { StoredClass storedClass = db().storedClass(Item.class); Assert.isFalse(storedClass.hasClassIndex()); assertNoItemFoundByQuery(); db().commit(); assertNoItemFoundByQuery(); }
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)); }
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); } }
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 testGetName() { StoredClass itemClass = itemStoredClass(); Assert.areEqual(reflector().forClass(Item.class).getName(), itemClass.getName()); }
public void testGetIds() { StoredClass itemClass = itemStoredClass(); long[] ids = itemClass.getIDs(); Assert.areEqual(1, ids.length); Assert.areEqual(_id, ids[0]); }