@Test public void deleteSearchSuggestCustomConfig() throws Exception { XWikiDocument searchSuggestConfigDoc = mock(XWikiDocument.class); when(xwiki.getDocument(eq(new DocumentReference("mainWiki", "XWiki", "SearchSuggestConfig")), any(XWikiContext.class))).thenReturn(searchSuggestConfigDoc); BaseObject objConfig1 = mock(BaseObject.class); BaseObject objConfig2 = mock(BaseObject.class); BaseObject objConfig3 = mock(BaseObject.class); BaseObject objConfig4 = mock(BaseObject.class); BaseObject objConfig5 = mock(BaseObject.class); BaseObject objConfig6 = mock(BaseObject.class); List<BaseObject> objects = new ArrayList<BaseObject>(); objects.add(objConfig1); objects.add(objConfig2); objects.add(objConfig3); objects.add(null); objects.add(objConfig4); objects.add(objConfig5); objects.add(objConfig6); when(searchSuggestConfigDoc.getXObjects(eq(new DocumentReference("mainWiki", "XWiki", "SearchSuggestSourceClass")))).thenReturn(objects); when(objConfig1.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces"); when(objConfig1.getStringValue("engine")).thenReturn("solr"); when(objConfig1.getStringValue("query")).thenReturn("class:XWiki.XWikiServerClass AND " + "propertyname:wikiprettyname AND propertyvalue__:(__INPUT__*)"); when(objConfig1.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestSolrService"); when(objConfig2.getStringValue("name")).thenReturn("Bad name"); when(objConfig2.getStringValue("engine")).thenReturn("solr"); when(objConfig2.getStringValue("query")).thenReturn("class:XWiki.XWikiServerClass AND " + "propertyname:wikiprettyname AND propertyvalue__:(__INPUT__*)"); when(objConfig2.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestSolrService"); when(objConfig3.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces"); when(objConfig3.getStringValue("engine")).thenReturn("lucene"); when(objConfig3.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " + "object:WorkspaceManager.WorkspaceClass"); when(objConfig3.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService"); when(objConfig4.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces"); when(objConfig4.getStringValue("engine")).thenReturn(null); when(objConfig4.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " + "object:WorkspaceManager.WorkspaceClass"); when(objConfig4.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService"); when(objConfig5.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces"); when(objConfig5.getStringValue("engine")).thenReturn(null); when(objConfig5.getStringValue("query")).thenReturn("bad query"); when(objConfig5.getStringValue("url")).thenReturn("xwiki:WorkspaceManager.WorkspacesSuggestLuceneService"); when(objConfig6.getStringValue("name")).thenReturn("platform.workspace.searchSuggestSourceWorkspaces"); when(objConfig6.getStringValue("engine")).thenReturn(null); when(objConfig6.getStringValue("query")).thenReturn("XWiki.XWikiServerClass.wikiprettyname:__INPUT__* AND " + "object:WorkspaceManager.WorkspaceClass"); when(objConfig6.getStringValue("url")).thenReturn("bad URL"); mocker.getComponentUnderTest().deleteSearchSuggestCustomConfig("mainWiki"); verify(searchSuggestConfigDoc).removeXObject(objConfig1); verify(searchSuggestConfigDoc).removeXObject(objConfig3); verify(xwiki).saveDocument(searchSuggestConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); }
@Override public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig"); DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass"); XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext); List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); if (objects != null) { boolean found = false; for (BaseObject object : objects) { if (object == null) { continue; } String name = object.getStringValue("name"); if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) { String query = object.getStringValue("query"); String engine = object.getStringValue("engine"); String url = object.getStringValue("url"); if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) { searchConfigDoc.removeXObject(object); found = true; } } } if (found) { xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); } } }
DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter { @Override public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig"); DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass"); XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext); List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); if (objects != null) { boolean found = false; for (BaseObject object : objects) { if (object == null) { continue; } String name = object.getStringValue("name"); if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) { String query = object.getStringValue("query"); String engine = object.getStringValue("engine"); String url = object.getStringValue("url"); if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) { searchConfigDoc.removeXObject(object); found = true; } } } if (found) { xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); } } } }
DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter { @Override public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig"); DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass"); XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext); List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); if (objects != null) { boolean found = false; for (BaseObject object : objects) { if (object == null) { continue; } String name = object.getStringValue("name"); if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) { String query = object.getStringValue("query"); String engine = object.getStringValue("engine"); String url = object.getStringValue("url"); if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) { searchConfigDoc.removeXObject(object); found = true; } } } if (found) { xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); } } }  }
DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter { @Override public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig"); DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass"); XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext); List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); if (objects != null) { boolean found = false; for (BaseObject object : objects) { if (object == null) { continue; } String name = object.getStringValue("name"); if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) { String query = object.getStringValue("query"); String engine = object.getStringValue("engine"); String url = object.getStringValue("url"); if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) { searchConfigDoc.removeXObject(object); found = true; } } } if (found) { xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); } } }  @Override void deleteSearchSuggestCustomConfig(String wikiId); }
DefaultSearchSuggestCustomConfigDeleter implements SearchSuggestCustomConfigDeleter { @Override public void deleteSearchSuggestCustomConfig(String wikiId) throws XWikiException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); DocumentReference searchConfigDocRef = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestConfig"); DocumentReference searchConfigClass = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "SearchSuggestSourceClass"); XWikiDocument searchConfigDoc = xwiki.getDocument(searchConfigDocRef, xcontext); List<BaseObject> objects = searchConfigDoc.getXObjects(searchConfigClass); if (objects != null) { boolean found = false; for (BaseObject object : objects) { if (object == null) { continue; } String name = object.getStringValue("name"); if (name.equals("platform.workspace.searchSuggestSourceWorkspaces")) { String query = object.getStringValue("query"); String engine = object.getStringValue("engine"); String url = object.getStringValue("url"); if (isSolrObject(query, engine, url) || isLuceneObject(query, engine, url)) { searchConfigDoc.removeXObject(object); found = true; } } } if (found) { xwiki.saveDocument(searchConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext); } } }  @Override void deleteSearchSuggestCustomConfig(String wikiId);  }