/* Assert Number of Entities */
List<IEntity> entities = db.query(IEntity.class);
assertEquals(entities.size(), defragmentedDb.query(IEntity.class).size());
for (IEntity entity : entities) {
Query query = defragmentedDb.query();
query.constrain(entity.getClass());
query.descend("fId").constrain(Long.valueOf(entity.getId())); //$NON-NLS-1$
List<?> result = query.execute();
assertEquals(1, result.size());
assertEquals(entity, result.get(0));
if (entity instanceof Attachment)
assertTrue(((Attachment) entity).isIdentical((Attachment) result.get(0)));
else if (entity instanceof BookMark)
assertTrue(((BookMark) entity).isIdentical((BookMark) result.get(0)));
else if (entity instanceof Category)
assertTrue(((Category) entity).isIdentical((Category) result.get(0)));
else if (entity instanceof Feed)
assertTrue(((Feed) entity).isIdentical((Feed) result.get(0)));
else if (entity instanceof Folder)
assertTrue(((Folder) entity).isIdentical((Folder) result.get(0)));
else if (entity instanceof Label)
assertTrue(((Label) entity).isIdentical((Label) result.get(0)));
else if (entity instanceof News)
assertTrue(((News) entity).isIdentical((News) result.get(0)));
else if (entity instanceof Person)
assertTrue(((Person) entity).isIdentical((Person) result.get(0)));
else if (entity instanceof SearchCondition)
assertTrue(((SearchCondition) entity).isIdentical((SearchCondition) result.get(0)));
else if (entity instanceof SearchMark)
assertTrue(((SearchMark) entity).isIdentical((SearchMark) result.get(0)));
}
/* Assert News */
List<INews> newsList = db.query(INews.class);
assertEquals(newsList.size(), defragmentedDb.query(INews.class).size());
for (INews news : newsList) {
Query query = defragmentedDb.query();
query.constrain(news.getClass());
query.descend("fId").constrain(Long.valueOf(news.getId())); //$NON-NLS-1$
List<INews> result = query.execute();
assertEquals(1, result.size());
assertEquals(news.getTitle(), result.get(0).getTitle());
}
/* Assert Description */
List<Description> descriptions = db.query(Description.class);
assertEquals(descriptions.size(), defragmentedDb.query(Description.class).size());
for (Description description : descriptions) {
Query query = defragmentedDb.query();
query.constrain(description.getClass());
query.descend("fNewsId").constrain(Long.valueOf(description.getNews().getId())); //$NON-NLS-1$
List<Description> result = query.execute();
assertEquals(1, result.size());
assertEquals(description.getValue(), result.get(0).getValue());
}
/* Assert News Bins */
List<INewsBin> newsBins = db.query(INewsBin.class);
assertEquals(newsBins.size(), defragmentedDb.query(INewsBin.class).size());
for (INewsBin newsBin : newsBins) {
Query query = defragmentedDb.query();
query.constrain(newsBin.getClass());
query.descend("fId").constrain(Long.valueOf(newsBin.getId())); //$NON-NLS-1$
List<INewsBin> result = query.execute();
assertEquals(1, result.size());
assertEquals(newsBin.getNews(), result.get(0).getNews());
}
/* Assert Folders, Bookmarks and Searchmarks */
List<IFolder> folders = db.query(IFolder.class);
assertEquals(folders.size(), defragmentedDb.query(IFolder.class).size());
for (IFolder folder : folders) {
Query query = defragmentedDb.query();
query.constrain(folder.getClass());
query.descend("fId").constrain(Long.valueOf(folder.getId())); //$NON-NLS-1$
List<IFolder> result = query.execute();
assertEquals(1, result.size());
IFolder otherFolder = result.get(0);
assertTrue(folder.getName().equals(otherFolder.getName()));
assertTrue(folder.getProperties().equals(otherFolder.getProperties()));
IBookMark bm = null;
ISearchMark sm = null;
List<IFolderChild> children = folder.getChildren();
for (IFolderChild child : children) {
if (child instanceof IBookMark)
bm = (IBookMark) child;
else if (child instanceof ISearchMark)
sm = (ISearchMark) child;
}
IBookMark otherBM = null;
ISearchMark otherSM = null;
List<IFolderChild> otherChildren = otherFolder.getChildren();
for (IFolderChild otherChild : otherChildren) {
if (otherChild instanceof IBookMark)
otherBM = (IBookMark) otherChild;
else if (otherChild instanceof ISearchMark)
otherSM = (ISearchMark) otherChild;
}
assertNotNull(bm);
assertNotNull(sm);
assertNotNull(otherBM);
assertNotNull(otherSM);
assertTrue(bm.getName().equals(otherBM.getName()));
assertTrue(bm.getProperties().equals(otherBM.getProperties()));
assertTrue(sm.getSearchConditions().size() == otherSM.getSearchConditions().size());
}
/* Assert Preference */
List<IPreference> preferences = db.query(IPreference.class);
assertEquals(preferences.size(), defragmentedDb.query(IPreference.class).size());
for (IPreference preference : preferences) {
Query query = defragmentedDb.query();
query.constrain(preference.getClass());
query.descend("fId").constrain(Long.valueOf(preference.getId())); //$NON-NLS-1$
List<IPreference> result = query.execute();
assertEquals(1, result.size());
IPreference otherPreference = result.get(0);
assertEquals(preference.getKey(), otherPreference.getKey());
if ("string".equals(preference.getKey()))
assertEquals(preference.getString(), otherPreference.getString());
if ("strings".equals(preference.getKey()))
assertTrue(Arrays.equals(preference.getStrings(), otherPreference.getStrings()));
if ("boolean".equals(preference.getKey()))
assertEquals(preference.getBoolean(), otherPreference.getBoolean());
if ("booleans".equals(preference.getKey()))
assertTrue(Arrays.equals(preference.getBooleans(), otherPreference.getBooleans()));
if ("integer".equals(preference.getKey()))
assertEquals(preference.getInteger(), otherPreference.getInteger());
if ("integers".equals(preference.getKey()))
assertTrue(Arrays.equals(preference.getIntegers(), otherPreference.getIntegers()));
if ("long".equals(preference.getKey()))
assertEquals(preference.getLong(), otherPreference.getLong());
if ("longs".equals(preference.getKey()))
assertTrue(Arrays.equals(preference.getLongs(), otherPreference.getLongs()));
}
/* Assert Label */
List<ILabel> labels = db.query(ILabel.class);
assertEquals(labels.size(), defragmentedDb.query(ILabel.class).size());
for (ILabel label : labels) {
Query query = defragmentedDb.query();
query.constrain(label.getClass());
query.descend("fId").constrain(Long.valueOf(label.getId())); //$NON-NLS-1$
List<INewsBin> result = query.execute();
assertEquals(1, result.size());
assertTrue(((Label) label).isIdentical((ILabel) result.get(0)));
}
/* Assert Counter */
assertEquals(db.query(Counter.class).get(0).getValue(), defragmentedDb.query(Counter.class).get(0).getValue());
/* Assert Search Filter */
List<ISearchFilter> filters = db.query(ISearchFilter.class);
assertEquals(filters.size(), defragmentedDb.query(ISearchFilter.class).size());
for (ISearchFilter filter : filters) {
Query query = defragmentedDb.query();
query.constrain(filter.getClass());
query.descend("fId").constrain(Long.valueOf(filter.getId())); //$NON-NLS-1$
List<INewsBin> result = query.execute();
assertEquals(1, result.size());
ISearchFilter otherFilter = (ISearchFilter) result.get(0);
assertTrue(filter.getName().equals(otherFilter.getName()));
assertEquals(filter.getActions().size(), otherFilter.getActions().size());
ISearch search = filter.getSearch();
ISearch otherSearch = otherFilter.getSearch();
assertEquals(search.getSearchConditions().size(), otherSearch.getSearchConditions().size());
}
/* Assert Conditional Get */
List<IConditionalGet> condGets = db.query(IConditionalGet.class);
assertEquals(condGets.size(), defragmentedDb.query(IConditionalGet.class).size());
for (IConditionalGet condGet : condGets) {
Query query = defragmentedDb.query();
query.constrain(condGet.getClass());
query.descend("fLink").constrain(condGet.getLink().toString()); //$NON-NLS-1$
List<IConditionalGet> result = query.execute();
assertEquals(1, result.size());
IConditionalGet otherCondGet = result.get(0);
assertEquals(condGet.getIfModifiedSince(), otherCondGet.getIfModifiedSince());
assertEquals(condGet.getIfNoneMatch(), otherCondGet.getIfNoneMatch());