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

File InstallPlanJobTest.java

 

Code metrics

0
407
36
1
831
586
37
0.09
11.31
36
1.03

Classes

Class Line # Actions
InstallPlanJobTest 44 407 0% 37 1
0.9977426599.8%
 

Contributing tests

This file is covered by 35 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.job.internal;
21   
22    import java.util.Iterator;
23   
24    import org.junit.Assert;
25    import org.junit.Before;
26    import org.junit.Test;
27    import org.xwiki.extension.CoreExtension;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.InstallException;
30    import org.xwiki.extension.LocalExtension;
31    import org.xwiki.extension.TestResources;
32    import org.xwiki.extension.job.InstallRequest;
33    import org.xwiki.extension.job.plan.ExtensionPlan;
34    import org.xwiki.extension.job.plan.ExtensionPlanAction;
35    import org.xwiki.extension.job.plan.ExtensionPlanAction.Action;
36    import org.xwiki.extension.job.plan.ExtensionPlanNode;
37    import org.xwiki.extension.repository.CoreExtensionRepository;
38    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
39    import org.xwiki.extension.test.ConfigurableDefaultCoreExtensionRepository;
40    import org.xwiki.extension.version.internal.DefaultVersion;
41   
42    import static org.junit.Assert.fail;
43   
 
44    public class InstallPlanJobTest extends AbstractExtensionHandlerTest
45    {
46    private ConfigurableDefaultCoreExtensionRepository coreRepository;
47   
 
48  35 toggle @Override
49    @Before
50    public void setUp() throws Exception
51    {
52  35 super.setUp();
53   
54  35 this.coreRepository = this.mocker.getInstance(CoreExtensionRepository.class);
55    }
56   
 
57  1 toggle @Test
58    public void testInstallPlanWithSimpleRemoteExtensionOnRoot() throws Throwable
59    {
60  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_SIMPLE_ID);
61   
62    // Tree
63   
64  1 Assert.assertEquals(1, plan.getTree().size());
65   
66  1 ExtensionPlanNode node = plan.getTree().iterator().next();
67   
68  1 ExtensionPlanAction action = node.getAction();
69   
70  1 Assert.assertEquals(TestResources.REMOTE_SIMPLE_ID, action.getExtension().getId());
71  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
72  1 Assert.assertNull(action.getPreviousExtension());
73  1 Assert.assertNull(action.getNamespace());
74  1 Assert.assertEquals(0, node.getChildren().size());
75   
76    // Actions
77   
78  1 Assert.assertEquals(1, plan.getActions().size());
79   
80  1 Assert.assertSame(action, plan.getActions().iterator().next());
81    }
82   
 
83  1 toggle @Test
84    public void testInstallPlanWithRemoteDependencyOnRoot() throws Throwable
85    {
86  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITHRDEPENDENCY_ID);
87   
88  1 Assert.assertEquals(1, plan.getTree().size());
89   
90  1 ExtensionPlanNode node = plan.getTree().iterator().next();
91   
92  1 Assert.assertEquals(TestResources.REMOTE_WITHRDEPENDENCY_ID, node.getAction().getExtension().getId());
93  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
94  1 Assert.assertNull(node.getAction().getPreviousExtension());
95  1 Assert.assertNull(node.getAction().getNamespace());
96  1 Assert.assertEquals(1, node.getChildren().size());
97   
98  1 ExtensionPlanNode childnode = node.getChildren().iterator().next();
99   
100  1 Assert.assertEquals(TestResources.REMOTE_SIMPLE_ID, childnode.getAction().getExtension().getId());
101  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
102  1 Assert.assertNull(node.getAction().getPreviousExtension());
103  1 Assert.assertNull(childnode.getAction().getNamespace());
104  1 Assert.assertTrue(childnode.getChildren().isEmpty());
105    }
106   
 
107  1 toggle @Test
108    public void testInstallPlanWithCoreDependencyOnRoot() throws Throwable
109    {
110  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITHCDEPENDENCY_ID);
111   
112  1 Assert.assertEquals(1, plan.getTree().size());
113   
114  1 ExtensionPlanNode node = plan.getTree().iterator().next();
115   
116  1 Assert.assertEquals(TestResources.REMOTE_WITHCDEPENDENCY_ID, node.getAction().getExtension().getId());
117  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
118  1 Assert.assertNull(node.getAction().getPreviousExtension());
119  1 Assert.assertNull(node.getAction().getNamespace());
120  1 Assert.assertEquals(1, node.getChildren().size());
121   
122  1 ExtensionPlanNode childnode = node.getChildren().iterator().next();
123   
124  1 Assert.assertTrue(childnode.getAction().getExtension() instanceof CoreExtension);
125  1 Assert.assertEquals(TestResources.CORE_ID, childnode.getAction().getExtension().getId());
126  1 Assert.assertEquals(Action.NONE, childnode.getAction().getAction());
127  1 Assert.assertNull(node.getAction().getPreviousExtension());
128  1 Assert.assertTrue(childnode.getChildren().isEmpty());
129    }
130   
 
131  1 toggle @Test
132    public void testInstallPlanWithInstalledDependencyOnRoot() throws Throwable
133    {
134  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITHLDEPENDENCY_ID);
135   
136  1 Assert.assertEquals(1, plan.getTree().size());
137   
138  1 ExtensionPlanNode node = plan.getTree().iterator().next();
139   
140  1 Assert.assertEquals(TestResources.REMOTE_WITHLDEPENDENCY_ID, node.getAction().getExtension().getId());
141  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
142  1 Assert.assertNull(node.getAction().getPreviousExtension());
143  1 Assert.assertNull(node.getAction().getNamespace());
144  1 Assert.assertEquals(1, node.getChildren().size());
145   
146  1 ExtensionPlanNode childnode = node.getChildren().iterator().next();
147   
148  1 Assert.assertTrue(childnode.getAction().getExtension() instanceof LocalExtension);
149  1 Assert.assertEquals(TestResources.INSTALLED_ID, childnode.getAction().getExtension().getId());
150  1 Assert.assertEquals(Action.NONE, childnode.getAction().getAction());
151  1 Assert.assertNull(node.getAction().getPreviousExtension());
152  1 Assert.assertTrue(childnode.getChildren().isEmpty());
153    }
154   
 
155  1 toggle @Test
156    public void testInstallPlanWithUpgradeOnRoot() throws Throwable
157    {
158  1 install(TestResources.REMOTE_UPGRADE10_ID);
159   
160    // //////////////////
161    // Test upgrade
162   
163  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE20_ID);
164   
165  1 Assert.assertEquals(1, plan.getTree().size());
166   
167  1 ExtensionPlanNode node = plan.getTree().iterator().next();
168   
169  1 ExtensionPlanAction action = node.getAction();
170   
171  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
172  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
173  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
174  1 Assert.assertNull(action.getNamespace());
175  1 Assert.assertEquals(0, node.getChildren().size());
176    }
177   
 
178  1 toggle @Test
179    public void testInstallPlanWithUpgradeOnDifferentId() throws Throwable
180    {
181  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_NOTINSTALLED_ID);
182   
183  1 Iterator<ExtensionPlanNode> it = plan.getTree().iterator();
184   
185  1 ExtensionPlanNode node = it.next();
186  1 ExtensionPlanAction action = node.getAction();
187  1 Assert.assertEquals(TestResources.INSTALLED_ID, action.getExtension().getId());
188  1 Assert.assertEquals(Action.UNINSTALL, action.getAction());
189  1 Assert.assertNull(action.getNamespace());
190  1 Assert.assertEquals(0, node.getChildren().size());
191   
192  1 node = it.next();
193  1 action = node.getAction();
194  1 Assert.assertEquals(TestResources.INSTALLED_DEPENDENCY_ID, action.getExtension().getId());
195  1 Assert.assertEquals(Action.UNINSTALL, action.getAction());
196  1 Assert.assertNull(action.getNamespace());
197  1 Assert.assertEquals(0, node.getChildren().size());
198   
199  1 node = it.next();
200  1 action = node.getAction();
201  1 Assert.assertEquals(TestResources.REMOTE_NOTINSTALLED_ID, action.getExtension().getId());
202  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
203  1 Assert.assertEquals(TestResources.INSTALLED_ID, action.getPreviousExtension().getId());
204  1 Assert.assertNull(action.getNamespace());
205  1 Assert.assertEquals(1, node.getChildren().size());
206   
207  1 node = node.getChildren().iterator().next();
208  1 action = node.getAction();
209  1 Assert.assertEquals(TestResources.REMOTE_NOTINSTALLED_DEPENDENCY_ID, action.getExtension().getId());
210  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
211  1 Assert.assertEquals(TestResources.INSTALLED_DEPENDENCY_ID, action.getPreviousExtension().getId());
212  1 Assert.assertNull(action.getNamespace());
213  1 Assert.assertEquals(0, node.getChildren().size());
214    }
215   
 
216  1 toggle @Test
217    public void testInstallPlanWithUpgradeFeatureWithDifferentVersion() throws Throwable
218    {
219  1 install(TestResources.REMOTE_UPGRADEFEATURE20_ID);
220   
221    // //////////////////
222    // Test upgrade
223   
224  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADEWITHFEATURE10_ID);
225   
226  1 Assert.assertEquals(2, plan.getTree().size());
227   
228  1 Iterator<ExtensionPlanNode> it = plan.getTree().iterator();
229   
230    // upgrade-feature
231   
232  1 ExtensionPlanNode node1 = it.next();
233   
234  1 ExtensionPlanAction action1 = node1.getAction();
235   
236  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEFEATURE20_ID, action1.getExtension().getId());
237  1 Assert.assertEquals(Action.UNINSTALL, action1.getAction());
238  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEFEATURE20_ID, action1.getPreviousExtension().getId());
239  1 Assert.assertNull(action1.getNamespace());
240  1 Assert.assertEquals(0, node1.getChildren().size());
241   
242    // upgrade-withfeature
243   
244  1 ExtensionPlanNode node2 = it.next();
245   
246  1 ExtensionPlanAction action2 = node2.getAction();
247   
248  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEWITHFEATURE10_ID, action2.getExtension().getId());
249  1 Assert.assertEquals(Action.UPGRADE, action2.getAction());
250  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEFEATURE20_ID, action2.getPreviousExtension().getId());
251  1 Assert.assertNull(action2.getNamespace());
252  1 Assert.assertEquals(0, node2.getChildren().size());
253    }
254   
 
255  1 toggle @Test
256    public void testInstallPlanWithDowngradeOnRoot() throws Throwable
257    {
258  1 install(TestResources.REMOTE_UPGRADE20_ID);
259   
260    // //////////////////
261    // Test downgrade
262   
263  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE10_ID);
264   
265  1 Assert.assertEquals(1, plan.getTree().size());
266   
267  1 ExtensionPlanNode node = plan.getTree().iterator().next();
268   
269  1 ExtensionPlanAction action = node.getAction();
270   
271  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
272  1 Assert.assertEquals(Action.DOWNGRADE, action.getAction());
273  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getPreviousExtension().getId());
274  1 Assert.assertNull(action.getNamespace());
275  1 Assert.assertEquals(0, node.getChildren().size());
276    }
277   
 
278  1 toggle @Test
279    public void testInstallOnNamespaceThenOnRoot() throws Throwable
280    {
281    // Install 1.0 on namespace
282  1 install(TestResources.REMOTE_UPGRADE10_ID, "namespace");
283   
284    // Move 1.0 on root
285  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE10_ID);
286   
287  1 Assert.assertEquals(2, plan.getTree().size());
288   
289  1 Iterator<ExtensionPlanNode> it = plan.getTree().iterator();
290   
291  1 ExtensionPlanNode node = it.next();
292  1 ExtensionPlanAction action = node.getAction();
293  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
294  1 Assert.assertEquals(Action.UNINSTALL, action.getAction());
295  1 Assert.assertEquals(1, action.getPreviousExtensions().size());
296  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
297  1 Assert.assertEquals("namespace", action.getNamespace());
298  1 Assert.assertEquals(0, node.getChildren().size());
299   
300  1 node = it.next();
301  1 action = node.getAction();
302  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
303  1 Assert.assertEquals(Action.INSTALL, action.getAction());
304  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
305  1 Assert.assertNull(action.getNamespace());
306  1 Assert.assertEquals(0, node.getChildren().size());
307    }
308   
 
309  1 toggle @Test
310    public void testInstallOnNamespaceThenUnpgradeOnRoot() throws Throwable
311    {
312    // Install 1.0 on namespace
313  1 install(TestResources.REMOTE_UPGRADE10_ID, "namespace");
314   
315    // Upgrade 2.0 on namespace
316  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE20_ID);
317   
318  1 Assert.assertEquals(2, plan.getTree().size());
319   
320  1 Iterator<ExtensionPlanNode> it = plan.getTree().iterator();
321   
322  1 ExtensionPlanNode node = it.next();
323  1 ExtensionPlanAction action = node.getAction();
324  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
325  1 Assert.assertEquals(Action.UNINSTALL, action.getAction());
326  1 Assert.assertEquals(1, action.getPreviousExtensions().size());
327  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
328  1 Assert.assertEquals("namespace", action.getNamespace());
329  1 Assert.assertEquals(0, node.getChildren().size());
330   
331  1 node = it.next();
332  1 action = node.getAction();
333  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
334  1 Assert.assertEquals(Action.INSTALL, action.getAction());
335  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
336  1 Assert.assertNull(action.getNamespace());
337  1 Assert.assertEquals(0, node.getChildren().size());
338    }
339   
340    // Errors
341   
 
342  1 toggle @Test(expected = InstallException.class)
343    public void testInstallPlanWithUnsupportedType() throws Throwable
344    {
345  1 installPlan(TestResources.REMOTE_UNSUPPORTED_ID);
346    }
347   
 
348  1 toggle @Test(expected = InstallException.class)
349    public void testInstallPlanWithCoreExtension() throws Throwable
350    {
351  1 this.coreRepository.addExtensions(TestResources.REMOTE_SIMPLE_ID.getId(), new DefaultVersion("version"));
352   
353  1 installPlan(TestResources.REMOTE_SIMPLE_ID);
354    }
355   
 
356  1 toggle @Test(expected = InstallException.class)
357    public void testInstallPlanWithFeatureAsCoreExtension() throws Throwable
358    {
359  1 this.coreRepository.addExtensions("rsimple-feature", new DefaultVersion("version"));
360   
361  1 installPlan(TestResources.REMOTE_SIMPLE_ID);
362    }
363   
 
364  1 toggle @Test(expected = InstallException.class)
365    public void testInstallPlanWithFeatureAsCoreExtensionFeature() throws Throwable
366    {
367  1 this.coreRepository.addExtensions("coreextension", new DefaultVersion("version"),
368    new ExtensionId("rsimple-feature"));
369   
370  1 installPlan(TestResources.REMOTE_SIMPLE_ID);
371    }
372   
 
373  1 toggle @Test(expected = InstallException.class)
374    public void testInstallPlanWithCoreExtensionFeature() throws Throwable
375    {
376  1 this.coreRepository.addExtensions("coreextension", new DefaultVersion("version"),
377    new ExtensionId(TestResources.REMOTE_SIMPLE_ID.getId()));
378   
379  1 installPlan(TestResources.REMOTE_SIMPLE_ID);
380    }
381   
 
382  1 toggle @Test(expected = InstallException.class)
383    public void testInstallPlanWithLowerCoreDependencyFeature() throws Throwable
384    {
385  1 this.coreRepository.addExtensions("coreextension", new DefaultVersion("3.0"),
386    TestResources.REMOTE_UPGRADE10_ID);
387   
388  1 installPlan(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID);
389    }
390   
 
391  1 toggle @Test
392    public void testInstallPlanWithHigherCoreDependencyFeature() throws Throwable
393    {
394  1 this.coreRepository.addExtensions("coreextension", new DefaultVersion("0.5"),
395    TestResources.REMOTE_UPGRADE20_ID);
396   
397  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID);
398   
399  1 Assert.assertEquals(1, plan.getTree().size());
400   
401  1 ExtensionPlanNode node = plan.getTree().iterator().next();
402   
403  1 ExtensionPlanAction action = node.getAction();
404   
405  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID, action.getExtension().getId());
406  1 Assert.assertEquals(Action.INSTALL, action.getAction());
407  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
408  1 Assert.assertNull(action.getNamespace());
409  1 Assert.assertEquals(1, node.getChildren().size());
410   
411  1 ExtensionPlanNode childnode = node.getChildren().iterator().next();
412   
413  1 Assert.assertTrue(childnode.getAction().getExtension() instanceof CoreExtension);
414  1 Assert.assertEquals(new ExtensionId("coreextension", "0.5"), childnode.getAction().getExtension().getId());
415  1 Assert.assertEquals(Action.NONE, childnode.getAction().getAction());
416  1 Assert.assertNull(node.getAction().getPreviousExtension());
417  1 Assert.assertTrue(childnode.getChildren().isEmpty());
418    }
419   
 
420  1 toggle @Test
421    public void testReInstalledWithMissingDependency() throws Throwable
422    {
423  1 ExtensionPlan plan = installPlan(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID);
424   
425  1 Assert.assertEquals(1, plan.getTree().size());
426   
427  1 ExtensionPlanNode node = plan.getTree().iterator().next();
428   
429  1 ExtensionPlanAction action = node.getAction();
430   
431  1 Assert.assertEquals(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, action.getExtension().getId());
432  1 Assert.assertEquals(Action.REPAIR, action.getAction());
433  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
434  1 Assert.assertNull(action.getNamespace());
435  1 Assert.assertEquals(1, node.getChildren().size());
436   
437  1 node = node.getChildren().iterator().next();
438  1 action = node.getAction();
439   
440  1 Assert.assertEquals(TestResources.REMOTE_MISSINGDEPENDENCY_ID, action.getExtension().getId());
441  1 Assert.assertEquals(Action.INSTALL, action.getAction());
442  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
443  1 Assert.assertNull(action.getNamespace());
444  1 Assert.assertEquals(0, node.getChildren().size());
445    }
446   
 
447  1 toggle @Test
448    public void testInstallRemoteWithMissingDependency() throws Throwable
449    {
450  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITHRMISSINGDEPENDENCY_ID);
451   
452  1 Assert.assertEquals(1, plan.getTree().size());
453   
454  1 ExtensionPlanNode node = plan.getTree().iterator().next();
455  1 ExtensionPlanAction action = node.getAction();
456   
457  1 Assert.assertEquals(TestResources.REMOTE_WITHRMISSINGDEPENDENCY_ID, action.getExtension().getId());
458  1 Assert.assertEquals(Action.INSTALL, action.getAction());
459  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
460  1 Assert.assertNull(action.getNamespace());
461  1 Assert.assertEquals(1, node.getChildren().size());
462   
463  1 node = node.getChildren().iterator().next();
464  1 action = node.getAction();
465   
466  1 Assert.assertEquals(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, action.getExtension().getId());
467  1 Assert.assertEquals(Action.REPAIR, action.getAction());
468  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
469  1 Assert.assertNull(action.getNamespace());
470  1 Assert.assertEquals(1, node.getChildren().size());
471   
472  1 node = node.getChildren().iterator().next();
473  1 action = node.getAction();
474   
475  1 Assert.assertEquals(TestResources.REMOTE_MISSINGDEPENDENCY_ID, action.getExtension().getId());
476  1 Assert.assertEquals(Action.INSTALL, action.getAction());
477  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
478  1 Assert.assertNull(action.getNamespace());
479  1 Assert.assertEquals(0, node.getChildren().size());
480    }
481   
 
482  1 toggle @Test
483    public void testInstallNameSpaceExtensionWithExistingRootExtension() throws Throwable
484    {
485    // Install 1.0 on root
486  1 install(TestResources.REMOTE_UPGRADE10_ID);
487    // Try to upgrade 2.0 on namespace
488  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_UPGRADE20_ID, "namespace");
489   
490  1 Assert.assertEquals(1, plan.getTree().size());
491   
492  1 ExtensionPlanNode node = plan.getTree().iterator().next();
493  1 ExtensionPlanAction action = node.getAction();
494   
495  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
496  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
497  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getPreviousExtension().getId());
498  1 Assert.assertNull(action.getNamespace());
499  1 Assert.assertEquals(0, node.getChildren().size());
500    }
501   
 
502  1 toggle @Test
503    public void testInstallNameSpaceExtensionWithDependencyAllowedOnRootOnly() throws Throwable
504    {
505    // Try to install remote extension with only root allowed dependency on namespace
506  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_ROOT_DEPENDENY10_ID, "namespace");
507   
508  1 Assert.assertEquals(1, plan.getTree().size());
509   
510  1 ExtensionPlanNode node = plan.getTree().iterator().next();
511  1 ExtensionPlanAction action = node.getAction();
512   
513  1 Assert.assertEquals(TestResources.REMOTE_WITH_ROOT_DEPENDENY10_ID, action.getExtension().getId());
514  1 Assert.assertEquals(Action.INSTALL, action.getAction());
515  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
516  1 Assert.assertEquals("namespace", action.getNamespace());
517  1 Assert.assertEquals(1, node.getChildren().size());
518   
519  1 node = node.getChildren().iterator().next();
520  1 action = node.getAction();
521   
522  1 Assert.assertEquals(TestResources.REMOTE_ROOTEXTENSION10_ID, action.getExtension().getId());
523  1 Assert.assertEquals(Action.INSTALL, action.getAction());
524  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
525  1 Assert.assertNull(action.getNamespace());
526  1 Assert.assertEquals(0, node.getChildren().size());
527    }
528   
 
529  1 toggle @Test
530    public void testUpgradeExtensionOnNamespaceWithDependencyAllowedOnRootOnly() throws Throwable
531    {
532    // Instance version 1.0
533  1 install(TestResources.REMOTE_WITH_ROOT_DEPENDENY10_ID, "namespace");
534   
535    // Try to upgrade remote extension with only root allowed dependency on namespace
536  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_ROOT_DEPENDENY20_ID, "namespace");
537   
538  1 Assert.assertEquals(1, plan.getTree().size());
539   
540  1 ExtensionPlanNode node = plan.getTree().iterator().next();
541  1 ExtensionPlanAction action = node.getAction();
542   
543  1 Assert.assertEquals(TestResources.REMOTE_WITH_ROOT_DEPENDENY20_ID, action.getExtension().getId());
544  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
545  1 Assert.assertEquals(TestResources.REMOTE_WITH_ROOT_DEPENDENY10_ID, action.getPreviousExtension().getId());
546  1 Assert.assertEquals("namespace", action.getNamespace());
547  1 Assert.assertEquals(1, node.getChildren().size());
548   
549  1 node = node.getChildren().iterator().next();
550  1 action = node.getAction();
551   
552  1 Assert.assertEquals(TestResources.REMOTE_ROOTEXTENSION20_ID, action.getExtension().getId());
553  1 Assert.assertEquals(Action.UPGRADE, action.getAction());
554  1 Assert.assertEquals(TestResources.REMOTE_ROOTEXTENSION10_ID, action.getPreviousExtension().getId());
555  1 Assert.assertNull(action.getNamespace());
556  1 Assert.assertEquals(0, node.getChildren().size());
557    }
558   
 
559  1 toggle @Test
560    public void testInstallWithOverwrittenManagedDependency() throws Throwable
561    {
562  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_OVERWRITTEN_MANAGED_DEPENDENY_ID, "namespace");
563   
564  1 Assert.assertEquals(1, plan.getTree().size());
565   
566  1 ExtensionPlanNode node = plan.getTree().iterator().next();
567  1 ExtensionPlanAction action = node.getAction();
568   
569  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
570  1 Assert.assertEquals(Action.INSTALL, action.getAction());
571  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
572  1 Assert.assertEquals("namespace", action.getNamespace());
573  1 Assert.assertEquals(1, node.getChildren().size());
574   
575  1 node = node.getChildren().iterator().next();
576  1 action = node.getAction();
577   
578  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
579  1 Assert.assertEquals(Action.INSTALL, action.getAction());
580  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
581  1 Assert.assertEquals("namespace", action.getNamespace());
582  1 Assert.assertEquals(0, node.getChildren().size());
583    }
584   
 
585  1 toggle @Test
586    public void testInstallWithManagedTransitiveDependency() throws Throwable
587    {
588  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_MANAGED_TRANSITIVEDEPENDENY_ID, "namespace");
589   
590  1 Assert.assertEquals(1, plan.getTree().size());
591   
592  1 ExtensionPlanNode node = plan.getTree().iterator().next();
593  1 ExtensionPlanAction action = node.getAction();
594   
595  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
596  1 Assert.assertEquals(Action.INSTALL, action.getAction());
597  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
598  1 Assert.assertEquals("namespace", action.getNamespace());
599  1 Assert.assertEquals(1, node.getChildren().size());
600   
601  1 node = node.getChildren().iterator().next();
602  1 action = node.getAction();
603   
604  1 Assert.assertEquals(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID, action.getExtension().getId());
605  1 Assert.assertEquals(Action.INSTALL, action.getAction());
606  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
607  1 Assert.assertEquals("namespace", action.getNamespace());
608  1 Assert.assertEquals(1, node.getChildren().size());
609   
610  1 node = node.getChildren().iterator().next();
611  1 action = node.getAction();
612   
613  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
614  1 Assert.assertEquals(Action.INSTALL, action.getAction());
615  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
616  1 Assert.assertEquals("namespace", action.getNamespace());
617  1 Assert.assertEquals(0, node.getChildren().size());
618    }
619   
 
620  1 toggle @Test
621    public void testInstallWithManagedDependency() throws Throwable
622    {
623  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, "namespace");
624   
625  1 Assert.assertEquals(1, plan.getTree().size());
626   
627  1 ExtensionPlanNode node = plan.getTree().iterator().next();
628  1 ExtensionPlanAction action = node.getAction();
629   
630  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
631  1 Assert.assertEquals(Action.INSTALL, action.getAction());
632  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
633  1 Assert.assertEquals("namespace", action.getNamespace());
634  1 Assert.assertEquals(1, node.getChildren().size());
635   
636  1 node = node.getChildren().iterator().next();
637  1 action = node.getAction();
638   
639  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
640  1 Assert.assertEquals(Action.INSTALL, action.getAction());
641  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
642  1 Assert.assertEquals("namespace", action.getNamespace());
643  1 Assert.assertEquals(0, node.getChildren().size());
644    }
645   
 
646  1 toggle @Test
647    public void testInstallWithRecommendedManagedDependency() throws Throwable
648    {
649    // Change the version of the dependency trough recommended version
650  1 this.coreRepository.getConfigurableEnvironmentExtension().putProperty("xwiki.extension.recommendedVersions",
651    "upgrade/2.0");
652   
653  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, "namespace");
654   
655  1 Assert.assertEquals(1, plan.getTree().size());
656   
657  1 ExtensionPlanNode node = plan.getTree().iterator().next();
658  1 ExtensionPlanAction action = node.getAction();
659   
660  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
661  1 Assert.assertEquals(Action.INSTALL, action.getAction());
662  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
663  1 Assert.assertEquals("namespace", action.getNamespace());
664  1 Assert.assertEquals(1, node.getChildren().size());
665   
666  1 node = node.getChildren().iterator().next();
667  1 action = node.getAction();
668   
669  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
670  1 Assert.assertEquals(Action.INSTALL, action.getAction());
671  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
672  1 Assert.assertEquals("namespace", action.getNamespace());
673  1 Assert.assertEquals(0, node.getChildren().size());
674    }
675   
 
676  1 toggle @Test
677    public void testInstallWithStrictRecommendedManagedDependency() throws Throwable
678    {
679    // Change the version of the dependency trough recommended version
680  1 this.coreRepository.getConfigurableEnvironmentExtension().putProperty("xwiki.extension.recommendedVersions",
681    "upgrade/[2.0]");
682   
683  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, "namespace");
684   
685  1 Assert.assertEquals(1, plan.getTree().size());
686   
687  1 ExtensionPlanNode node = plan.getTree().iterator().next();
688  1 ExtensionPlanAction action = node.getAction();
689   
690  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
691  1 Assert.assertEquals(Action.INSTALL, action.getAction());
692  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
693  1 Assert.assertEquals("namespace", action.getNamespace());
694  1 Assert.assertEquals(1, node.getChildren().size());
695   
696  1 node = node.getChildren().iterator().next();
697  1 action = node.getAction();
698   
699  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE20_ID, action.getExtension().getId());
700  1 Assert.assertEquals(Action.INSTALL, action.getAction());
701  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
702  1 Assert.assertEquals("namespace", action.getNamespace());
703  1 Assert.assertEquals(0, node.getChildren().size());
704    }
705   
 
706  1 toggle @Test
707    public void testInstallWithInvalidRecommendedManagedDependency() throws Throwable
708    {
709    // Change the version of the dependency trough recommended version
710  1 this.coreRepository.getConfigurableEnvironmentExtension().putProperty("xwiki.extension.recommendedVersions",
711    "upgrade/10.0");
712   
713  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, "namespace");
714   
715  1 Assert.assertEquals(1, plan.getTree().size());
716   
717  1 ExtensionPlanNode node = plan.getTree().iterator().next();
718  1 ExtensionPlanAction action = node.getAction();
719   
720  1 Assert.assertEquals(TestResources.REMOTE_WITH_MANAGED_DEPENDENY_ID, action.getExtension().getId());
721  1 Assert.assertEquals(Action.INSTALL, action.getAction());
722  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
723  1 Assert.assertEquals("namespace", action.getNamespace());
724  1 Assert.assertEquals(1, node.getChildren().size());
725   
726  1 node = node.getChildren().iterator().next();
727  1 action = node.getAction();
728   
729  1 Assert.assertEquals(TestResources.REMOTE_UPGRADE10_ID, action.getExtension().getId());
730  1 Assert.assertEquals(Action.INSTALL, action.getAction());
731  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
732  1 Assert.assertEquals("namespace", action.getNamespace());
733  1 Assert.assertEquals(0, node.getChildren().size());
734    }
735   
 
736  1 toggle @Test
737    public void testInstallWithInvalidOptionalDependency() throws Throwable
738    {
739  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_WITHRMISSINGOPTIONALDEPENDENCY_ID, "namespace");
740   
741  1 Assert.assertEquals(1, plan.getTree().size());
742   
743  1 ExtensionPlanNode node = plan.getTree().iterator().next();
744  1 ExtensionPlanAction action = node.getAction();
745   
746  1 Assert.assertEquals(TestResources.REMOTE_WITHRMISSINGOPTIONALDEPENDENCY_ID, action.getExtension().getId());
747  1 Assert.assertEquals(Action.INSTALL, action.getAction());
748  1 Assert.assertEquals(0, action.getPreviousExtensions().size());
749  1 Assert.assertEquals("namespace", action.getNamespace());
750  1 Assert.assertEquals(0, node.getChildren().size());
751    }
752   
 
753  1 toggle @Test
754    public void testInstallPlanWithCrossDependencies() throws Throwable
755    {
756  1 ExtensionPlan plan = installPlan(TestResources.REMOTE_CROSSDEPENDENCY1);
757   
758    // Tree
759   
760  1 Assert.assertEquals(1, plan.getTree().size());
761   
762  1 ExtensionPlanNode node = plan.getTree().iterator().next();
763   
764  1 ExtensionPlanAction action = node.getAction();
765   
766  1 Assert.assertEquals(TestResources.REMOTE_CROSSDEPENDENCY1, action.getExtension().getId());
767  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
768  1 Assert.assertEquals(1, node.getChildren().size());
769   
770  1 ExtensionPlanNode childnode = node.getChildren().iterator().next();
771   
772  1 Assert.assertEquals(TestResources.REMOTE_CROSSDEPENDENCY2, childnode.getAction().getExtension().getId());
773  1 Assert.assertEquals(Action.INSTALL, node.getAction().getAction());
774    }
775   
776    // Failures
777   
 
778  1 toggle @Test(expected = InstallException.class)
779    public void testForbiddenInstallLowerVersionOfDependencyOnRoot() throws Throwable
780    {
781    // Install extension 2.0 on namespace
782  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID, "namespace");
783    // Install dependency 1.0 on root
784  1 installPlan(TestResources.REMOTE_UPGRADE10_ID, false);
785    }
786   
 
787  1 toggle @Test(expected = InstallException.class)
788    public void testForbiddenInstallNameSpaceExtensionWithExistingRootExtension() throws Throwable
789    {
790    // Install 1.0 on root
791  1 install(TestResources.REMOTE_UPGRADE10_ID);
792    // Try to upgrade 2.0 on namespace
793  1 installPlan(TestResources.REMOTE_UPGRADE20_ID, "namespace", false);
794    }
795   
 
796  1 toggle @Test(expected = InstallException.class)
797    public void testForbiddenInstallNameSpaceExtensionWithIncompatibleRootDependency() throws Throwable
798    {
799    // Install 1.0 on root
800  1 install(TestResources.REMOTE_UPGRADE10_ID);
801    // Install extension 2.0 on namespace
802  1 installPlan(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID, "namespace", false);
803    }
804   
 
805  1 toggle @Test
806    public void testForbiddenInstallExtensionOnIncompatibleNamespace() throws Throwable
807    {
808    // Install 1.0 on root
809  1 install(TestResources.REMOTE_ROOTEXTENSION10_ID);
810  1 uninstall(TestResources.REMOTE_ROOTEXTENSION10_ID, null);
811   
812    // Install 1.0 on incompatible namespace
813  1 try {
814  1 install(TestResources.REMOTE_ROOTEXTENSION10_ID, "namespace", false);
815   
816  0 fail("Should not be allowed to install [" + TestResources.REMOTE_ROOTEXTENSION10_ID
817    + "] on namespace [namespace]");
818    } catch (InstallException e) {
819   
820    }
821    }
822   
 
823  1 toggle @Test(expected = InstallException.class)
824    public void testInstallPlanWithUpgradeOnDifferentIdNotAllowed() throws Throwable
825    {
826  1 InstallRequest installRequest = createInstallRequest(TestResources.REMOTE_NOTINSTALLED_ID);
827  1 installRequest.setUninstallAllowed(false);
828   
829  1 installPlan(installRequest);
830    }
831    }