Search in sources :

Example 26 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class ExtensionInstallerTest method installExtensionWithException.

@Test
public void installExtensionWithException() throws Exception {
    // Test
    WikiCreationException caughtException = null;
    try {
        mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
    } catch (WikiCreationException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to install the extension [extensionId/version] on the wiki [wikiId].", caughtException.getMessage());
    assertTrue(caughtException.getCause() instanceof ComponentLookupException);
}
Also used : WikiCreationException(org.xwiki.platform.wiki.creationjob.WikiCreationException) ExtensionId(org.xwiki.extension.ExtensionId) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) Test(org.junit.Test)

Example 27 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class ProvisionWikiStepTest method executeWhenSourceIsExtension.

@Test
public void executeWhenSourceIsExtension() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    verify(extensionInstaller).installExtension(eq("wikiId"), eq(extensionId));
    verify(observationManager).notify(eq(new WikiProvisioningEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verify(observationManager).notify(eq(new WikiProvisionedEvent("wikiId")), eq("wikiId"), eq(xcontext));
    verifyZeroInteractions(wikiCopier);
}
Also used : WikiProvisionedEvent(org.xwiki.bridge.event.WikiProvisionedEvent) WikiProvisioningEvent(org.xwiki.bridge.event.WikiProvisioningEvent) WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test)

Example 28 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class SaveWikiMetaDataStepTest method execute.

@Test
public void execute() throws Exception {
    WikiCreationRequest request = new WikiCreationRequest();
    request.setWikiId("wikiId");
    request.setDescription("description");
    request.setPrettyName("pretty name");
    request.setOwnerId("ownerId");
    request.setTemplate(false);
    request.setUserScope(UserScope.GLOBAL_ONLY);
    request.setMembershipType(MembershipType.INVITE);
    request.setWikiSource(WikiSource.EXTENSION);
    ExtensionId extensionId = new ExtensionId("id", "version");
    request.setExtensionId(extensionId);
    // Mock
    WikiDescriptor descriptor = new WikiDescriptor("wikiId", "alias");
    when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor);
    // Test
    mocker.getComponentUnderTest().execute(request);
    // Verify
    assertEquals("description", descriptor.getDescription());
    assertEquals("pretty name", descriptor.getPrettyName());
    assertEquals("ownerId", descriptor.getOwnerId());
    verify(wikiDescriptorManager).saveDescriptor(descriptor);
    verify(wikiTemplateManager).setTemplate("wikiId", false);
    verify(wikiUserManager).setUserScope("wikiId", UserScope.GLOBAL_ONLY);
    verify(wikiUserManager).setMembershipType("wikiId", MembershipType.INVITE);
}
Also used : WikiCreationRequest(org.xwiki.platform.wiki.creationjob.WikiCreationRequest) ExtensionId(org.xwiki.extension.ExtensionId) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 29 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class WikiCreationJobScriptServicesTest method setUp.

@Before
public void setUp() throws Exception {
    wikiCreator = mocker.getInstance(WikiCreator.class);
    execution = mocker.getInstance(Execution.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    distributionManager = mocker.getInstance(DistributionManager.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWikiId");
    ExecutionContext executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    ExtensionId extensionId = new ExtensionId("authorized-extension", "1.0");
    when(distributionManager.getWikiUIExtensionId()).thenReturn(extensionId);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) WikiCreator(org.xwiki.platform.wiki.creationjob.WikiCreator) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExtensionId(org.xwiki.extension.ExtensionId) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DistributionManager(org.xwiki.extension.distribution.internal.DistributionManager) Before(org.junit.Before)

Example 30 with ExtensionId

use of org.xwiki.extension.ExtensionId in project xwiki-platform by xwiki.

the class ExtensionInstanceOutputFilterStream method endExtension.

@Override
public void endExtension(String id, String version, FilterEventParameters parameters) throws FilterException {
    // TODO: add support for complete extension
    ExtensionId extensionId = new ExtensionId(id, factory.getVersion(version));
    try {
        LocalExtension localExtension = this.localRepository.getLocalExtension(extensionId);
        if (localExtension == null) {
            Extension extension;
            try {
                // Try to find and download the extension from a repository
                extension = this.extensionRepository.resolve(extensionId);
            } catch (ResolveException e) {
                this.logger.debug("Can't find extension [{}]", extensionId, e);
                // FIXME: Create a dummy extension. Need support for partial/lazy extension.
                return;
            }
            localExtension = this.localRepository.storeExtension(extension);
        }
        String namespace = getCurrentNamespace();
        // TODO: should probably make it configurable
        if (installedRepository.getInstalledExtension(localExtension.getId().getId(), namespace) == null) {
            for (ExtensionId feature : localExtension.getExtensionFeatures()) {
                if (installedRepository.getInstalledExtension(feature.getId(), namespace) != null) {
                    // Already exist so don't register it or it could create a mess
                    return;
                }
            }
        } else {
            return;
        }
        // Register the extension as installed
        installedRepository.installExtension(localExtension, namespace, false);
    } catch (Exception e) {
        this.logger.error("Failed to register extenion [{}] from the XAR", extensionId, e);
    }
}
Also used : Extension(org.xwiki.extension.Extension) LocalExtension(org.xwiki.extension.LocalExtension) ResolveException(org.xwiki.extension.ResolveException) LocalExtension(org.xwiki.extension.LocalExtension) ExtensionId(org.xwiki.extension.ExtensionId) IOException(java.io.IOException) ResolveException(org.xwiki.extension.ResolveException) FilterException(org.xwiki.filter.FilterException)

Aggregations

ExtensionId (org.xwiki.extension.ExtensionId)67 Test (org.junit.Test)37 InstalledExtension (org.xwiki.extension.InstalledExtension)13 ExtensionAdministrationPage (org.xwiki.extension.test.po.ExtensionAdministrationPage)11 TestExtension (org.xwiki.repository.test.TestExtension)11 ExtensionPane (org.xwiki.extension.test.po.ExtensionPane)9 DocumentReference (org.xwiki.model.reference.DocumentReference)9 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)8 Extension (org.xwiki.extension.Extension)7 InstallRequest (org.xwiki.extension.job.InstallRequest)6 DefaultVersionConstraint (org.xwiki.extension.version.internal.DefaultVersionConstraint)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 IOException (java.io.IOException)5 DefaultExtensionDependency (org.xwiki.extension.DefaultExtensionDependency)5 SearchResultsPane (org.xwiki.extension.test.po.SearchResultsPane)5 ViewPage (org.xwiki.test.ui.po.ViewPage)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 ResolveException (org.xwiki.extension.ResolveException)4 DependencyPane (org.xwiki.extension.test.po.DependencyPane)4 LogItemPane (org.xwiki.extension.test.po.LogItemPane)4