@Test public void testUpgradeOnRoot() throws Throwable { doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getWikiDescriptorManager()).getAllIds(); install(this.localXarExtensiontId1, null, this.contextUser); verifyHasAdminRight(3); 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"); install(this.localXarExtensiontId2, null, this.contextUser); verifyHasAdminRight(6); XWikiDocument samepage = this.oldcore.getSpyXWiki() .getDocument(new DocumentReference("wiki1", "samespace", "samepage"), getXWikiContext()); Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion()); 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)); 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()); XWikiDocument removedPage = this.oldcore.getSpyXWiki() .getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()); assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew()); deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "deletedpage"), getXWikiContext()); assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew()); modifieddeletedpage = this.oldcore.getSpyXWiki() .getDocument(new DocumentReference("wiki1", "space", "modifieddeletedpage"), getXWikiContext()); assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew()); 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"))); 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()); }
@Override public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException { if (!request.isRemote()) { String wiki; try { wiki = XarHandlerUtils.getWikiFromNamespace(namespace); } catch (UnsupportedNamespaceException e) { throw new InstallException("Failed to extract wiki id from namespace", e); } installInternal(localExtension, wiki, request); } }
XarExtensionHandler extends AbstractExtensionHandler { @Override public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException { if (!request.isRemote()) { String wiki; try { wiki = XarHandlerUtils.getWikiFromNamespace(namespace); } catch (UnsupportedNamespaceException e) { throw new InstallException("Failed to extract wiki id from namespace", e); } installInternal(localExtension, wiki, request); } } }
XarExtensionHandler extends AbstractExtensionHandler { @Override public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException { if (!request.isRemote()) { String wiki; try { wiki = XarHandlerUtils.getWikiFromNamespace(namespace); } catch (UnsupportedNamespaceException e) { throw new InstallException("Failed to extract wiki id from namespace", e); } installInternal(localExtension, wiki, request); } }  }
XarExtensionHandler extends AbstractExtensionHandler { @Override public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException { if (!request.isRemote()) { String wiki; try { wiki = XarHandlerUtils.getWikiFromNamespace(namespace); } catch (UnsupportedNamespaceException e) { throw new InstallException("Failed to extract wiki id from namespace", e); } installInternal(localExtension, wiki, request); } }  @Override void install(LocalExtension localExtension, String namespace, Request request); @Override void upgrade(Collection<InstalledExtension> previousLocalExtensions, LocalExtension newLocalExtension,
        String namespace, Request request); @Override void uninstall(InstalledExtension installedExtension, String namespace, Request request); }
XarExtensionHandler extends AbstractExtensionHandler { @Override public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException { if (!request.isRemote()) { String wiki; try { wiki = XarHandlerUtils.getWikiFromNamespace(namespace); } catch (UnsupportedNamespaceException e) { throw new InstallException("Failed to extract wiki id from namespace", e); } installInternal(localExtension, wiki, request); } }  @Override void install(LocalExtension localExtension, String namespace, Request request); @Override void upgrade(Collection<InstalledExtension> previousLocalExtensions, LocalExtension newLocalExtension,
        String namespace, Request request); @Override void uninstall(InstalledExtension installedExtension, String namespace, Request request); static final String TYPE; }