use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class DefaultWikiComponentBuilderEventListener method installOrUpdateComponentRequirementXClass.
/**
* Verify that the {@link #DEPENDENCY_CLASS} exists and is up-to-date (act if not).
*
* @throws XWikiException on failure
*/
private void installOrUpdateComponentRequirementXClass() throws XWikiException {
XWikiContext xcontext = getXWikiContext();
XWikiDocument doc = xcontext.getWiki().getDocument(DEPENDENCY_CLASS_REFERENCE, xcontext);
BaseClass bclass = doc.getXClass();
bclass.setDocumentReference(doc.getDocumentReference());
boolean needsUpdate = false;
needsUpdate |= this.initializeXClassDocumentMetadata(doc, "Wiki Component Dependency XWiki Class");
needsUpdate |= bclass.addTextField(COMPONENT_ROLE_TYPE_FIELD, "Dependency Role Type", 30);
needsUpdate |= bclass.addTextField(COMPONENT_ROLE_HINT_FIELD, "Dependency Role Hint", 30);
needsUpdate |= bclass.addTextField(DEPENDENCY_BINDING_NAME_FIELD, "Binding name", 30);
if (needsUpdate) {
this.update(doc);
}
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method testInstallOnWikiWithoutAuthor.
@Test
public void testInstallOnWikiWithoutAuthor() throws Throwable {
XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
BaseObject object = new BaseObject();
object.setXClassReference(new DocumentReference("wiki", "space", "class"));
existingDocument.addXObject(object);
existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
this.oldcore.getSpyXWiki().saveDocument(existingDocument, "", true, getXWikiContext());
// install
install(this.localXarExtensiontId1, "wiki", null);
// validate
DocumentReference xarAuthorReference = new DocumentReference("wiki", "XWiki", "author");
DocumentReference xarCreatorReference = new DocumentReference("wiki", "XWiki", "creator");
DocumentReference xarContentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor");
// space.page
XWikiDocument page = this.oldcore.getSpyXWiki().getDocument(existingDocument.getDocumentReference(), getXWikiContext());
Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());
Assert.assertNull(page.getXObject(object.getXClassReference()));
Assert.assertEquals("Wrong content", "content", page.getContent());
Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"), page.getCreatorReference());
Assert.assertEquals("Wrong author", xarAuthorReference, page.getAuthorReference());
Assert.assertEquals("Wrong content author", xarContentAuthorReference, page.getContentAuthorReference());
Assert.assertEquals("Wrong version", "2.1", page.getVersion());
Assert.assertEquals("Wrong version", Locale.ROOT, page.getLocale());
Assert.assertFalse("Document is hidden", page.isHidden());
BaseClass baseClass = page.getXClass();
Assert.assertNotNull(baseClass.getField("property"));
Assert.assertEquals("property", baseClass.getField("property").getName());
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
// space.pagewithattachment
XWikiDocument pagewithattachment = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getXWikiContext());
Assert.assertFalse(pagewithattachment.isNew());
Assert.assertEquals("Wrong version", "1.1", pagewithattachment.getVersion());
Assert.assertEquals("Wrong creator", xarCreatorReference, pagewithattachment.getCreatorReference());
Assert.assertEquals("Wrong author", xarAuthorReference, pagewithattachment.getAuthorReference());
Assert.assertEquals("Wrong content author", xarContentAuthorReference, pagewithattachment.getContentAuthorReference());
XWikiAttachment attachment = pagewithattachment.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));
Assert.assertEquals(new DocumentReference("wiki", "XWiki", "attachmentauthor"), attachment.getAuthorReference());
// space1.page1
XWikiDocument page1 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext());
Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());
// translated.translated
DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
XWikiDocument defaultTranslated = this.oldcore.getSpyXWiki().getDocument(translatedReference, getXWikiContext());
Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database", defaultTranslated);
Assert.assertFalse("Document wiki:translated.translated has not been saved in the database", defaultTranslated.isNew());
Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
Assert.assertEquals("Wrong creator", xarCreatorReference, defaultTranslated.getCreatorReference());
Assert.assertEquals("Wrong author", xarAuthorReference, defaultTranslated.getAuthorReference());
Assert.assertEquals("Wrong content author", xarContentAuthorReference, defaultTranslated.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());
// translated.translated.tr
XWikiDocument translated = this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("tr")));
Assert.assertNotNull("Document wiki:translated.translated in langauge tr has not been saved in the database", translated);
Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database", translated.isNew());
Assert.assertEquals("Wrong content", "tr content", translated.getContent());
Assert.assertEquals("Wrong creator", xarCreatorReference, translated.getCreatorReference());
Assert.assertEquals("Wrong author", xarAuthorReference, translated.getAuthorReference());
Assert.assertEquals("Wrong content author", xarContentAuthorReference, translated.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", translated.getVersion());
// translated.translated.fr
XWikiDocument translated2 = this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("fr")));
Assert.assertNotNull("Document wiki:translated.translated in language fr has not been saved in the database", translated2);
Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database", translated2.isNew());
Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
Assert.assertEquals("Wrong creator", xarCreatorReference, translated2.getCreatorReference());
Assert.assertEquals("Wrong author", xarAuthorReference, translated2.getAuthorReference());
Assert.assertEquals("Wrong content author", xarContentAuthorReference, translated2.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());
// space.hiddenpage
XWikiDocument hiddenpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "hiddenpage"), getXWikiContext());
Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());
Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}
use of com.xpn.xwiki.objects.classes.BaseClass 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 com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method setUp.
@Before
public void setUp() throws Exception {
// mock
this.contextUser = new DocumentReference(getXWikiContext().getWikiId(), "XWiki", "ExtensionUser");
this.localXarExtensiontId1 = new ExtensionId("test", "1.0");
this.localXarExtensiontId2 = new ExtensionId("test", "2.0");
this.collisionextension1 = new ExtensionId("collisionextension1", "version");
this.collisionextension2 = new ExtensionId("collisionextension2", "version");
// classes
BaseClass styleSheetClass = new BaseClass();
this.classes.put("StyleSheetExtension", styleSheetClass);
// checking
doReturn(true).when(this.oldcore.getSpyXWiki()).hasAttachmentRecycleBin(any(XWikiContext.class));
getXWikiContext().setUserReference(this.contextUser);
((XWikiStubContextProvider) this.componentManager.getInstance(XWikiStubContextProvider.class)).initialize(getXWikiContext());
CoreConfiguration coreConfiguration = this.componentManager.getInstance(CoreConfiguration.class);
doReturn(Syntax.PLAIN_1_0).when(coreConfiguration).getDefaultDocumentSyntax();
// lookup
this.jobExecutor = this.componentManager.getInstance(JobExecutor.class);
this.xarExtensionRepository = this.componentManager.getInstance(InstalledExtensionRepository.class, XarExtensionHandler.TYPE);
this.observation = this.repositoryUtil.getComponentManager().getInstance(ObservationManager.class);
// Get rid of wiki macro listener
this.componentManager.<ObservationManager>getInstance(ObservationManager.class).removeListener("RegisterMacrosOnImportListener");
this.installedExtensionRepository = this.componentManager.getInstance(InstalledExtensionRepository.class, "xar");
// Programming right is not required for XAR extensions
doThrow(AccessDeniedException.class).when(this.oldcore.getMockAuthorizationManager()).checkAccess(eq(Right.PROGRAM), any(), any());
}
use of com.xpn.xwiki.objects.classes.BaseClass in project xwiki-platform by xwiki.
the class XarExtensionHandlerTest method testDowngradeOnWiki.
@Test
public void testDowngradeOnWiki() throws Throwable {
install(this.localXarExtensiontId2, "wiki", this.contextUser);
verifyHasAdminRight(1);
// upgrade
install(this.localXarExtensiontId1, "wiki", this.contextUser);
verifyHasAdminRight(3);
// validate
// samespace.samepage
XWikiDocument samepage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext());
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion());
// space.page
XWikiDocument modifiedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext());
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew());
Assert.assertEquals("Wrong content", "content", 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());
BaseClass baseClass = modifiedpage.getXClass();
Assert.assertNotNull(baseClass.getField("property"));
Assert.assertEquals("property", baseClass.getField("property").getName());
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
// The attachment does not exist in version 1.0
Assert.assertNull(modifiedpage.getAttachment("attachment.txt"));
// space2.page2
XWikiDocument newPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space2", "page2"), getXWikiContext());
Assert.assertTrue("Document wiki.space2.page2 has not been removed from the database", newPage.isNew());
// space1.page1
XWikiDocument removedPage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext());
Assert.assertFalse("Document wiki.space1.page1 has not been saved in the database", removedPage.isNew());
}
Aggregations