Search in sources :

Example 96 with XWikiDocument

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);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 97 with XWikiDocument

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");
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 98 with XWikiDocument

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));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 99 with XWikiDocument

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));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) List(java.util.List) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 100 with XWikiDocument

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);
    }
}
Also used : WikiTemplatePropertyGroup(org.xwiki.wiki.template.WikiTemplatePropertyGroup) WikiPropertyGroupException(org.xwiki.wiki.properties.WikiPropertyGroupException) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)869 DocumentReference (org.xwiki.model.reference.DocumentReference)469 BaseObject (com.xpn.xwiki.objects.BaseObject)318 Test (org.junit.Test)284 XWikiContext (com.xpn.xwiki.XWikiContext)232 XWikiException (com.xpn.xwiki.XWikiException)178 ArrayList (java.util.ArrayList)99 XWiki (com.xpn.xwiki.XWiki)97 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)86 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)71 Document (com.xpn.xwiki.api.Document)48 EntityReference (org.xwiki.model.reference.EntityReference)48 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)41 Date (java.util.Date)41 IOException (java.io.IOException)40 HashMap (java.util.HashMap)33 QueryException (org.xwiki.query.QueryException)27 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)25 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)23 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)23