Search in sources :

Example 11 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XarExtensionHandlerTest method testUpgradeOnRoot.

@Test
public void testUpgradeOnRoot() throws Throwable {
    doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getWikiDescriptorManager()).getAllIds();
    install(this.localXarExtensiontId1, null, this.contextUser);
    verifyHasAdminRight(2);
    // Do some local modifications
    XWikiDocument deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "deletedpage"), getXWikiContext());
    this.oldcore.getSpyXWiki().deleteDocument(deletedpage, getXWikiContext());
    XWikiDocument modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "modifieddeletedpage"), getXWikiContext());
    this.oldcore.getSpyXWiki().deleteDocument(modifieddeletedpage, getXWikiContext());
    XWikiDocument pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "pagewithobject"), getXWikiContext());
    pagewithobject.removeXObjects(new LocalDocumentReference("XWiki", "XWikiGroups"));
    this.oldcore.getSpyXWiki().saveDocument(pagewithobject, getXWikiContext());
    XWikiDocument deletedpagewithmodifications = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "modified"), getXWikiContext());
    deletedpagewithmodifications.setContent("modified content");
    // upgrade
    install(this.localXarExtensiontId2, null, this.contextUser);
    verifyHasAdminRight(3);
    // validate
    // samespace.samepage
    XWikiDocument samepage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "samespace", "samepage"), getXWikiContext());
    Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion());
    // space.page
    XWikiDocument modifiedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext());
    Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew());
    Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent());
    Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference());
    Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion());
    Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale());
    Assert.assertEquals("Wrong customclass", "customclass2", modifiedpage.getCustomClass());
    Assert.assertEquals("Wrong defaultTemplate", "defaultTemplate2", modifiedpage.getDefaultTemplate());
    Assert.assertEquals("Wrong hidden", true, modifiedpage.isHidden());
    Assert.assertEquals("Wrong ValidationScript", "validationScript2", modifiedpage.getValidationScript());
    BaseClass baseClass = modifiedpage.getXClass();
    Assert.assertNotNull(baseClass.getField("property"));
    Assert.assertEquals("property", baseClass.getField("property").getName());
    Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
    XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt");
    Assert.assertNotNull(attachment);
    Assert.assertEquals("attachment.txt", attachment.getFilename());
    Assert.assertEquals(18, attachment.getContentLongSize(getXWikiContext()));
    Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getXWikiContext()), StandardCharsets.UTF_8));
    // space2.page2
    XWikiDocument newPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space2", "page2"), getXWikiContext());
    Assert.assertFalse("Document wiki:space2.page2 has not been saved in the database", newPage.isNew());
    // space1.page1
    XWikiDocument removedPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext());
    Assert.assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew());
    // space.deletedpage
    deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "deletedpage"), getXWikiContext());
    Assert.assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew());
    // space.modifieddeletedpage
    modifieddeletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "modifieddeletedpage"), getXWikiContext());
    Assert.assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew());
    // space.pagewithobject
    pagewithobject = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "pagewithobject"), getXWikiContext());
    Assert.assertNull("Document wiki:space.pagewithobject does not contain an XWiki.XWikiGroups object", pagewithobject.getXObject(new LocalDocumentReference("XWiki", "XWikiGroups")));
    // space1.modified
    XWikiDocument space1modified = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "modified"), getXWikiContext());
    Assert.assertFalse("Document wiki:space1.modified has been removed from the database", space1modified.isNew());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 12 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XarInstalledExtensionRepository method getXarInstalledExtensions.

/**
 * @param reference the reference of the document
 * @return the extension owners of the passed document
 * @since 8.1M2
 */
public Collection<XarInstalledExtension> getXarInstalledExtensions(DocumentReference reference) {
    if (reference instanceof DocumentVersionReference) {
        DocumentVersionReference versionReference = (DocumentVersionReference) reference;
        if (versionReference.getVersion() instanceof ExtensionId) {
            ExtensionId extensionId = (ExtensionId) versionReference.getVersion();
            if (extensionId != null) {
                return Arrays.asList((XarInstalledExtension) getInstalledExtension(extensionId));
            }
        }
    }
    Collection<XarInstalledExtension> wikiExtensions = this.documents.get(reference.getLocale() == null ? new DocumentReference(reference, Locale.ROOT) : reference);
    Collection<XarInstalledExtension> rootExtensions = this.rootDocuments.get(reference.getLocalDocumentReference().getLocale() == null ? new LocalDocumentReference(reference.getLocalDocumentReference(), Locale.ROOT) : reference.getLocalDocumentReference());
    List<XarInstalledExtension> allExtensions = new ArrayList<>();
    if (wikiExtensions != null) {
        allExtensions.addAll(wikiExtensions);
    }
    if (rootExtensions != null) {
        allExtensions.addAll(rootExtensions);
    }
    return allExtensions;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentVersionReference(org.xwiki.extension.xar.job.diff.DocumentVersionReference) ArrayList(java.util.ArrayList) ExtensionId(org.xwiki.extension.ExtensionId) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 13 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XWikiAuthServiceImplTest method testLogintoVirtualXwikiWithWikiPrefixUsername.

/**
 * Test that user is authenticated with a global account when a local one with the same name exists and the username
 * contains a wiki prefix.
 */
@Test
public void testLogintoVirtualXwikiWithWikiPrefixUsername() throws Exception {
    // Setup simple user profile documents
    XWikiDocument userDocLocal = new XWikiDocument(new DocumentReference(this.oldcore.getXWikiContext().getMainXWiki(), "XWiki", "Admin"));
    BaseObject mockUserObj = userDocLocal.newXObject(new LocalDocumentReference("XWiki", "XWikiUsers"), this.oldcore.getXWikiContext());
    mockUserObj.setStringValue("password", "admin");
    // Save the user
    this.oldcore.getSpyXWiki().saveDocument(userDocLocal, this.oldcore.getXWikiContext());
    // Run the test: Using XWiki.Admin should correctly authenticate the Admin user
    Principal principalLocal = this.authService.authenticate("XWiki.Admin", "admin", this.oldcore.getXWikiContext());
    assertNotNull(principalLocal);
    assertEquals("XWiki.Admin", principalLocal.getName());
    // Set the database name to local.
    this.oldcore.getXWikiContext().setWikiId("local");
    // Finally run the test: Using xwiki:Xwiki.Admin should correctly authenticate the Admin user
    Principal principalVirtual = this.authService.authenticate("xwiki:XWiki.Admin", "admin", this.oldcore.getXWikiContext());
    assertNotNull(principalVirtual);
    assertEquals("xwiki:XWiki.Admin", principalVirtual.getName());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Principal(java.security.Principal) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 14 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class ApplicationsPanelAdministrationTest method createApplicationUIX.

private void createApplicationUIX(String applicationName) {
    getUtil().deletePage(new LocalDocumentReference(Arrays.asList("Apps", applicationName), "WebHome"));
    ViewPage page = getUtil().gotoPage("Apps", applicationName);
    ObjectEditPage editPage = page.editObjects();
    ObjectEditPane object = editPage.addObject("XWiki.UIExtensionClass");
    fillField(object, "extensionPointId", "org.xwiki.platform.panels.Applications");
    fillField(object, "name", applicationName);
    fillField(object, "parameters", String.format("label=%s\ntarget=Apps.%s\nicon=icon:home", applicationName, applicationName));
    editPage.clickSaveAndView();
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) ObjectEditPane(org.xwiki.test.ui.po.editor.ObjectEditPane) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage)

Example 15 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class ApplicationsPanelAdministrationTest method cleanUp.

private void cleanUp() throws Exception {
    getUtil().rest().delete(new LocalDocumentReference(Arrays.asList("Apps", "App1"), "WebHome"));
    getUtil().rest().delete(new LocalDocumentReference(Arrays.asList("Apps", "App2"), "WebHome"));
    getUtil().rest().delete(new LocalDocumentReference(Arrays.asList("Apps", "App3"), "WebHome"));
    getUtil().rest().delete(new LocalDocumentReference(Arrays.asList("PanelsCode"), "ApplicationsPanelConfiguration"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2