1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.jar

File JarExtensionHandlerTest.java

 

Code metrics

20
454
37
1
1,129
707
54
0.12
12.27
37
1.46

Classes

Class Line # Actions
JarExtensionHandlerTest 55 454 0% 54 16
0.9686888596.9%
 

Contributing tests

This file is covered by 23 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.jar;
21   
22    import java.io.File;
23    import java.lang.reflect.ParameterizedType;
24    import java.lang.reflect.Type;
25   
26    import org.apache.commons.lang3.reflect.MethodUtils;
27    import org.junit.Assert;
28    import org.junit.Test;
29    import org.xwiki.classloader.ClassLoaderManager;
30    import org.xwiki.component.internal.StackingComponentEventManager;
31    import org.xwiki.component.internal.multi.ComponentManagerManager;
32    import org.xwiki.component.manager.ComponentLookupException;
33    import org.xwiki.component.manager.ComponentManager;
34    import org.xwiki.component.util.DefaultParameterizedType;
35    import org.xwiki.component.util.ReflectionUtils;
36    import org.xwiki.extension.ExtensionId;
37    import org.xwiki.extension.InstallException;
38    import org.xwiki.extension.InstalledExtension;
39    import org.xwiki.extension.LocalExtension;
40    import org.xwiki.extension.repository.internal.installed.DefaultInstalledExtension;
41    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
42    import org.xwiki.logging.LogLevel;
43    import org.xwiki.logging.LoggerManager;
44    import org.xwiki.observation.ObservationManager;
45    import org.xwiki.test.annotation.AfterComponent;
46   
47    import packagefile.jarextension.DefaultTestComponent;
48    import packagefile.jarextension.TestComponent;
49    import packagefile.jarextensionwithdeps.DefaultTestComponentWithDeps;
50    import packagefile.jarextensionwithdeps.TestComponentWithDeps;
51   
52    import static org.junit.Assert.assertNotNull;
53    import static org.junit.Assert.assertNull;
54   
 
55    public class JarExtensionHandlerTest extends AbstractExtensionHandlerTest
56    {
57    private ComponentManagerManager componentManagerManager;
58   
59    private ClassLoader testApplicationClassloader;
60   
61    private ClassLoaderManager jarExtensionClassLoader;
62   
63    private static final String NAMESPACE = "namespace";
64   
 
65  23 toggle @AfterComponent
66    public void registerComponents() throws Exception
67    {
68    // Override the system ClassLoader to isolate class loading of extensions from the current ClassLoader
69    // (which already contains the extensions)
70  23 this.mocker.registerComponent(TestJarExtensionClassLoaderManager.class);
71   
72    // Make sure to fully enable ObservationManager to test EventListener live registration
73  23 StackingComponentEventManager componentEventManager = new StackingComponentEventManager();
74  23 componentEventManager.shouldStack(false);
75  23 this.mocker.setComponentEventManager(componentEventManager);
76   
77    // Ignore warning log during setup
78  23 ((LoggerManager) this.mocker.getInstance(LoggerManager.class)).pushLogListener(null);
79    }
80   
 
81  23 toggle @Override
82    public void setUp() throws Exception
83    {
84  23 super.setUp();
85   
86  23 this.testApplicationClassloader = Thread.currentThread().getContextClassLoader();
87   
88    // lookup
89  23 this.componentManagerManager = this.mocker.getInstance(ComponentManagerManager.class);
90  23 this.jarExtensionClassLoader = this.mocker.getInstance(ClassLoaderManager.class);
91   
92    // Make sure to fully enable ObservationManager to test EventListener live registration
93  23 StackingComponentEventManager componentEventManager =
94    (StackingComponentEventManager) this.mocker.getComponentEventManager();
95  23 ObservationManager manager = this.mocker.getInstance(ObservationManager.class);
96  23 componentEventManager.setObservationManager(manager);
97   
98  23 ((LoggerManager) this.mocker.getInstance(LoggerManager.class)).popLogListener();
99    }
100   
 
101  22 toggle private void assertNotEquals(Type type1, Type type2)
102    {
103  22 if (type1.equals(type2)) {
104  0 Assert.fail("expected not equals");
105    }
106    }
107   
108    /**
109    * @param namespace the namespace to be used
110    * @return the extension class loader for the current namespace
111    */
 
112  103 toggle private ClassLoader getExtensionClassloader(String namespace)
113    {
114  103 ClassLoader extensionLoader = this.jarExtensionClassLoader.getURLClassLoader(namespace, false);
115  103 if (extensionLoader == null) {
116  0 extensionLoader =
117    ((TestJarExtensionClassLoaderManager) this.jarExtensionClassLoader).testExtensionClassLoader;
118    }
119   
120  103 return extensionLoader;
121    }
122   
123    /**
124    * @param namespace the namespace to be used
125    * @return the extension ComponentManager for the current namespace
126    */
 
127  44 toggle private ComponentManager getExtensionComponentManager(String namespace)
128    {
129  44 ComponentManager extensionComponentManager = this.componentManagerManager.getComponentManager(namespace, false);
130  44 if (extensionComponentManager == null) {
131  0 try {
132  0 extensionComponentManager = this.mocker.getInstance(ComponentManager.class);
133    } catch (Exception e) {
134    // Should never happen
135    }
136    }
137   
138  44 return extensionComponentManager;
139    }
140   
141    /**
142    * Check that the extension is properly reported to be installed in all namespaces.
143    *
144    * @param installedExtension the local extension to check
145    */
 
146  23 toggle private void checkInstallStatus(InstalledExtension installedExtension)
147    {
148  23 checkInstallStatus(installedExtension, null);
149    }
150   
151    /**
152    * Check that the extension is properly reported to be installed in the given namespace.
153    *
154    * @param installedExtension the local extension to check
155    * @param namespace the namespace where it has been installed
156    */
 
157  50 toggle private void checkInstallStatus(InstalledExtension installedExtension, String namespace)
158    {
159    // check extension status
160  50 Assert.assertNotNull(installedExtension);
161  50 Assert.assertNotNull(installedExtension.getFile());
162  50 Assert.assertTrue(new File(installedExtension.getFile().getAbsolutePath()).exists());
163  50 Assert.assertTrue(installedExtension.isInstalled(namespace));
164  50 if (namespace != null) {
165  26 Assert.assertFalse(installedExtension.isInstalled(null));
166    }
167   
168    // check repository status
169  50 Assert.assertNotNull(
170    this.installedExtensionRepository.getInstalledExtension(installedExtension.getId().getId(), namespace));
171  50 if (namespace != null) {
172  26 Assert.assertNull(
173    this.installedExtensionRepository.getInstalledExtension(installedExtension.getId().getId(), null));
174    }
175    }
176   
 
177  100 toggle private Type getLoadedType(Type role, ClassLoader extensionLoader) throws ClassNotFoundException
178    {
179  100 if (role instanceof Class) {
180  46 return Class.forName(((Class<?>) role).getName(), true, extensionLoader);
181  54 } else if (role instanceof ParameterizedType) {
182  54 Class<?> rawType =
183    Class.forName(((Class<?>) ((ParameterizedType) role).getRawType()).getName(), true, extensionLoader);
184  45 return new DefaultParameterizedType(((ParameterizedType) role).getOwnerType(), rawType,
185    ((ParameterizedType) role).getActualTypeArguments());
186    }
187   
188  0 return null;
189    }
190   
191    /**
192    * Check that an extension is effectively available in all namespace and that the global component manager provide
193    * the expected default implementation.
194    *
195    * @param role the role expected to be provided by the extension
196    * @param implementation the implementation expected for the given role
197    * @param <T> the role class
198    * @return the effective role class in the extension class loader
199    * @throws Exception on error
200    */
 
201  27 toggle private <T> Type checkJarExtensionAvailability(Type role, Class<? extends T> implementation) throws Exception
202    {
203  27 return checkJarExtensionAvailability(role, implementation, null);
204    }
205   
206    /**
207    * Check that an extension is effectively available in the given namespace and that the corresponding component
208    * manager provide the expected default implementation.
209    *
210    * @param role the role expected to be provided by the extension
211    * @param implementation the implementation expected for the given role
212    * @param namespace the namespace where the extension is expected to installed
213    * @param <T> the role class
214    * @return the effective role class in the extension class loader
215    * @throws Exception on error
216    */
 
217  72 toggle private <T> Type checkJarExtensionAvailability(Type role, Class<? extends T> implementation, String namespace)
218    throws Exception
219    {
220  72 ClassLoader extensionLoader = getExtensionClassloader(namespace);
221  72 Assert.assertNotNull(extensionLoader);
222  72 Assert.assertNotSame(this.testApplicationClassloader, extensionLoader);
223   
224  72 Type loadedRole = getLoadedType(role, extensionLoader);
225    // Ensure the loaded role does not came from the application classloader (a check to validate the test)
226  72 Assert.assertFalse(loadedRole.equals(role));
227   
228  72 if (namespace != null) {
229  44 try {
230  44 this.jarExtensionClassLoader.getURLClassLoader(null, false)
231    .loadClass(ReflectionUtils.getTypeClass(loadedRole).getName());
232  0 Assert.fail("the interface should not be in the root class loader");
233    } catch (ClassNotFoundException expected) {
234    // expected
235    }
236    }
237   
238    // check components managers
239  72 Class<?> componentInstanceClass = null;
240  72 if (namespace != null) {
241  44 componentInstanceClass = getExtensionComponentManager(namespace).getInstance(loadedRole).getClass();
242   
243  44 try {
244  44 this.mocker.getInstance(loadedRole);
245  0 Assert.fail("the component should not be in the root component manager");
246    } catch (ComponentLookupException expected) {
247    // expected
248    }
249    } else {
250  28 componentInstanceClass = this.mocker.getInstance(loadedRole).getClass();
251    }
252  72 Assert.assertEquals(implementation.getName(), componentInstanceClass.getName());
253  72 Assert.assertNotSame(implementation, componentInstanceClass);
254   
255  72 return loadedRole;
256    }
257   
258    /**
259    * Check that the extension is properly reported to be not installed in all namespace.
260    *
261    * @param localExtension the local extension to check
262    */
 
263  15 toggle private void ckeckUninstallStatus(LocalExtension localExtension)
264    {
265  15 ckeckUninstallStatus(localExtension, null);
266    }
267   
268    /**
269    * Check that the extension is properly reported to be not installed in the given namespace.
270    *
271    * @param localExtension the local extension to check
272    * @param namespace the namespace where it should not be installed
273    */
 
274  23 toggle private void ckeckUninstallStatus(LocalExtension localExtension, String namespace)
275    {
276    // check extension status
277  23 Assert.assertFalse(DefaultInstalledExtension.isInstalled(localExtension, namespace));
278  23 Assert.assertFalse(DefaultInstalledExtension.isInstalled(localExtension, null));
279   
280    // check repository status
281  23 InstalledExtension installedExtension =
282    this.installedExtensionRepository.getInstalledExtension(localExtension.getId().getId(), namespace);
283  23 if (installedExtension != null) {
284  1 Assert.assertNotEquals(localExtension.getId(), installedExtension.getId());
285    }
286    }
287   
288    /**
289    * Check that an extension is effectively not available in all namespace and that the corresponding component
290    * manager does not provide an implementation.
291    *
292    * @param role the role expected to not be provide
293    * @throws Exception on error
294    */
 
295  7 toggle private void checkJarExtensionUnavailability(Type role) throws Exception
296    {
297  7 checkJarExtensionUnavailability(role, null);
298    }
299   
300    /**
301    * Check that an extension is effectively not available in the given namespace and that the corresponding component
302    * manager does not provide an implementation.
303    *
304    * @param role the role expected to not be provide
305    * @param namespace the namespace where the extension is not expected to be installed
306    * @throws Exception on error
307    */
 
308  28 toggle private void checkJarExtensionUnavailability(Type role, String namespace) throws Exception
309    {
310  28 try {
311  28 ClassLoader extensionLoader = getExtensionClassloader(namespace);
312  28 Type loadedRole = getLoadedType(role, extensionLoader);
313   
314    // check components managers
315  0 this.mocker.getInstance(loadedRole);
316  0 Assert.fail("the extension has not been uninstalled, component found!");
317    } catch (ComponentLookupException unexpected) {
318  0 Assert.fail("the extension has not been uninstalled, role found!");
319    } catch (ClassNotFoundException expected) {
320    // expected
321    }
322    }
323   
 
324  1 toggle @Test
325    public void testInstallAndUninstallExtension() throws Throwable
326    {
327  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension", "test");
328   
329    // actual install test
330  1 InstalledExtension installedExtension = install(extensionId);
331   
332  1 checkInstallStatus(installedExtension);
333   
334  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
335   
336  1 Type extensionRole1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
337   
338    // try to install again
339  1 try {
340  1 install(extensionId);
341  0 Assert.fail("installExtension should have failed");
342    } catch (InstallException expected) {
343    // expected
344    }
345   
346    // actual uninstall test
347  1 LocalExtension localExtension = uninstall(extensionId, null);
348   
349  1 ckeckUninstallStatus(localExtension);
350   
351  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING);
352   
353    // actual reinstall test
354  1 installedExtension = install(extensionId);
355   
356  1 checkInstallStatus(installedExtension);
357   
358  1 Type extensionRole2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
359  1 assertNotEquals(extensionRole1, extensionRole2);
360    }
361   
 
362  1 toggle @Test
363    public void testInstallAndUninstallWebjarExtension() throws Throwable
364    {
365  1 final ExtensionId extensionId = new ExtensionId("webjar", "test");
366   
367    // actual install test
368  1 InstalledExtension installedExtension = install(extensionId);
369   
370  1 checkInstallStatus(installedExtension);
371   
372    // actual uninstall test
373  1 LocalExtension localExtension = uninstall(extensionId, null);
374   
375  1 ckeckUninstallStatus(localExtension);
376   
377    // actual reinstall test
378  1 installedExtension = install(extensionId);
379   
380  1 checkInstallStatus(installedExtension);
381    }
382   
 
383  1 toggle @Test
384    public void testUpgradeAndDowngradeExtensionOnNamespace() throws Throwable
385    {
386  1 final ExtensionId extensionId1 = new ExtensionId("test", "1.0");
387  1 final ExtensionId extensionId2 = new ExtensionId("test", "2.0");
388   
389    // install 1.0
390  1 InstalledExtension installedExtension = install(extensionId1, NAMESPACE);
391   
392  1 checkInstallStatus(installedExtension, NAMESPACE);
393   
394  1 Assert.assertSame(installedExtension,
395    this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), NAMESPACE));
396  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), null));
397   
398  1 Class<?> clazz = Class.forName("test.TestClass", true, getExtensionClassloader(NAMESPACE));
399  1 assertNotNull(MethodUtils.getAccessibleMethod(clazz, "method1"));
400  1 assertNull(MethodUtils.getAccessibleMethod(clazz, "method2"));
401   
402    // upgrade to 2.0
403  1 installedExtension = install(extensionId2, NAMESPACE);
404   
405  1 checkInstallStatus(installedExtension, NAMESPACE);
406   
407  1 Assert.assertSame(installedExtension,
408    this.installedExtensionRepository.getInstalledExtension(extensionId2.getId(), NAMESPACE));
409  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(extensionId2.getId(), null));
410   
411  1 clazz = Class.forName("test.TestClass", true, getExtensionClassloader(NAMESPACE));
412  1 assertNotNull(MethodUtils.getAccessibleMethod(clazz, "method1"));
413  1 assertNotNull(MethodUtils.getAccessibleMethod(clazz, "method2"));
414   
415    // downgrade to 1.0
416  1 installedExtension = install(extensionId1, NAMESPACE);
417   
418  1 checkInstallStatus(installedExtension, NAMESPACE);
419   
420  1 Assert.assertSame(installedExtension,
421    this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), NAMESPACE));
422  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), null));
423   
424  1 clazz = Class.forName("test.TestClass", true, getExtensionClassloader(NAMESPACE));
425  1 assertNotNull(MethodUtils.getAccessibleMethod(clazz, "method1"));
426  1 assertNull(MethodUtils.getAccessibleMethod(clazz, "method2"));
427    }
428   
 
429  1 toggle @Test
430    public void testInstallAndUninstallExtensionOnNamespace() throws Throwable
431    {
432  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension", "test");
433   
434    // actual install test
435  1 InstalledExtension installedExtension = install(extensionId, NAMESPACE);
436   
437  1 checkInstallStatus(installedExtension, NAMESPACE);
438   
439  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", NAMESPACE));
440  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
441   
442  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, NAMESPACE);
443   
444  1 try {
445  1 install(extensionId, NAMESPACE);
446  0 Assert.fail("installExtension should have failed");
447    } catch (InstallException expected) {
448    // expected
449    }
450   
451    // actual uninstall test
452  1 LocalExtension localExtension = uninstall(extensionId, null);
453   
454  1 ckeckUninstallStatus(localExtension, NAMESPACE);
455   
456  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING, NAMESPACE);
457    }
458   
 
459  1 toggle @Test
460    public void testInstallAndUninstallExtensionWithoutComponents() throws Throwable
461    {
462  1 final ExtensionId extensionId = new ExtensionId("simplejar", "test");
463   
464    // actual install test
465  1 InstalledExtension installedExtension = install(extensionId);
466   
467  1 checkInstallStatus(installedExtension);
468   
469    // actual uninstall test
470  1 LocalExtension localExtension = uninstall(extensionId, null);
471   
472  1 ckeckUninstallStatus(localExtension);
473   
474    // actual reinstall test
475  1 installedExtension = install(extensionId);
476   
477  1 checkInstallStatus(installedExtension);
478    }
479   
 
480  1 toggle @Test
481    public void testInstallAndUninstallExtensionWithDependency() throws Throwable
482    {
483  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
484   
485    // actual install test
486  1 InstalledExtension installedExtension = install(extensionId);
487   
488  1 checkInstallStatus(installedExtension);
489   
490  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", null));
491  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
492   
493  1 Type extensionRole1 =
494    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class);
495  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
496   
497    // actual uninstall test
498  1 LocalExtension localExtension = uninstall(extensionId, null);
499   
500  1 ckeckUninstallStatus(localExtension);
501   
502  1 checkJarExtensionUnavailability(TestComponentWithDeps.class);
503  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
504  1 assertNotEquals(extensionDep1, extensionDep2);
505   
506    // actual reinstall test
507  1 installedExtension = install(extensionId);
508   
509  1 checkInstallStatus(installedExtension);
510   
511  1 Type extensionRole2 =
512    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class);
513  1 Type extensionDep3 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
514  1 assertNotEquals(extensionRole1, extensionRole2);
515  1 Assert.assertEquals(extensionDep2, extensionDep3);
516    }
517   
 
518  1 toggle @Test
519    public void testInstallAndUninstallExtensionWithDependencyOnANamespace() throws Throwable
520    {
521  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
522  1 final String namespace = NAMESPACE;
523   
524    // actual install test
525  1 InstalledExtension installExtension = install(extensionId, namespace);
526   
527  1 checkInstallStatus(installExtension, namespace);
528   
529  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace));
530  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", null));
531   
532  1 checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
533  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace);
534   
535    // actual uninstall test
536  1 LocalExtension localExtension = uninstall(extensionId, null);
537   
538  1 ckeckUninstallStatus(localExtension, namespace);
539   
540  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace);
541  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace);
542    }
543   
 
544  1 toggle @Test
545    public void testInstallEntensionAndUninstallDependency() throws Throwable
546    {
547  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
548  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
549   
550    // actual install test
551  1 InstalledExtension installedExtension = install(extensionId);
552   
553  1 checkInstallStatus(installedExtension);
554   
555  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", null));
556  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
557   
558  1 Type extensionRole1 =
559    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class);
560  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
561   
562    // actual uninstall test
563  1 LocalExtension localExtension = uninstall(dependencyId, null);
564   
565  1 ckeckUninstallStatus(localExtension);
566   
567  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING);
568  1 checkJarExtensionUnavailability(TestComponentWithDeps.class);
569   
570    // actual reinstall test
571  1 installedExtension = install(extensionId);
572   
573  1 checkInstallStatus(installedExtension);
574   
575  1 Type extensionRole2 =
576    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class);
577  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
578  1 assertNotEquals(extensionRole1, extensionRole2);
579  1 assertNotEquals(extensionDep1, extensionDep2);
580    }
581   
 
582  1 toggle @Test
583    public void testInstallExtensionAndUninstallDependencyOnANamespace() throws Throwable
584    {
585  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
586  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
587  1 final String namespace = NAMESPACE;
588   
589    // actual install test
590  1 InstalledExtension installedExtension = install(extensionId, namespace);
591   
592  1 checkInstallStatus(installedExtension, namespace);
593   
594  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace));
595  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", null));
596   
597  1 checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
598  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace);
599   
600    // actual uninstall test
601  1 LocalExtension localExtension = uninstall(dependencyId, null);
602   
603  1 ckeckUninstallStatus(localExtension, namespace);
604   
605  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace);
606  1 checkJarExtensionUnavailability(TestComponentWithDeps.class);
607    }
608   
 
609  1 toggle @Test
610    public void testInstallDependencyInstallExtensionOnANamespaceAndUninstallExtension() throws Throwable
611    {
612  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
613  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
614  1 final String namespace = NAMESPACE;
615   
616    // actual install test
617  1 InstalledExtension installedExtension = install(dependencyId);
618   
619  1 checkInstallStatus(installedExtension);
620  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
621  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
622   
623    // actual install test
624  1 installedExtension = install(extensionId, namespace);
625   
626  1 checkInstallStatus(installedExtension, namespace);
627  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
628   
629  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace));
630  1 Type extensionRole1 =
631    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
632  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
633  1 Assert.assertEquals(extensionDep1, extensionDep2);
634   
635    // actual uninstall test
636  1 LocalExtension localExtension = uninstall(extensionId, namespace);
637   
638  1 ckeckUninstallStatus(localExtension, namespace);
639  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
640   
641  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace);
642  1 Type extensionDep3 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
643  1 Assert.assertEquals(extensionDep1, extensionDep3);
644   
645    // actual reinstall test
646  1 installedExtension = install(extensionId, namespace);
647   
648  1 checkInstallStatus(installedExtension, namespace);
649   
650  1 Type extensionRole2 =
651    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
652  1 Type extensionDep4 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
653  1 assertNotEquals(extensionRole1, extensionRole2);
654  1 Assert.assertEquals(extensionDep1, extensionDep4);
655    }
656   
 
657  1 toggle @Test
658    public void testInstallDependencyInstallExtensionOnANamespaceAndUninstallDependency() throws Throwable
659    {
660  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
661  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
662  1 final String namespace = NAMESPACE;
663   
664    // actual install test
665  1 InstalledExtension installedExtension = install(dependencyId);
666   
667  1 checkInstallStatus(installedExtension);
668  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
669  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
670   
671    // actual install test
672  1 installedExtension = install(extensionId, namespace);
673   
674  1 checkInstallStatus(installedExtension, namespace);
675  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
676   
677  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace));
678  1 Type extensionRole1 =
679    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
680  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
681  1 Assert.assertEquals(extensionDep1, extensionDep2);
682   
683    // actual uninstall test
684  1 LocalExtension localExtension = uninstall(dependencyId, null);
685   
686  1 ckeckUninstallStatus(localExtension);
687  1 ckeckUninstallStatus(this.localExtensionRepository.resolve(extensionId), namespace);
688   
689  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING);
690  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace);
691   
692    // actual reinstall test
693  1 installedExtension = install(extensionId, namespace);
694   
695  1 checkInstallStatus(installedExtension, namespace);
696  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId), namespace);
697   
698  1 Type extensionRole2 =
699    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace);
700  1 Type extensionDep3 =
701    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace);
702  1 assertNotEquals(extensionRole1, extensionRole2);
703  1 assertNotEquals(extensionDep1, extensionDep3);
704    }
705   
 
706  1 toggle @Test
707    public void testMultipleInstallOnANamespaceAndUninstall() throws Throwable
708    {
709  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
710  1 final String namespace1 = "namespace1";
711  1 final String namespace2 = "namespace2";
712   
713    // actual install test
714  1 InstalledExtension installedExtension = install(extensionId, namespace1);
715   
716  1 checkInstallStatus(installedExtension, namespace1);
717   
718  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
719  1 Type extensionRole1 =
720    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
721  1 Type extensionDep1 =
722    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
723   
724    // actual install test
725    // TODO: go back to LogLevel.WARN when https://jira.xwiki.org/browse/XCOMMONS-213 is fixed
726  1 installedExtension = install(extensionId, namespace2, LogLevel.ERROR);
727   
728  1 checkInstallStatus(installedExtension, namespace2);
729   
730  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
731  1 Type extensionRole2 =
732    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
733  1 Type extensionDep2 =
734    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
735  1 assertNotEquals(extensionRole1, extensionRole2);
736  1 assertNotEquals(extensionDep1, extensionDep2);
737   
738    // actual uninstall test
739    // FIXME: Ignore warning because of https://jira.xwiki.org/browse/XCOMMONS-213
740  1 LocalExtension localExtension = uninstall(extensionId, namespace1, LogLevel.ERROR);
741   
742  1 ckeckUninstallStatus(localExtension);
743   
744  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
745  1 Type extensionDep3 =
746    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
747  1 assertNotEquals(extensionDep1, extensionDep3);
748   
749  1 Type extensionRole3 =
750    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
751  1 Type extensionDep4 =
752    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
753  1 Assert.assertEquals(extensionRole2, extensionRole3);
754  1 Assert.assertEquals(extensionDep2, extensionDep4);
755   
756    // actual uninstall test
757    // FIXME: Ignore warning because of https://jira.xwiki.org/browse/XCOMMONS-213
758  1 localExtension = uninstall(extensionId, namespace2, LogLevel.ERROR);
759   
760  1 ckeckUninstallStatus(localExtension);
761   
762  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace2);
763  1 Type extensionDep5 =
764    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
765  1 assertNotEquals(extensionDep2, extensionDep5);
766   
767  1 Type extensionDep6 =
768    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
769  1 Assert.assertEquals(extensionDep3, extensionDep6);
770    }
771   
 
772  1 toggle @Test
773    public void testMultipleInstallOnANamespaceAndUninstallDependency() throws Throwable
774    {
775  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
776  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
777  1 final String namespace1 = "namespace1";
778  1 final String namespace2 = "namespace2";
779   
780  1 InstalledExtension installedExtension = install(extensionId, namespace1);
781   
782  1 checkInstallStatus(installedExtension, namespace1);
783   
784  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
785  1 Type extensionRole1 =
786    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
787  1 Type extensionDep1 =
788    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
789   
790    // TODO: go back to LogLevel.WARN when https://jira.xwiki.org/browse/XCOMMONS-213 is fixed
791  1 installedExtension = install(extensionId, namespace2, LogLevel.ERROR);
792   
793  1 checkInstallStatus(installedExtension, namespace2);
794   
795  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
796  1 Type extensionRole2 =
797    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
798  1 Type extensionDep2 =
799    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
800  1 assertNotEquals(extensionRole1, extensionRole2);
801  1 assertNotEquals(extensionDep1, extensionDep2);
802   
803    // actual uninstall test
804  1 LocalExtension localExtension = uninstall(dependencyId, namespace1);
805   
806  1 ckeckUninstallStatus(localExtension);
807   
808  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING, namespace1);
809  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
810   
811  1 Type extensionRole3 =
812    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
813  1 Type extensionDep3 =
814    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
815  1 Assert.assertEquals(extensionRole2, extensionRole3);
816  1 Assert.assertEquals(extensionDep2, extensionDep3);
817   
818    // actual uninstall test
819  1 localExtension = uninstall(dependencyId, namespace2);
820   
821  1 ckeckUninstallStatus(localExtension);
822   
823  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING, namespace2);
824  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace2);
825    }
826   
 
827  1 toggle @Test
828    public void testMultipleInstallOnANamespaceAndUninstallAll() throws Throwable
829    {
830  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
831  1 final String namespace1 = "namespace1";
832  1 final String namespace2 = "namespace2";
833   
834  1 InstalledExtension installedExtension = install(extensionId, namespace1);
835   
836  1 checkInstallStatus(installedExtension, namespace1);
837   
838  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
839  1 Type extensionRole1 =
840    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
841  1 Type extensionDep1 =
842    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
843   
844    // TODO: go back to LogLevel.WARN when https://jira.xwiki.org/browse/XCOMMONS-213 is fixed
845  1 installedExtension = install(extensionId, namespace2, LogLevel.ERROR);
846   
847  1 checkInstallStatus(installedExtension, namespace2);
848   
849  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
850  1 Type extensionRole2 =
851    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
852  1 Type extensionDep2 =
853    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
854  1 assertNotEquals(extensionRole1, extensionRole2);
855  1 assertNotEquals(extensionDep1, extensionDep2);
856   
857    // actual uninstall test
858    // FIXME: Ignore warning because of https://jira.xwiki.org/browse/XCOMMONS-213
859  1 LocalExtension localExtension = uninstall(extensionId, null, LogLevel.ERROR);
860   
861  1 ckeckUninstallStatus(localExtension);
862   
863  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
864  1 Type extensionDep3 =
865    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
866  1 assertNotEquals(extensionDep1, extensionDep3);
867  1 Type extensionDep4 =
868    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
869  1 assertNotEquals(extensionDep2, extensionDep4);
870    }
871   
 
872  1 toggle @Test
873    public void testMultipleInstallOnANamespaceAndUninstallDependencyAll() throws Throwable
874    {
875  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
876  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
877  1 final String namespace1 = "namespace1";
878  1 final String namespace2 = "namespace2";
879   
880  1 InstalledExtension installedExtension = install(extensionId, namespace1);
881   
882  1 checkInstallStatus(installedExtension, namespace1);
883   
884  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
885  1 Type extensionRole1 =
886    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
887  1 Type extensionDep1 =
888    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace1);
889   
890    // TODO: go back to LogLevel.WARN when https://jira.xwiki.org/browse/XCOMMONS-213 is fixed
891  1 installedExtension = install(extensionId, namespace2, LogLevel.ERROR);
892   
893  1 checkInstallStatus(installedExtension, namespace2);
894   
895  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
896  1 Type extensionRole2 =
897    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
898  1 Type extensionDep2 =
899    checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, namespace2);
900  1 assertNotEquals(extensionRole1, extensionRole2);
901  1 assertNotEquals(extensionDep1, extensionDep2);
902   
903    // actual uninstall test
904  1 LocalExtension localExtension = uninstall(dependencyId, null);
905   
906  1 ckeckUninstallStatus(localExtension);
907   
908  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING, namespace1);
909  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
910  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING, namespace2);
911  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace2);
912    }
913   
 
914  1 toggle @Test
915    public void testMultipleInstallOnANamespaceWithGlobalDependencyAndUninstall() throws Throwable
916    {
917  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
918  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
919  1 final String namespace1 = "namespace1";
920  1 final String namespace2 = "namespace2";
921   
922    // install global deps
923  1 InstalledExtension installedExtension = install(dependencyId);
924   
925  1 checkInstallStatus(installedExtension);
926   
927  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
928  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
929   
930    // actual install test
931  1 installedExtension = install(extensionId, namespace1);
932   
933  1 checkInstallStatus(installedExtension, namespace1);
934  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
935   
936  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
937  1 Type extensionRole1 =
938    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
939  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
940  1 Assert.assertEquals(extensionDep1, extensionDep2);
941   
942    // actual install test
943  1 installedExtension = install(extensionId, namespace2);
944   
945  1 checkInstallStatus(installedExtension, namespace2);
946  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
947   
948  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
949  1 Type extensionRole2 =
950    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
951  1 Type extensionDep3 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
952  1 assertNotEquals(extensionRole1, extensionRole2);
953  1 Assert.assertEquals(extensionDep1, extensionDep3);
954   
955    // actual uninstall test
956  1 LocalExtension localExtension = uninstall(extensionId, namespace1);
957   
958  1 ckeckUninstallStatus(localExtension);
959  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
960   
961  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
962   
963  1 Type extensionRole3 =
964    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
965  1 Type extensionDep4 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
966  1 Assert.assertEquals(extensionRole2, extensionRole3);
967  1 Assert.assertEquals(extensionDep1, extensionDep4);
968   
969    // actual uninstall test
970  1 localExtension = uninstall(extensionId, namespace2);
971   
972  1 ckeckUninstallStatus(localExtension);
973  1 checkInstallStatus(this.installedExtensionRepository.resolve(dependencyId));
974   
975  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace2);
976  1 Type extensionDep5 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
977  1 Assert.assertEquals(extensionDep1, extensionDep5);
978    }
979   
 
980  1 toggle @Test
981    public void testMultipleInstallOnANamespaceWithGlobalDependencyAndUninstallDependency() throws Throwable
982    {
983  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension-with-deps", "test");
984  1 final ExtensionId dependencyId = new ExtensionId("org.xwiki.test:test-extension", "test");
985  1 final String namespace1 = "namespace1";
986  1 final String namespace2 = "namespace2";
987   
988    // install global deps
989  1 InstalledExtension installedExtension = install(dependencyId);
990   
991  1 checkInstallStatus(installedExtension);
992   
993  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature", null));
994  1 Type extensionDep1 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
995   
996  1 installedExtension = install(extensionId, namespace1);
997   
998  1 checkInstallStatus(installedExtension, namespace1);
999   
1000  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace1));
1001  1 Type extensionRole1 =
1002    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace1);
1003  1 Type extensionDep2 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
1004  1 Assert.assertEquals(extensionDep1, extensionDep2);
1005   
1006  1 installedExtension = install(extensionId, namespace2);
1007   
1008  1 checkInstallStatus(installedExtension, namespace2);
1009   
1010  1 Assert.assertNotNull(this.installedExtensionRepository.getInstalledExtension("feature-with-deps", namespace2));
1011  1 Type extensionRole2 =
1012    checkJarExtensionAvailability(TestComponentWithDeps.class, DefaultTestComponentWithDeps.class, namespace2);
1013  1 Type extensionDep3 = checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
1014  1 assertNotEquals(extensionRole1, extensionRole2);
1015  1 Assert.assertEquals(extensionDep1, extensionDep3);
1016   
1017    // actual uninstall test
1018  1 LocalExtension localExtension = uninstall(dependencyId, null);
1019   
1020  1 ckeckUninstallStatus(localExtension);
1021  1 ckeckUninstallStatus(this.localExtensionRepository.resolve(extensionId), namespace1);
1022  1 ckeckUninstallStatus(this.localExtensionRepository.resolve(extensionId), namespace2);
1023   
1024  1 checkJarExtensionUnavailability(TestComponent.TYPE_STRING);
1025  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace1);
1026  1 checkJarExtensionUnavailability(TestComponentWithDeps.class, namespace2);
1027    }
1028   
 
1029  1 toggle @Test
1030    public void testUninstallInvalidExtensionFromNamespace() throws Throwable
1031    {
1032  1 ExtensionId extensionId = new ExtensionId("invalidextensiononnamespace", "version");
1033   
1034  1 uninstall(extensionId, "namespaceofinvalidextension");
1035    }
1036   
 
1037  1 toggle @Test
1038    public void testUninstallInvalidExtensionFromRoot() throws Throwable
1039    {
1040  1 ExtensionId extensionId = new ExtensionId("invalidextensiononroot", "version");
1041   
1042  1 uninstall(extensionId, null);
1043    }
1044   
 
1045  1 toggle @Test
1046    public void testExtensionInstalledOnNamespaceAtInit() throws Throwable
1047    {
1048  1 ExtensionId extensionId = new ExtensionId("installedextensiononnamespace", "1.0");
1049   
1050  1 InstalledExtension installedExtension = this.installedExtensionRepository.resolve(extensionId);
1051   
1052  1 checkInstallStatus(installedExtension, NAMESPACE);
1053   
1054  1 checkJarExtensionAvailability(packagefile.installedextensiononnamespace.TestInstalledComponent.TYPE_STRING,
1055    packagefile.installedextensiononnamespace.DefaultTestInstalledComponent.class, NAMESPACE);
1056   
1057  1 uninstall(extensionId, NAMESPACE);
1058    }
1059   
 
1060  1 toggle @Test
1061    public void testExtensionInstalledOnRootAtInit() throws Throwable
1062    {
1063  1 ExtensionId extensionId = new ExtensionId("installedextensiononroot", "1.0");
1064   
1065  1 InstalledExtension installedExtension = this.installedExtensionRepository.resolve(extensionId);
1066   
1067  1 checkInstallStatus(installedExtension, null);
1068   
1069  1 checkJarExtensionAvailability(packagefile.installedextensiononroot.TestInstalledComponent.TYPE_STRING,
1070    packagefile.installedextensiononroot.DefaultTestInstalledComponent.class, null);
1071   
1072  1 uninstall(extensionId, null);
1073    }
1074   
 
1075  1 toggle @Test
1076    public void testInstallOnNamespaceThenOnRoot() throws Throwable
1077    {
1078  1 final ExtensionId extensionId = new ExtensionId("org.xwiki.test:test-extension", "test");
1079   
1080    // install on namespace
1081  1 InstalledExtension installedExtension = install(extensionId, NAMESPACE);
1082   
1083  1 checkInstallStatus(installedExtension, NAMESPACE);
1084   
1085  1 Assert.assertSame(installedExtension,
1086    this.installedExtensionRepository.getInstalledExtension(extensionId.getId(), NAMESPACE));
1087  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(extensionId.getId(), null));
1088   
1089  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class, NAMESPACE);
1090   
1091    // install on root
1092  1 installedExtension = install(extensionId);
1093   
1094  1 checkInstallStatus(installedExtension);
1095   
1096  1 checkJarExtensionAvailability(TestComponent.TYPE_STRING, DefaultTestComponent.class);
1097    }
1098   
 
1099  1 toggle @Test
1100    public void testInstallOnNamespaceThenUpgradeOnRoot() throws Throwable
1101    {
1102  1 final ExtensionId extensionId1 = new ExtensionId("jarupgrade", "1.0");
1103  1 final ExtensionId extensionId2 = new ExtensionId("jarupgrade", "2.0");
1104   
1105    // install on namespace
1106  1 InstalledExtension installedExtension1 = install(extensionId1, NAMESPACE);
1107   
1108  1 checkInstallStatus(installedExtension1, NAMESPACE);
1109   
1110  1 Assert.assertSame(installedExtension1,
1111    this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), NAMESPACE));
1112  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(extensionId1.getId(), null));
1113   
1114  1 checkJarExtensionAvailability(packagefile.jarupgrade1.TestComponent.class,
1115    packagefile.jarupgrade1.DefaultTestComponent.class, NAMESPACE);
1116   
1117    // install on root
1118  1 InstalledExtension installedExtension2 = install(extensionId2);
1119   
1120  1 LocalExtension localExtension = this.localExtensionRepository.getLocalExtension(extensionId1);
1121   
1122  1 ckeckUninstallStatus(localExtension, NAMESPACE);
1123  1 checkInstallStatus(installedExtension2);
1124   
1125  1 checkJarExtensionUnavailability(packagefile.jarupgrade1.TestComponent.class, NAMESPACE);
1126  1 checkJarExtensionAvailability(packagefile.jarupgrade2.TestComponent.class,
1127    packagefile.jarupgrade2.DefaultTestComponent.class);
1128    }
1129    }