use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class DefaultSearchSuggestCustomConfigDeleterTest method deleteSearchSuggestCustomConfig.
@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);
// null objects can be present in the list
objects.add(null);
objects.add(objConfig4);
objects.add(objConfig5);
objects.add(objConfig6);
when(searchSuggestConfigDoc.getXObjects(eq(new DocumentReference("mainWiki", "XWiki", "SearchSuggestSourceClass")))).thenReturn(objects);
// Object 1
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");
// Object 2
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");
// Object 3
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");
// Object 4
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");
// Object 5
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");
// Object 6
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");
// Run
mocker.getComponentUnderTest().deleteSearchSuggestCustomConfig("mainWiki");
// Verify that the good objects has been removed
verify(searchSuggestConfigDoc).removeXObject(objConfig1);
verify(searchSuggestConfigDoc).removeXObject(objConfig3);
// Verify that the document have been saved
verify(xwiki).saveDocument(searchSuggestConfigDoc, "Remove object previously introduced by WorkspaceManager.Install", xcontext);
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class WorkspaceMigrationTest method upgradeWorkspaceTemplate.
@Test
public void upgradeWorkspaceTemplate() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspacetemplate");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspacetemplate")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Mock that the workspace special page exists
DocumentReference workspacePageReference = new DocumentReference("workspacetemplate", "XWiki", "ManageWorkspace");
when(xwiki.exists(eq(workspacePageReference), any(XWikiContext.class))).thenReturn(true);
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify that the log contains a warning about the documents that the migration failed to restore
verify(mocker.getMockedLogger()).warn("Failed to restore some documents: [{}]. You should import manually " + "(1) xwiki-platform-administration-ui.xar and then (2) xwiki-platform-wiki-ui-wiki.xar into your" + " wiki, to restore these documents.", "workspacetemplate:XWiki.AdminRegistrationSheet, " + "workspacetemplate:XWiki.RegistrationConfig, workspacetemplate:XWiki.RegistrationHelp, " + "workspacetemplate:XWiki.AdminUsersSheet");
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class WorkspaceMigrationTest method upgradeRegularSubwiki.
@Test
public void upgradeRegularSubwiki() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerSubwiki")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify that the migration did not try to restore old documents
verify(xwiki, never()).exists(eq(new DocumentReference("subwiki", "XWiki", "AdminRegistrationSheet")), any(XWikiContext.class));
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class WorkspaceMigrationTest method errorWhenRestoringFromXAR.
@Test
public void errorWhenRestoringFromXAR() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspace");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspace")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Mocks about the old workspace object
BaseObject oldWorkspaceObject = mock(BaseObject.class);
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(oldWorkspaceObject);
doThrow(new XWikiException()).when(documentRestorerFromAttachedXAR).restoreDocumentFromAttachedXAR(any(DocumentReference.class), any(String.class), any(List.class));
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify
verify(mocker.getMockedLogger()).error(eq("Error while restoring documents from the Workspace XAR"), any(XWikiException.class));
}
use of com.xpn.xwiki.doc.XWikiDocument in project xwiki-platform by xwiki.
the class WikiTemplatePropertyGroupProvider method save.
@Override
public void save(WikiPropertyGroup group, String wikiId) throws WikiPropertyGroupException {
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
WikiTemplatePropertyGroup templateGroup = (WikiTemplatePropertyGroup) group;
try {
XWikiDocument descriptorDocument = wikiDescriptorDocumentHelper.getDocumentFromWikiId(wikiId);
BaseObject object = descriptorDocument.getXObject(WikiTemplateClassDocumentInitializer.SERVER_CLASS, true, context);
object.setIntValue(WikiTemplateClassDocumentInitializer.FIELD_ISWIKITEMPLATE, templateGroup.isTemplate() ? 1 : 0);
// The document must have a creator
if (descriptorDocument.getCreatorReference() == null) {
descriptorDocument.setCreatorReference(context.getUserReference());
}
// The document must have an author
if (descriptorDocument.getAuthorReference() == null) {
descriptorDocument.setAuthorReference(context.getUserReference());
}
xwiki.saveDocument(descriptorDocument, String.format("Changed property group [%s].", GROUP_NAME), context);
} catch (WikiManagerException e) {
throw new WikiPropertyGroupException(String.format(ERROR_MESSAGE_NO_DESCRIPTOR_DOCUMENT, wikiId), e);
} catch (XWikiException e) {
throw new WikiPropertyGroupException("Unable to save descriptor document.", e);
}
}
Aggregations