Search in sources :

Example 1 with InstalledExtensionRepository

use of org.xwiki.extension.repository.InstalledExtensionRepository in project xwiki-platform by xwiki.

the class ExtensionManagerScriptServiceTest method testOverwriteAllowedNamespaces.

@Test
public void testOverwriteAllowedNamespaces() throws Throwable {
    InstallRequest installRequest = this.scriptService.createInstallRequest("extension", "version", "namespace");
    // Indicate all extensions of type "test" should be installed on root
    ((ScriptExtensionRewriter) installRequest.getRewriter()).installExtensionTypeOnRootNamespace("test");
    // Allow redirect on root
    installRequest.setRootModificationsAllowed(true);
    Job job = this.scriptService.install(installRequest);
    if (job == null) {
        throw this.scriptService.getLastError();
    }
    job.join();
    List<LogEvent> errors = job.getStatus().getLog().getLogsFrom(LogLevel.WARN);
    if (!errors.isEmpty()) {
        throw errors.get(0).getThrowable();
    }
    // Validate
    InstalledExtensionRepository repository = mocker.getInstance(InstalledExtensionRepository.class);
    assertNotNull(repository.getInstalledExtension("extension", null));
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) InstallRequest(org.xwiki.extension.job.InstallRequest) Job(org.xwiki.job.Job) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 2 with InstalledExtensionRepository

use of org.xwiki.extension.repository.InstalledExtensionRepository in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLWithoutVersion.

@Test
public void computeURLWithoutVersion() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css"));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 3 with InstalledExtensionRepository

use of org.xwiki.extension.repository.InstalledExtensionRepository in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLWithParametersAndWikiIsNotSpecifiedInParameter.

@Test
public void computeURLWithParametersAndWikiIsNotSpecifiedInParameter() throws Exception {
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("math");
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.<String, Object>emptyMap()));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 4 with InstalledExtensionRepository

use of org.xwiki.extension.repository.InstalledExtensionRepository in project xwiki-platform by xwiki.

the class WebJarsScriptServiceTest method computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter.

@Test
public void computeURLForBackwardCompatibilityWhenWikiIsSpecifiedAsParameter() throws Exception {
    InstalledExtensionRepository installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
    InstalledExtension extension = mock(InstalledExtension.class);
    when(installedExtensionRepository.getInstalledExtension("org.webjars:angular", "wiki:math")).thenReturn(extension);
    when(extension.getId()).thenReturn(new ExtensionId("bar", "2.1.11"));
    WebJarsResourceReference resourceReference = new WebJarsResourceReference("wiki:math", Arrays.asList("angular", "2.1.11", "angular.css"));
    when(this.serializer.serialize(resourceReference)).thenReturn(new ExtendedURL(Arrays.asList("xwiki", "angular", "2.1.11", "angular.css")));
    assertEquals("/xwiki/angular/2.1.11/angular.css", this.mocker.getComponentUnderTest().url("angular", "angular.css", Collections.singletonMap("wiki", "math")));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) WebJarsResourceReference(org.xwiki.webjars.internal.WebJarsResourceReference) ExtensionId(org.xwiki.extension.ExtensionId) ExtendedURL(org.xwiki.url.ExtendedURL) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Example 5 with InstalledExtensionRepository

use of org.xwiki.extension.repository.InstalledExtensionRepository in project xwiki-platform by xwiki.

the class ExtensionPingDataProviderTest method provideData.

@Test
public void provideData() throws Exception {
    ExtensionId extensionId = new ExtensionId("extensionid", "1.0");
    InstalledExtension extension = mock(InstalledExtension.class);
    when(extension.getId()).thenReturn(extensionId);
    when(extension.getFeatures()).thenReturn(Arrays.asList("feature1", "feature2"));
    InstalledExtensionRepository repository = this.mocker.getInstance(InstalledExtensionRepository.class);
    when(repository.getInstalledExtensions()).thenReturn(Collections.singletonList(extension));
    Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
    assertEquals(1, data.size());
    JSONObject[] extensions = (JSONObject[]) data.get("extensions");
    assertEquals(1, extensions.length);
    JSONObject propertiesData = extensions[0];
    assertEquals(3, propertiesData.size());
    assertEquals("extensionid", propertiesData.get("id"));
    assertEquals("1.0", propertiesData.get("version"));
    JSONArray features = (JSONArray) propertiesData.get("features");
    assertEquals(2, features.size());
    assertEquals("feature1", features.get(0));
    assertEquals("feature2", features.get(1));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) ExtensionId(org.xwiki.extension.ExtensionId) JSONObject(net.sf.json.JSONObject) InstalledExtensionRepository(org.xwiki.extension.repository.InstalledExtensionRepository) Test(org.junit.Test)

Aggregations

InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)7 ExtensionId (org.xwiki.extension.ExtensionId)6 Test (org.junit.Test)5 InstalledExtension (org.xwiki.extension.InstalledExtension)5 ExtendedURL (org.xwiki.url.ExtendedURL)3 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)3 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)2 LocalExtensionRepository (org.xwiki.extension.repository.LocalExtensionRepository)2 ObservationManager (org.xwiki.observation.ObservationManager)2 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 File (java.io.File)1 IOException (java.io.IOException)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1 DocumentException (org.dom4j.DocumentException)1 Mock (org.jmock.Mock)1 Extension (org.xwiki.extension.Extension)1 LocalExtension (org.xwiki.extension.LocalExtension)1