private void check( CollectionHolder holder, CollectionHolder original1, CollectionHolder original2) { Assert.isTrue(holder != original1); Assert.isTrue(holder != original2); if (holder.name().equals("h1")) checkH1(holder); else checkH2(holder); }
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)); }
private void checkH1(CollectionHolder holder) { Assert.areEqual("value", holder.map().get("key")); Assert.areEqual(holder, holder.map().get("key2")); Assert.areEqual("value2", holder.map().get(holder)); Assert.areEqual("one", holder.list().get(0)); Assert.areEqual(holder, holder.list().get(1)); Assert.isTrue(holder.set().contains("one")); Assert.isTrue(holder.set().contains(holder)); }
private void checkH2(CollectionHolder holder) { Assert.areEqual("h1", ((CollectionHolder) holder.map().get("key")).name()); Assert.areEqual("h1", ((CollectionHolder) holder.map().get(holder)).name()); Assert.areEqual("two", holder.list().get(0)); Assert.areEqual("h1", ((CollectionHolder) holder.list().get(1)).name()); Assert.areEqual(holder, holder.list().get(2)); Assert.isTrue(holder.set().remove("two")); Assert.isTrue(holder.set().remove(holder)); CollectionHolder remaining = nextCollectionHolder(holder.set().iterator()); Assert.areEqual("h1", remaining.name()); }
public void checkUpdate(ExtObjectContainer oc) { Query q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); ObjectSet os = q.execute(); Assert.areEqual(COUNT, os.size()); String expected = null; while (os.hasNext()) { IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next(); if (expected == null) { expected = idi.atom.name; Assert.isTrue(expected.startsWith("updated")); Assert.isTrue(expected.length() > "updated".length()); } Assert.areEqual(expected, idi.atom.name); } }
private Item storedItem(String id) { Query query = newQuery(Item.class); query.descend("_id").constrain(id); ObjectSet<Item> result = query.execute(); Assert.isTrue(result.hasNext()); return result.next(); }
protected void store() throws Exception { Map map = new HashMap(); map.put(KEY, null); Data data = new Data(map); Assert.isTrue(data._map.containsKey(KEY)); store(data); }
private void assertOrdered(ObjectSet result) { Assert.areEqual(IDS.length, result.size()); int previousId = 0; while (result.hasNext()) { Data data = (Data) result.next(); Assert.isTrue(previousId < data._id); previousId = data._id; } }
public void checkUpdateSameObject(ExtObjectContainer oc) throws Exception { Query query = oc.query(); query.descend("_s").constrain(testString + COUNT / 2); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); int i = o.getI(); Assert.isTrue(COUNT <= i && i < COUNT + threadCount()); }
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 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 checkFiles(boolean useLogFile, String fileName, String infix, int count) { for (int i = 1; i <= count; i++) { String versionedFileName = fileName + infix + i; if (VERBOSE) { System.out.println("Checking " + versionedFileName); } ObjectContainer oc = Db4o.openFile(baseConfig(useLogFile), versionedFileName); try { if (!stateBeforeCommit(oc)) { if (!stateAfterFirstCommit(oc)) { Assert.isTrue(stateAfterSecondCommit(oc)); } } } finally { oc.close(); } } }
private void tDefaultArray(Object[] arr) { Assert.areEqual(DEFAULT.length, arr.length); String str[] = new String[DEFAULT.length]; System.arraycopy(DEFAULT, 0, str, 0, DEFAULT.length); for (int i = 0; i < arr.length; i++) { boolean found = false; for (int j = 0; j < str.length; j++) { if (arr[i].equals(str[j])) { str[j] = null; found = true; } } Assert.isTrue(found); } for (int j = 0; j < str.length; j++) { Assert.isNull(str[j]); } }
/** * 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 testRunsRed() { TestResult result = new TestResult(); new TestRunner(Iterators.singletonIterable(new RunsRed(EXCEPTION))).run(result); Assert.isTrue(result.failures().size() == 1, "not red"); }
public void testRunsGreen() { TestResult result = new TestResult(); new TestRunner(Iterators.singletonIterable(new RunsGreen())).run(result); Assert.isTrue(result.failures().size() == 0, "not green"); }
public void testNullValueIsPersisted() { Data data = (Data) retrieveOnlyInstance(Data.class); Assert.isTrue(data._map.containsKey(KEY)); }
private CollectionHolder nextCollectionHolder(Iterator objects) { Assert.isTrue(objects.hasNext()); return (CollectionHolder) objects.next(); }
/** @deprecated using deprecated api */ private void runElementTest(Data data, boolean onOriginal) throws Exception { Map otherMap = new HashMap(); AtomData atom = null; tDefaultValues(data); int itCount = 0; Iterator i = data.i_map.keySet().iterator(); while (i.hasNext()) { String str = (String) i.next(); itCount++; atom = (AtomData) data.i_map.get(str); Assert.areEqual(str, atom.name); otherMap.put(str, atom); } Assert.areEqual(DEFAULT.length, itCount); Assert.areEqual(DEFAULT.length, data.i_map.size()); Assert.isFalse(data.i_map.isEmpty()); db().deactivate(data.i_map, Integer.MAX_VALUE); data.i_map.get("great"); Assert.areEqual("great", ((AtomData) data.i_map.get("great")).name); db().deactivate(data.i_map, Integer.MAX_VALUE); if (onOriginal) { Query q = newQuery(); Data template = new Data(); template.i_map = db().collections().newHashMap(1); template.i_map.put("cool", new AtomData("cool")); q.constrain(template); ObjectSet qResult = q.execute(); Assert.areEqual(1, qResult.size()); Assert.areEqual(data, qResult.next()); } Assert.isTrue(data.i_map.keySet().containsAll(otherMap.keySet())); Object[] arr = data.i_map.keySet().toArray(); tDefaultArray(arr); String[] cmp = new String[DEFAULT.length]; System.arraycopy(DEFAULT, 0, cmp, 0, DEFAULT.length); i = data.i_map.keySet().iterator(); while (i.hasNext()) { String str = (String) i.next(); boolean found = false; for (int j = 0; j < cmp.length; j++) { if (str.equals(cmp[j])) { cmp[j] = null; found = true; } } Assert.isTrue(found); } for (int j = 0; j < cmp.length; j++) { Assert.isNull(cmp[j]); } db().deactivate(data.i_map, Integer.MAX_VALUE); Assert.isFalse(data.i_map.isEmpty()); db().deactivate(data.i_map, Integer.MAX_VALUE); data.i_map.put("yup", new AtomData("yup")); db().store(data.i_map); db().store(data.i_map); db().store(data.i_map); db().store(data.i_helper); db().store(data.i_helper); db().store(data.i_helper); db().commit(); Assert.areEqual(4, data.i_map.size()); atom = (AtomData) data.i_map.get("yup"); Assert.areEqual("yup", atom.name); AtomData removed = (AtomData) data.i_map.remove("great"); Assert.areEqual("great", removed.name); Assert.isNull(data.i_map.remove("great")); db().deactivate(data.i_map, Integer.MAX_VALUE); Assert.areEqual(3, data.i_map.size()); Assert.isTrue(data.i_map.keySet().removeAll(otherMap.keySet())); db().deactivate(data.i_map, Integer.MAX_VALUE); Assert.isFalse(data.i_map.keySet().removeAll(otherMap.keySet())); Assert.areEqual(1, data.i_map.size()); i = data.i_map.keySet().iterator(); String str = (String) i.next(); Assert.areEqual("yup", str); Assert.isFalse(i.hasNext()); data.i_map.clear(); Assert.isTrue(data.i_map.isEmpty()); Assert.areEqual(0, data.i_map.size()); setDefaultValues(data.i_map); String[] strArr = new String[1]; strArr = (String[]) data.i_map.keySet().toArray(strArr); tDefaultArray(strArr); data.i_map.clear(); data.i_map.put("zero", "zero"); for (int j = 0; j < COUNT; j++) { data.i_map.put(MORE + j, new AtomData(MORE + j)); } Assert.areEqual(COUNT + 1, data.i_map.size()); lookupLast(data); db().deactivate(data.i_map, Integer.MAX_VALUE); lookupLast(data); lookupLast(data); reopen(); restoreMembers(data); lookupLast(data); atom = new AtomData("double"); data.i_map.put("double", atom); int previousSize = data.i_map.size(); db().deactivate(data.i_map, Integer.MAX_VALUE); AtomData doubleAtom = (AtomData) data.i_map.put("double", new AtomData("double")); Assert.areSame(atom, doubleAtom); Assert.areEqual(previousSize, data.i_map.size()); data.i_map.put("double", doubleAtom); db().commit(); data.i_map.put("rollBack", "rollBack"); data.i_map.put("double", new AtomData("nono")); db().rollback(); Assert.isNull(data.i_map.get("rollBack")); Assert.areEqual(previousSize, data.i_map.size()); atom = (AtomData) data.i_map.get("double"); Assert.areSame(atom, doubleAtom); Assert.isTrue(data.i_map.containsKey("double")); Assert.isFalse(data.i_map.containsKey("rollBack")); otherMap.clear(); otherMap.put("other1", doubleAtom); otherMap.put("other2", doubleAtom); data.i_map.putAll(otherMap); db().deactivate(data.i_map, Integer.MAX_VALUE); Assert.areSame(doubleAtom, data.i_map.get("other1")); Assert.areSame(doubleAtom, data.i_map.get("other2")); data.i_map.clear(); Assert.areEqual(0, data.i_map.size()); setDefaultValues(data.i_map); int j = 0; i = data.i_map.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); if (key.equals("cool")) { i.remove(); } j++; } Assert.areEqual(2, data.i_map.size()); Assert.isFalse(data.i_map.containsKey("cool")); Assert.areEqual(3, j); data.i_map.put("double", doubleAtom); ((Db4oMap) data.i_map).deleteRemoved(true); data.i_map.keySet().remove("double"); Assert.isFalse(db().isStored(doubleAtom)); ((Db4oMap) data.i_map).deleteRemoved(false); data.i_map.clear(); Assert.areEqual(0, data.i_map.size()); setDefaultValues(data.i_map); }
public void testAcceptsOptOutNetworking() { Assert.isTrue(subject.accept(OptOutNetworkingTest.class)); }
public void testAcceptsDb4oTest() { Assert.isTrue(subject.accept(Db4oTest.class)); }