@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(this.localXarExtensiontId1, "wiki", null); DocumentReference xarAuthorReference = new DocumentReference("wiki", "XWiki", "author"); DocumentReference xarCreatorReference = new DocumentReference("wiki", "XWiki", "creator"); DocumentReference xarContentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor"); 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()); 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()); 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()); 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()); 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()); 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()); 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()); assertTrue("Document is not hidden", hiddenpage.isHidden()); }
@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; }