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());
}
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;
}
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());
}
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();
}
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"));
}
Aggregations