Search in sources :

Example 1 with DefaultLocalExtension

use of org.xwiki.extension.repository.internal.local.DefaultLocalExtension in project xwiki-platform by xwiki.

the class JARTranslationBundleFactoryTest method mockInstalledExtension.

private DefaultInstalledExtension mockInstalledExtension(ExtensionId extensionId, String namespace) {
    DefaultLocalExtension localExtension = new DefaultLocalExtension(null, extensionId, "jar");
    localExtension.setFile(this.extensionPackager.getExtensionFile(extensionId));
    DefaultInstalledExtension installedExtension = new DefaultInstalledExtension(localExtension, null);
    installedExtension.setInstalled(true, namespace);
    return installedExtension;
}
Also used : DefaultLocalExtension(org.xwiki.extension.repository.internal.local.DefaultLocalExtension) DefaultInstalledExtension(org.xwiki.extension.repository.internal.installed.DefaultInstalledExtension)

Example 2 with DefaultLocalExtension

use of org.xwiki.extension.repository.internal.local.DefaultLocalExtension in project xwiki-platform by xwiki.

the class ImportTest method testImportExtension.

/**
 * Test the regular document import when the XAR is tagged as extension.
 *
 * @throws Exception
 */
public void testImportExtension() throws Exception {
    ExtensionId extensionId = new ExtensionId("test", "1.0");
    XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport"));
    doc1.setDefaultLanguage("en");
    byte[] zipFile = this.createZipFile(new XWikiDocument[] { doc1 }, new String[] { "ISO-8859-1" }, extensionId);
    // Store the extension in the local repository
    DefaultLocalExtension localExtension = new DefaultLocalExtension(null, extensionId, "xar");
    File file = File.createTempFile("temp", ".xar");
    FileUtils.writeByteArrayToFile(file, zipFile);
    localExtension.setFile(file);
    LocalExtensionRepository localeRepository = getComponentManager().getInstance(LocalExtensionRepository.class);
    localeRepository.storeExtension(localExtension);
    // Listen to extension installed event
    Mock extensionListener = mock(EventListener.class);
    extensionListener.stubs().method("getEvents").will(returnValue(Arrays.asList(new ExtensionInstalledEvent())));
    extensionListener.stubs().method("getName").will(returnValue("extension installed listener"));
    extensionListener.expects(once()).method("onEvent");
    ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class);
    observationManager.addListener((EventListener) extensionListener.proxy());
    // make sure no data is in the packager from the other tests run
    this.pack = new Package();
    // import and install this document
    this.pack.Import(zipFile, getContext());
    this.pack.install(getContext());
    // check if it is there
    XWikiDocument foundDocument = this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImport"), getContext());
    assertFalse(foundDocument.isNew());
    XWikiDocument nonExistingDocument = this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext());
    assertTrue(nonExistingDocument.isNew());
    XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext());
    assertSame(foundDocument, foundTranslationDocument);
    XWikiDocument doc1Translation = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport"));
    doc1Translation.setLanguage("fr");
    doc1Translation.setDefaultLanguage("en");
    this.xwiki.saveDocument(doc1Translation, getContext());
    foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext());
    assertNotSame(foundDocument, foundTranslationDocument);
    // Check that the extension has been registered
    InstalledExtensionRepository installedExtensionRepository = getComponentManager().getInstance(InstalledExtensionRepository.class);
    assertNotNull(installedExtensionRepository.getInstalledExtension(extensionId));
    assertNotNull(installedExtensionRepository.getInstalledExtension(extensionId.getId(), "wiki:" + getContext().getWikiId()));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) LocalExtensionRepository(org.xwiki.extension.repository.LocalExtensionRepository) ExtensionId(org.xwiki.extension.ExtensionId) ObservationManager(org.xwiki.observation.ObservationManager) DefaultLocalExtension(org.xwiki.extension.repository.internal.local.DefaultLocalExtension) File(java.io.File) DocumentReference(org.xwiki.model.reference.DocumentReference) Mock(org.jmock.Mock) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) ExtensionInstalledEvent(org.xwiki.extension.event.ExtensionInstalledEvent)

Aggregations

DefaultLocalExtension (org.xwiki.extension.repository.internal.local.DefaultLocalExtension)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 File (java.io.File)1 Mock (org.jmock.Mock)1 ExtensionId (org.xwiki.extension.ExtensionId)1 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)1 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)1 LocalExtensionRepository (org.xwiki.extension.repository.LocalExtensionRepository)1 DefaultInstalledExtension (org.xwiki.extension.repository.internal.installed.DefaultInstalledExtension)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ObservationManager (org.xwiki.observation.ObservationManager)1