Search in sources :

Example 16 with InstalledExtension

use of org.xwiki.extension.InstalledExtension 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 17 with InstalledExtension

use of org.xwiki.extension.InstalledExtension 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 18 with InstalledExtension

use of org.xwiki.extension.InstalledExtension 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)

Example 19 with InstalledExtension

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

the class ExtensionPingDataProvider method provideData.

@Override
public Map<String, Object> provideData() {
    Collection<InstalledExtension> installedExtensions = this.extensionRepository.getInstalledExtensions();
    JSONObject[] extensions = new JSONObject[installedExtensions.size()];
    Iterator<InstalledExtension> it = installedExtensions.iterator();
    int i = 0;
    while (it.hasNext()) {
        InstalledExtension extension = it.next();
        Map<String, Object> extensionMap = new HashMap<>();
        extensionMap.put(PROPERTY_ID, extension.getId().getId());
        extensionMap.put(PROPERTY_VERSION, extension.getId().getVersion().toString());
        extensionMap.put(PROPERTY_FEATURES, extension.getFeatures().toArray());
        extensions[i] = JSONObject.fromObject(extensionMap);
        i++;
    }
    return Collections.singletonMap(PROPERTY_EXTENSIONS, (Object) extensions);
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) JSONObject(net.sf.json.JSONObject) HashMap(java.util.HashMap) JSONObject(net.sf.json.JSONObject)

Example 20 with InstalledExtension

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

the class RepairXarJobTest method testRepairInvalidOnRoot.

@Test
public void testRepairInvalidOnRoot() throws Throwable {
    ExtensionId extensionId = new ExtensionId("invalid", "1.0");
    repair(extensionId, null, LogLevel.ERROR);
    InstalledExtension installedExtension = this.xarExtensionRepository.resolve(extensionId);
    assertFalse(installedExtension.isValid(null));
}
Also used : InstalledExtension(org.xwiki.extension.InstalledExtension) ExtensionId(org.xwiki.extension.ExtensionId) Test(org.junit.Test) AbstractExtensionHandlerTest(org.xwiki.extension.test.AbstractExtensionHandlerTest)

Aggregations

InstalledExtension (org.xwiki.extension.InstalledExtension)27 ExtensionId (org.xwiki.extension.ExtensionId)12 Test (org.junit.Test)8 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)5 Namespace (org.xwiki.component.namespace.Namespace)4 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)4 Collection (java.util.Collection)3 ExtensionDependency (org.xwiki.extension.ExtensionDependency)3 ExtensionInstalledEvent (org.xwiki.extension.event.ExtensionInstalledEvent)3 AbstractExtensionHandlerTest (org.xwiki.extension.test.AbstractExtensionHandlerTest)3 ExtendedURL (org.xwiki.url.ExtendedURL)3 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)3 JSONObject (net.sf.json.JSONObject)2 ExtensionEvent (org.xwiki.extension.event.ExtensionEvent)2 ExtensionUninstalledEvent (org.xwiki.extension.event.ExtensionUninstalledEvent)2 InstallRequest (org.xwiki.extension.job.InstallRequest)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 XWikiException (com.xpn.xwiki.XWikiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1