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

File InstallJobTest.java

 

Code metrics

0
123
12
1
345
237
12
0.1
10.25
12
1

Classes

Class Line # Actions
InstallJobTest 39 123 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 11 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.Arrays;
23    import java.util.Collections;
24   
25    import org.junit.Assert;
26    import org.junit.Test;
27    import org.xwiki.extension.ExtensionId;
28    import org.xwiki.extension.InstalledExtension;
29    import org.xwiki.extension.LocalExtension;
30    import org.xwiki.extension.TestResources;
31    import org.xwiki.extension.handler.ExtensionHandler;
32    import org.xwiki.extension.test.AbstractExtensionHandlerTest;
33    import org.xwiki.extension.test.TestExtensionHandler;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.junit.Assert.assertNotNull;
37    import static org.junit.Assert.assertTrue;
38   
 
39    public class InstallJobTest extends AbstractExtensionHandlerTest
40    {
41    private TestExtensionHandler handler;
42   
 
43  11 toggle @Override
44    public void setUp() throws Exception
45    {
46  11 super.setUp();
47   
48    // lookup
49   
50  11 this.handler = (TestExtensionHandler) this.mocker.getInstance(ExtensionHandler.class, "test");
51    }
52   
 
53  1 toggle @Test
54    public void testInstallOnRoot() throws Throwable
55    {
56  1 install(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID);
57   
58    // Is extension installed
59  1 InstalledExtension installedExtension = this.installedExtensionRepository
60    .getInstalledExtension(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID.getId(), null);
61  1 Assert.assertNotNull(installedExtension);
62  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
63  1 Assert.assertNotNull(this.installedExtensionRepository
64    .getInstalledExtension(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID.getId(), "namespace"));
65  1 Assert.assertFalse(installedExtension.isDependency(null));
66  1 Assert.assertFalse(installedExtension.isDependency("namespace"));
67   
68    // Is dependency installed
69  1 installedExtension =
70    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), null);
71  1 Assert.assertNotNull(installedExtension);
72  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
73  1 Assert.assertNotNull(this.installedExtensionRepository
74    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace"));
75  1 Assert.assertTrue(installedExtension.isDependency(null));
76  1 Assert.assertTrue(installedExtension.isDependency("namespace"));
77    }
78   
 
79  1 toggle @Test
80    public void testInstallRemoteOnNamespace() throws Throwable
81    {
82  1 install(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID, "namespace");
83   
84    // Is extension installed
85  1 InstalledExtension installedExtension = this.installedExtensionRepository
86    .getInstalledExtension(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID.getId(), "namespace");
87  1 Assert.assertNotNull(installedExtension);
88  1 Assert.assertTrue(this.handler.getExtensions().get("namespace").contains(installedExtension));
89  1 Assert.assertFalse(installedExtension.isDependency(null));
90  1 Assert.assertFalse(installedExtension.isDependency("namespace"));
91   
92    // Is dependency installed
93  1 installedExtension = this.installedExtensionRepository
94    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace");
95  1 Assert.assertNotNull(installedExtension);
96  1 Assert.assertTrue(this.handler.getExtensions().get("namespace").contains(installedExtension));
97  1 Assert.assertFalse(installedExtension.isDependency(null));
98  1 Assert.assertTrue(installedExtension.isDependency("namespace"));
99    }
100   
 
101  1 toggle @Test
102    public void testInstallRemoteOnNamespaces() throws Throwable
103    {
104  1 install(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID, new String[] { "namespace1", "namespace2" });
105   
106  1 LocalExtension installedExtension = this.installedExtensionRepository
107    .getInstalledExtension(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID.getId(), "namespace1");
108  1 Assert.assertNotNull(installedExtension);
109  1 Assert.assertNotNull(this.installedExtensionRepository
110    .getInstalledExtension(TestResources.REMOTE_WITHRANDCDEPENDENCIES_ID.getId(), "namespace2"));
111  1 Assert.assertTrue(this.handler.getExtensions().get("namespace1").contains(installedExtension));
112  1 Assert.assertTrue(this.handler.getExtensions().get("namespace2").contains(installedExtension));
113   
114  1 installedExtension = this.installedExtensionRepository
115    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace1");
116  1 Assert.assertNotNull(installedExtension);
117  1 Assert.assertNotNull(this.installedExtensionRepository
118    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace2"));
119  1 Assert.assertTrue(this.handler.getExtensions().get("namespace1").contains(installedExtension));
120  1 Assert.assertTrue(this.handler.getExtensions().get("namespace2").contains(installedExtension));
121    }
122   
 
123  1 toggle @Test
124    public void testUpgradeFirstOnRoot() throws Throwable
125    {
126  1 install(TestResources.REMOTE_UPGRADE10_ID);
127   
128  1 LocalExtension installedExtension;
129   
130    // Test upgrade
131   
132  1 install(TestResources.REMOTE_UPGRADE20_ID);
133   
134  1 installedExtension =
135    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), null);
136  1 Assert.assertNotNull(installedExtension);
137  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
138  1 Assert.assertNotNull(this.installedExtensionRepository
139    .getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), "namespace"));
140   
141  1 Assert.assertNull(installedExtension =
142    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID));
143   
144    // Test downgrade
145   
146  1 install(TestResources.REMOTE_UPGRADE10_ID);
147   
148  1 installedExtension =
149    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), null);
150  1 Assert.assertNotNull(installedExtension);
151  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
152  1 Assert.assertNotNull(this.installedExtensionRepository
153    .getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), "namespace"));
154    }
155   
 
156  1 toggle @Test
157    public void testDowngradeFirstOnRoot() throws Throwable
158    {
159  1 install(TestResources.REMOTE_UPGRADE20_ID);
160   
161  1 LocalExtension installedExtension;
162   
163    // //////////////////
164    // Test downgrade
165   
166  1 install(TestResources.REMOTE_UPGRADE10_ID);
167   
168  1 installedExtension =
169    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), null);
170  1 Assert.assertNotNull(installedExtension);
171  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
172  1 Assert.assertNotNull(this.installedExtensionRepository
173    .getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), "namespace"));
174   
175    // Test upgrade
176   
177  1 install(TestResources.REMOTE_UPGRADE20_ID);
178   
179  1 installedExtension =
180    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), null);
181  1 Assert.assertNotNull(installedExtension);
182  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
183  1 Assert.assertNotNull(this.installedExtensionRepository
184    .getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), "namespace"));
185    }
186   
 
187  1 toggle @Test
188    public void testReplaceDependencyWithFeature() throws Throwable
189    {
190  1 InstalledExtension installedextension =
191    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID);
192   
193    // installedextensiondependency 1.0
194  1 Assert.assertEquals(Arrays.asList(installedextension), this.installedExtensionRepository
195    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
196  1 Assert.assertEquals(Collections.singletonMap(null, Arrays.asList(installedextension)),
197    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID));
198   
199  1 ExtensionId installedextensiondependency2 = new ExtensionId("overrideinstalledextensiondependency", "2.0");
200   
201    // change dependency
202  1 install(installedextensiondependency2);
203   
204    // installedextensiondependency 2.0
205  1 Assert.assertEquals(Arrays.asList(installedextension), this.installedExtensionRepository
206    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
207    // overrideinstalledextensiondependency
208  1 Assert.assertEquals(Arrays.asList(installedextension),
209    this.installedExtensionRepository.getBackwardDependencies(installedextensiondependency2.getId(), null));
210  1 Assert.assertEquals(Collections.singletonMap(null, Arrays.asList(installedextension)),
211    this.installedExtensionRepository.getBackwardDependencies(installedextensiondependency2));
212    }
213   
 
214  1 toggle @Test
215    public void testInstallOnNamespaceThenOnRoot() throws Throwable
216    {
217    // Install 1.0 on "namespace"
218   
219  1 install(TestResources.REMOTE_UPGRADE10_ID, "namespace");
220   
221  1 InstalledExtension installedExtension =
222    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID);
223   
224  1 Assert.assertNotNull(installedExtension);
225  1 Assert.assertNotNull(installedExtension.getNamespaces());
226  1 Assert.assertTrue(this.handler.getExtensions().get("namespace").contains(installedExtension));
227   
228    // Install 1.0 on root
229   
230  1 install(TestResources.REMOTE_UPGRADE10_ID);
231   
232  1 installedExtension =
233    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), null);
234  1 Assert.assertSame(installedExtension, this.installedExtensionRepository
235    .getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID.getId(), "namespace"));
236  1 Assert.assertNotNull(installedExtension);
237  1 Assert.assertNull("Extension is not marked as installed on root", installedExtension.getNamespaces());
238  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension));
239    }
240   
 
241  1 toggle @Test
242    public void testInstallOnNamespaceThenUpgradeOnRoot() throws Throwable
243    {
244    // Install 1.0 on "namespace"
245   
246  1 install(TestResources.REMOTE_UPGRADE10_ID, "namespace");
247   
248  1 InstalledExtension installedExtension1 =
249    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID);
250   
251  1 Assert.assertNotNull(installedExtension1);
252   
253    // Upgrade 2.0 on root
254   
255  1 install(TestResources.REMOTE_UPGRADE20_ID);
256   
257  1 installedExtension1 =
258    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID);
259   
260  1 Assert.assertNull(installedExtension1);
261   
262  1 LocalExtension installedExtension2 =
263    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), null);
264  1 Assert.assertNotNull(installedExtension2);
265  1 Assert.assertTrue(this.handler.getExtensions().get(null).contains(installedExtension2));
266   
267  1 Assert.assertNull(installedExtension2 =
268    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID));
269    }
270   
 
271  1 toggle @Test
272    public void testInstallOnNamespaceThenMoveDependencyOnRoot() throws Throwable
273    {
274  1 install(TestResources.REMOTE_WITHRDEPENDENCY_ID, "namespace");
275   
276  1 Assert.assertNotNull(this.installedExtensionRepository
277    .getInstalledExtension(TestResources.REMOTE_WITHRDEPENDENCY_ID.getId(), "namespace"));
278  1 Assert.assertNotNull(this.installedExtensionRepository
279    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace"));
280   
281  1 install(TestResources.REMOTE_SIMPLE_ID);
282   
283  1 Assert.assertNotNull(this.installedExtensionRepository
284    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), "namespace"));
285  1 Assert.assertNotNull(
286    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), null));
287  1 Assert.assertNotNull(this.installedExtensionRepository
288    .getInstalledExtension(TestResources.REMOTE_WITHRDEPENDENCY_ID.getId(), "namespace"));
289  1 Assert.assertNull(this.installedExtensionRepository
290    .getInstalledExtension(TestResources.REMOTE_WITHRDEPENDENCY_ID.getId(), null));
291    }
292   
 
293  1 toggle @Test
294    public void testInstallOnNamespaceThenOnRootWithLowerDependency() throws Throwable
295    {
296    // Install extension on namespace
297  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID, "namespace");
298    // Upgrade dependency
299  1 install(TestResources.REMOTE_OTHERUPGRADEWITHDEPENDENCY20_ID, "namespace");
300   
301  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID));
302  1 Assert.assertNull(
303    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID));
304   
305    // Install extension on root
306  1 install(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID);
307   
308  1 Assert.assertNull(this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE10_ID));
309  1 Assert.assertNull(
310    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADEWITHDEPENDENCY20_ID));
311   
312  1 Assert.assertNotNull(this.installedExtensionRepository
313    .getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), "namespace"));
314  1 Assert.assertNotNull(
315    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_UPGRADE20_ID.getId(), null));
316  1 Assert.assertNotNull(this.installedExtensionRepository
317    .getInstalledExtension(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID.getId(), "namespace"));
318  1 Assert.assertNotNull(this.installedExtensionRepository
319    .getInstalledExtension(TestResources.REMOTE_UPGRADEWITHDEPENDENCY10_ID.getId(), null));
320    }
321   
 
322  1 toggle @Test
323    public void testInstallRemoteWithMissingDependency() throws Throwable
324    {
325  1 install(TestResources.REMOTE_WITHRMISSINGDEPENDENCY_ID);
326   
327  1 InstalledExtension installedExtension = this.installedExtensionRepository
328    .getInstalledExtension(TestResources.REMOTE_WITHRMISSINGDEPENDENCY_ID.getId(), "namespace");
329  1 assertNotNull(installedExtension);
330  1 assertEquals(TestResources.REMOTE_WITHRMISSINGDEPENDENCY_ID, installedExtension.getId());
331  1 assertTrue(installedExtension.isValid("namespace"));
332   
333  1 installedExtension = this.installedExtensionRepository
334    .getInstalledExtension(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID.getId(), "namespace");
335  1 assertNotNull(installedExtension);
336  1 assertEquals(TestResources.INSTALLED_WITHMISSINDEPENDENCY_ID, installedExtension.getId());
337  1 assertTrue(installedExtension.isValid("namespace"));
338   
339  1 installedExtension = this.installedExtensionRepository
340    .getInstalledExtension(TestResources.REMOTE_MISSINGDEPENDENCY_ID.getId(), "namespace");
341  1 assertNotNull(installedExtension);
342  1 assertEquals(TestResources.REMOTE_MISSINGDEPENDENCY_ID, installedExtension.getId());
343  1 assertTrue(installedExtension.isValid("namespace"));
344    }
345    }