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

File DefaultInstalledExtensionRepositoryTest.java

 

Code metrics

0
246
20
1
658
449
25
0.1
12.3
20
1.25

Classes

Class Line # Actions
DefaultInstalledExtensionRepositoryTest 65 246 0% 25 5
0.98120398.1%
 

Contributing tests

This file is covered by 17 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.repository.installed;
21   
22    import java.util.ArrayList;
23    import java.util.Arrays;
24    import java.util.Collection;
25    import java.util.Collections;
26    import java.util.HashMap;
27    import java.util.Map;
28   
29    import org.junit.Before;
30    import org.junit.Rule;
31    import org.junit.Test;
32    import org.xwiki.extension.DefaultExtensionDependency;
33    import org.xwiki.extension.Extension;
34    import org.xwiki.extension.ExtensionDependency;
35    import org.xwiki.extension.ExtensionId;
36    import org.xwiki.extension.InstallException;
37    import org.xwiki.extension.InstalledExtension;
38    import org.xwiki.extension.LocalExtension;
39    import org.xwiki.extension.ResolveException;
40    import org.xwiki.extension.TestResources;
41    import org.xwiki.extension.UninstallException;
42    import org.xwiki.extension.handler.ExtensionHandler;
43    import org.xwiki.extension.repository.ExtensionRepositoryManager;
44    import org.xwiki.extension.repository.InstalledExtensionRepository;
45    import org.xwiki.extension.repository.LocalExtensionRepository;
46    import org.xwiki.extension.repository.LocalExtensionRepositoryException;
47    import org.xwiki.extension.repository.result.IterableResult;
48    import org.xwiki.extension.repository.search.ExtensionQuery;
49    import org.xwiki.extension.repository.search.ExtensionQuery.COMPARISON;
50    import org.xwiki.extension.repository.search.SearchException;
51    import org.xwiki.extension.test.MockitoRepositoryUtilsRule;
52    import org.xwiki.extension.test.TestExtensionHandler;
53    import org.xwiki.extension.version.internal.DefaultVersionConstraint;
54    import org.xwiki.test.annotation.AllComponents;
55   
56    import static org.junit.Assert.assertEquals;
57    import static org.junit.Assert.assertFalse;
58    import static org.junit.Assert.assertNotNull;
59    import static org.junit.Assert.assertNull;
60    import static org.junit.Assert.assertSame;
61    import static org.junit.Assert.assertTrue;
62    import static org.junit.Assert.fail;
63   
64    @AllComponents
 
65    public class DefaultInstalledExtensionRepositoryTest
66    {
67    @Rule
68    public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule();
69   
70    private InstalledExtensionRepository installedExtensionRepository;
71   
72    private LocalExtensionRepository localExtensionRepository;
73   
74    private ExtensionRepositoryManager repositoryManager;
75   
76    private TestResources resources;
77   
78    private TestExtensionHandler handler;
79   
 
80  17 toggle @Before
81    public void setUp() throws Exception
82    {
83    // lookup
84   
85  17 this.installedExtensionRepository =
86    this.repositoryUtil.getComponentManager().getInstance(InstalledExtensionRepository.class);
87  17 this.localExtensionRepository =
88    this.repositoryUtil.getComponentManager().getInstance(LocalExtensionRepository.class);
89  17 this.repositoryManager =
90    this.repositoryUtil.getComponentManager().getInstance(ExtensionRepositoryManager.class);
91  17 this.handler = this.repositoryUtil.getComponentManager().getInstance(ExtensionHandler.class, "test");
92   
93    // resources
94   
95  17 this.resources = new TestResources();
96  17 this.resources.init(this.installedExtensionRepository);
97    }
98   
 
99  1 toggle private void install(ExtensionId extensionId)
100    throws ResolveException, LocalExtensionRepositoryException, InstallException
101    {
102  1 Extension extension = this.repositoryManager.resolve(extensionId);
103   
104    // store
105   
106  1 this.localExtensionRepository.storeExtension(extension);
107   
108  1 LocalExtension localExtension = this.localExtensionRepository.resolve(extensionId);
109   
110  1 assertEquals(extensionId, localExtension.getId());
111   
112    // install
113   
114  1 this.installedExtensionRepository.installExtension(localExtension, null, false);
115    }
116   
117    // Tests
118   
 
119  1 toggle @Test
120    public void testInit()
121    {
122  1 assertTrue(this.installedExtensionRepository.countExtensions() > 0);
123   
124    // installedonnamespace
125  1 InstalledExtension extension =
126    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ONNAMESPACE_ID);
127   
128  1 assertNotNull(extension);
129  1 assertEquals(TestResources.INSTALLED_ONNAMESPACE_ID, extension.getId());
130   
131  1 extension = this.installedExtensionRepository
132    .getInstalledExtension(TestResources.INSTALLED_ONNAMESPACE_ID.getId(), "namespace");
133   
134  1 assertNotNull(extension);
135  1 assertEquals(TestResources.INSTALLED_ONNAMESPACE_ID, extension.getId());
136  1 assertTrue(extension.isValid("namespace"));
137   
138    // installedextension
139  1 extension = this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID);
140   
141  1 assertNotNull(extension);
142  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
143   
144  1 extension =
145    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace");
146   
147  1 assertNotNull(extension);
148  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
149  1 assertTrue(this.handler.getExtensions().get(null).contains(extension));
150  1 assertFalse(this.handler.getExtensions().get("namespace").contains(extension));
151  1 assertSame(extension,
152    this.installedExtensionRepository.getInstalledExtension("installedextension", "namespace"));
153   
154    // installedonnemspacewithrootdependency
155  1 extension = this.installedExtensionRepository
156    .getInstalledExtension(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID);
157   
158  1 assertNotNull(extension);
159  1 assertEquals(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID, extension.getId());
160   
161  1 extension = this.installedExtensionRepository
162    .getInstalledExtension(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID.getId(), "namespace");
163   
164  1 assertNotNull(extension);
165  1 assertEquals(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID, extension.getId());
166  1 assertFalse(this.handler.getExtensions().get(null).contains(extension));
167  1 assertTrue(this.handler.getExtensions().get("namespace").contains(extension));
168   
169    // installedwithfeatureasdependency
170  1 extension =
171    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_WITHFEATUREASDEPENDENCY_ID);
172   
173  1 assertNotNull(extension);
174  1 assertEquals(TestResources.INSTALLED_WITHFEATUREASDEPENDENCY_ID, extension.getId());
175   
176  1 extension = this.installedExtensionRepository
177    .getInstalledExtension(TestResources.INSTALLED_WITHFEATUREASDEPENDENCY_ID.getId(), "namespace");
178   
179  1 assertNotNull(extension);
180  1 assertEquals(TestResources.INSTALLED_WITHFEATUREASDEPENDENCY_ID, extension.getId());
181  1 assertTrue(this.handler.getExtensions().get(null).contains(extension));
182  1 assertFalse(this.handler.getExtensions().get("namespace").contains(extension));
183   
184    // invalidextension
185  1 extension = this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_INVALID_ID);
186   
187  1 assertNotNull(extension);
188  1 assertEquals(TestResources.INSTALLED_INVALID_ID, extension.getId());
189  1 assertFalse(extension.isValid(null));
190  1 assertFalse(this.handler.getExtensions().get(null).contains(extension));
191  1 assertFalse(this.handler.getExtensions().get("namespace").contains(extension));
192   
193    // installedmanagedextension
194  1 extension = this.installedExtensionRepository.getInstalledExtension("installedmanagedextension", null);
195   
196  1 assertNotNull(extension);
197  1 assertTrue(extension.isValid(null));
198  1 assertEquals("2.0", extension.getId().getVersion().toString());
199   
200  1 extension = this.installedExtensionRepository.getInstalledExtension("installedmanagedextension", "namespace");
201   
202  1 assertNotNull(extension);
203  1 assertTrue(extension.isValid(null));
204  1 assertEquals("2.0", extension.getId().getVersion().toString());
205   
206  1 extension = this.installedExtensionRepository.getInstalledExtension("installedmanageddependency", null);
207   
208  1 assertNotNull(extension);
209  1 assertTrue(extension.isValid(null));
210  1 assertEquals("2.0", extension.getId().getVersion().toString());
211   
212  1 extension =
213    this.installedExtensionRepository.getInstalledExtension("installedmanagedtransitivedependency", null);
214   
215  1 assertNotNull(extension);
216  1 assertTrue(extension.isValid(null));
217  1 assertEquals("1.0", extension.getId().getVersion().toString());
218   
219    // installedorphaneddependency
220   
221  1 extension = this.installedExtensionRepository.getInstalledExtension("installedorphaneddependency", null);
222   
223  1 assertNotNull(extension);
224  1 assertTrue(extension.isValid(null));
225  1 assertEquals("version", extension.getId().getVersion().toString());
226   
227    // install on several namespaces
228   
229  1 extension = this.installedExtensionRepository.getInstalledExtension("installedonseveralnamespaces", null);
230   
231  1 assertNull(extension);
232   
233  1 extension =
234    this.installedExtensionRepository.getInstalledExtension("installedonseveralnamespaces", "namespace1");
235   
236  1 assertNotNull(extension);
237  1 assertTrue(extension.isValid("namespace1"));
238  1 assertTrue(extension.isInstalled("namespace1"));
239  1 assertEquals("version", extension.getId().getVersion().toString());
240   
241  1 extension =
242    this.installedExtensionRepository.getInstalledExtension("installedonseveralnamespaces", "namespace2");
243   
244  1 assertNotNull(extension);
245  1 assertTrue(extension.isValid("namespace2"));
246  1 assertTrue(extension.isInstalled("namespace2"));
247  1 assertEquals("version", extension.getId().getVersion().toString());
248    }
249   
 
250  1 toggle @Test
251    public void testGetLocalExtension()
252    {
253  1 assertNull(this.installedExtensionRepository.getInstalledExtension("unexistingextension", null));
254   
255  1 Extension extension =
256    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), null);
257   
258  1 assertNotNull(extension);
259  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
260  1 assertEquals("test", extension.getType());
261  1 assertEquals(Arrays.asList(TestResources.INSTALLED_ID.getId() + "-feature"),
262    new ArrayList<String>(extension.getFeatures()));
263   
264  1 ExtensionDependency dependency = extension.getDependencies().iterator().next();
265  1 assertEquals(TestResources.INSTALLED_DEPENDENCY_ID.getId(), dependency.getId());
266  1 assertEquals(TestResources.INSTALLED_DEPENDENCY_ID.getVersion(),
267    dependency.getVersionConstraint().getVersion());
268    }
269   
 
270  1 toggle @Test
271    public void testResolve() throws ResolveException
272    {
273  1 try {
274  1 this.installedExtensionRepository.resolve(new ExtensionId("unexistingextension", "version"));
275   
276  0 fail("Resolve should have failed");
277    } catch (ResolveException expected) {
278    // expected
279    }
280   
281  1 try {
282  1 this.installedExtensionRepository
283    .resolve(new ExtensionId(TestResources.INSTALLED_ID.getId(), "wrongversion"));
284   
285  0 fail("Resolve should have failed");
286    } catch (ResolveException expected) {
287    // expected
288    }
289   
290  1 Extension extension = this.installedExtensionRepository.resolve(TestResources.INSTALLED_ID);
291   
292  1 assertNotNull(extension);
293  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
294    }
295   
 
296  1 toggle @Test
297    public void testResolveDependency() throws ResolveException
298    {
299  1 try {
300  1 this.installedExtensionRepository.resolve(
301    new DefaultExtensionDependency("unexistingextension", new DefaultVersionConstraint("version")));
302   
303  0 fail("Resolve should have failed");
304    } catch (ResolveException expected) {
305    // expected
306    }
307   
308  1 try {
309  1 this.installedExtensionRepository.resolve(new DefaultExtensionDependency(TestResources.INSTALLED_ID.getId(),
310    new DefaultVersionConstraint("wrongversion")));
311   
312  0 fail("Resolve should have failed");
313    } catch (ResolveException expected) {
314    // expected
315    }
316   
317  1 Extension extension =
318    this.installedExtensionRepository.resolve(new DefaultExtensionDependency(TestResources.INSTALLED_ID.getId(),
319    new DefaultVersionConstraint(TestResources.INSTALLED_ID.getVersion().getValue())));
320   
321  1 assertNotNull(extension);
322  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
323    }
324   
 
325  1 toggle @Test
326    public void testInstallTwice() throws InstallException
327    {
328    // Change status
329  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace",
330    !this.resources.installed.isDependency("namespace"));
331   
332    // Try to install again with the same status
333  1 try {
334  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace",
335    this.resources.installed.isDependency("namespace"));
336  0 fail("Install should have failed");
337    } catch (InstallException expected) {
338    // expected
339    }
340    }
341   
 
342  1 toggle @Test
343    public void testStoreExtensionAndInstall()
344    throws ResolveException, LocalExtensionRepositoryException, InstallException
345    {
346  1 install(TestResources.REMOTE_SIMPLE_ID);
347   
348  1 assertNotNull(
349    this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(), null));
350  1 assertNotNull(this.installedExtensionRepository.getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId(),
351    "namespace"));
352  1 assertNotNull(this.installedExtensionRepository
353    .getInstalledExtension(TestResources.REMOTE_SIMPLE_ID.getId() + "-feature", null));
354    }
355   
 
356  1 toggle @Test
357    public void testUninstallExtension() throws UninstallException, InstallException
358    {
359    // uninstall from root
360   
361  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, null);
362   
363  1 assertNull(this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), null));
364  1 assertNull(
365    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace"));
366  1 assertNull(this.installedExtensionRepository
367    .getInstalledExtension(TestResources.INSTALLED_ID.getId() + "-feature", null));
368  1 assertNull(this.installedExtensionRepository
369    .getInstalledExtension(TestResources.INSTALLED_ID.getId() + "-feature", "namespace"));
370   
371  1 this.installedExtensionRepository.uninstallExtension(this.resources.installedDependency, null);
372   
373  1 assertNull(this.installedExtensionRepository
374    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
375   
376    // uninstall from namespace
377   
378  1 this.installedExtensionRepository.installExtension(this.resources.installedDependency, "namespace", false);
379  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace", false);
380   
381  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, "namespace");
382   
383  1 assertNull(
384    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace"));
385  1 assertNull(this.installedExtensionRepository
386    .getInstalledExtension(TestResources.INSTALLED_ID.getId() + "-feature", "namespace"));
387   
388  1 this.installedExtensionRepository.uninstallExtension(this.resources.installedDependency, "namespace");
389   
390  1 assertNull(this.installedExtensionRepository
391    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), "namespace"));
392   
393    // uninstall from namespace with dependency on root
394   
395  1 this.installedExtensionRepository.installExtension(this.resources.installedDependency, null, false);
396  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace", false);
397   
398  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, "namespace");
399   
400  1 assertNull(
401    this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(), "namespace"));
402  1 assertNull(this.installedExtensionRepository
403    .getInstalledExtension(TestResources.INSTALLED_ID.getId() + "-feature", "namespace"));
404   
405  1 this.installedExtensionRepository.uninstallExtension(this.resources.installedDependency, null);
406   
407  1 assertNull(this.installedExtensionRepository
408    .getInstalledExtension(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
409    }
410   
 
411  1 toggle @Test
412    public void testBackwardDependenciesAfterInit() throws ResolveException
413    {
414    // installedextension
415  1 assertEquals(Arrays.asList(this.resources.installedwithfeatureasdependency),
416    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_ID.getId(), null));
417  1 assertEquals(new HashMap<String, Collection<InstalledExtension>>()
418    {
 
419  1 toggle {
420  1 put(null, Arrays
421    .asList(DefaultInstalledExtensionRepositoryTest.this.resources.installedwithfeatureasdependency));
422  1 put("namespace", Arrays.asList(
423    DefaultInstalledExtensionRepositoryTest.this.resources.installedonnemspacewithrootdependency));
424    }
425    }, this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_ID));
426   
427    // installedextensiondependency
428  1 assertEquals(Arrays.asList(this.resources.installed), this.installedExtensionRepository
429    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
430  1 assertEquals(Collections.singletonMap(null, Arrays.asList(this.resources.installed)),
431    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID));
432   
433    // installedonnemspacewithrootdependency
434  1 assertEquals(Collections.EMPTY_MAP, this.installedExtensionRepository
435    .getBackwardDependencies(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID));
436  1 assertEquals(Collections.EMPTY_LIST, this.installedExtensionRepository
437    .getBackwardDependencies(TestResources.INSTALLED_ONNAMESPACEWITHROOTDEPENDENCY_ID.getId(), "namespace"));
438    }
439   
 
440  1 toggle @Test
441    public void testBackwardDependenciesAfterUninstall() throws ResolveException, UninstallException
442    {
443  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, null);
444   
445  1 assertEquals(Collections.EMPTY_LIST, this.installedExtensionRepository
446    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
447    }
448   
 
449  1 toggle @Test
450    public void testBackwardDependenciesWithExtensionAndDepOnRoot() throws ResolveException
451    {
452  1 assertEquals(Arrays.asList(this.resources.installed),
453    new ArrayList<InstalledExtension>(this.installedExtensionRepository
454    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null)));
455   
456  1 assertEquals(Arrays.asList(), new ArrayList<InstalledExtension>(this.installedExtensionRepository
457    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), "namespace")));
458   
459  1 assertEquals(Arrays.asList(this.resources.installedwithfeatureasdependency), new ArrayList<InstalledExtension>(
460    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_ID.getId(), null)));
461   
462  1 Map<String, Collection<InstalledExtension>> map = new HashMap<String, Collection<InstalledExtension>>();
463  1 map.put(null, Arrays.asList(this.resources.installed));
464   
465  1 assertEquals(map,
466    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID));
467    }
468   
 
469  1 toggle @Test
470    public void testBackwardDependenciesWithExtensionOnNamespaceAndDepOnNamespace()
471    throws InstallException, ResolveException, UninstallException
472    {
473  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, null);
474   
475  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace", true);
476   
477  1 assertEquals(Collections.EMPTY_LIST, this.installedExtensionRepository
478    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), null));
479   
480  1 assertEquals(Arrays.asList(this.resources.installed), this.installedExtensionRepository
481    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), "namespace"));
482   
483  1 assertEquals(Arrays.asList(this.resources.installedonnemspacewithrootdependency),
484    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_ID.getId(), "namespace"));
485    }
486   
 
487  1 toggle @Test
488    public void testBackwardDependenciesWithExtensionAndDepOnNamespace()
489    throws InstallException, ResolveException, UninstallException
490    {
491  1 this.installedExtensionRepository.uninstallExtension(this.resources.installed, null);
492  1 this.installedExtensionRepository.uninstallExtension(this.resources.installedDependency, null);
493   
494  1 this.installedExtensionRepository.installExtension(this.resources.installedDependency, "namespace", true);
495  1 this.installedExtensionRepository.installExtension(this.resources.installed, "namespace", true);
496   
497  1 assertEquals(Arrays.asList(this.resources.installed), this.installedExtensionRepository
498    .getBackwardDependencies(TestResources.INSTALLED_DEPENDENCY_ID.getId(), "namespace"));
499   
500  1 assertEquals(Arrays.asList(this.resources.installedonnemspacewithrootdependency),
501    this.installedExtensionRepository.getBackwardDependencies(TestResources.INSTALLED_ID.getId(), "namespace"));
502    }
503   
 
504  1 toggle @Test
505    public void testSearch() throws SearchException
506    {
507  1 IterableResult<Extension> result = this.installedExtensionRepository.search(null, 0, -1);
508   
509  1 assertEquals(15, result.getTotalHits());
510  1 assertEquals(15, result.getSize());
511  1 assertEquals(0, result.getOffset());
512   
513  1 result = this.installedExtensionRepository.search("", 0, -1);
514   
515  1 assertEquals(15, result.getTotalHits());
516  1 assertEquals(15, result.getSize());
517  1 assertEquals(0, result.getOffset());
518   
519  1 result = this.installedExtensionRepository.search("extension", 0, -1);
520   
521  1 assertEquals(5, result.getTotalHits());
522  1 assertEquals(5, result.getSize());
523  1 assertEquals(0, result.getOffset());
524   
525  1 result = this.installedExtensionRepository.search("Extension", 0, -1);
526   
527  1 assertEquals(5, result.getTotalHits());
528  1 assertEquals(5, result.getSize());
529  1 assertEquals(0, result.getOffset());
530   
531  1 result = this.installedExtensionRepository.search("dependency", 0, -1);
532   
533  1 assertEquals(8, result.getTotalHits());
534  1 assertEquals(8, result.getSize());
535  1 assertEquals(0, result.getOffset());
536   
537  1 result = this.installedExtensionRepository.search(null, 0, 0);
538   
539  1 assertEquals(15, result.getTotalHits());
540  1 assertEquals(0, result.getSize());
541  1 assertEquals(0, result.getOffset());
542   
543  1 result = this.installedExtensionRepository.search(null, 0, 2);
544   
545  1 assertEquals(15, result.getTotalHits());
546  1 assertEquals(2, result.getSize());
547  1 assertEquals(0, result.getOffset());
548   
549  1 result = this.installedExtensionRepository.search(null, 0, 1);
550   
551  1 assertEquals(15, result.getTotalHits());
552  1 assertEquals(1, result.getSize());
553  1 assertEquals(0, result.getOffset());
554   
555  1 result = this.installedExtensionRepository.search(null, 1, 2);
556   
557  1 assertEquals(15, result.getTotalHits());
558  1 assertEquals(2, result.getSize());
559  1 assertEquals(1, result.getOffset());
560   
561  1 result = this.installedExtensionRepository.search(null, 2, 2);
562   
563  1 assertEquals(15, result.getTotalHits());
564  1 assertEquals(2, result.getSize());
565  1 assertEquals(2, result.getOffset());
566   
567  1 result = this.installedExtensionRepository.search(null, -1, 2);
568   
569  1 assertEquals(15, result.getTotalHits());
570  1 assertEquals(2, result.getSize());
571  1 assertEquals(-1, result.getOffset());
572   
573  1 result = this.installedExtensionRepository.search(null, -1, 1);
574   
575  1 assertEquals(15, result.getTotalHits());
576  1 assertEquals(1, result.getSize());
577  1 assertEquals(-1, result.getOffset());
578    }
579   
 
580  1 toggle @Test
581    public void testAdvancedSearchWithNullQuery() throws SearchException
582    {
583  1 ExtensionQuery query = new ExtensionQuery();
584   
585  1 query.addFilter(Extension.FIELD_ID, TestResources.INSTALLED_ID.getId(), COMPARISON.EQUAL);
586   
587  1 IterableResult<Extension> result = this.installedExtensionRepository.search(query);
588   
589  1 assertEquals(1, result.getTotalHits());
590  1 assertEquals(1, result.getSize());
591  1 assertEquals(0, result.getOffset());
592  1 assertEquals(TestResources.INSTALLED_ID, result.iterator().next().getId());
593    }
594   
 
595  1 toggle @Test
596    public void testAdvancedSearchInstalledWithNullQuery() throws SearchException
597    {
598  1 ExtensionQuery query = new ExtensionQuery();
599   
600  1 query.addFilter(Extension.FIELD_ID, TestResources.INSTALLED_ID.getId(), COMPARISON.EQUAL);
601   
602  1 IterableResult<InstalledExtension> result =
603    this.installedExtensionRepository.searchInstalledExtensions((String) null, query);
604   
605  1 assertEquals(1, result.getTotalHits());
606  1 assertEquals(1, result.getSize());
607  1 assertEquals(0, result.getOffset());
608  1 assertEquals(TestResources.INSTALLED_ID, result.iterator().next().getId());
609    }
610   
 
611  1 toggle @Test
612    public void testSearchInstalledExtensions() throws SearchException
613    {
614    // Root namespace
615  1 IterableResult<InstalledExtension> result =
616    this.installedExtensionRepository.searchInstalledExtensions(null, null, 0, -1);
617   
618  1 assertEquals(9, result.getTotalHits());
619  1 assertEquals(9, result.getSize());
620  1 assertEquals(0, result.getOffset());
621   
622    // Namespace "namespace" + "root"
623  1 result = this.installedExtensionRepository.searchInstalledExtensions(null, "namespace", 0, -1);
624   
625  1 assertEquals(13, result.getTotalHits());
626  1 assertEquals(13, result.getSize());
627  1 assertEquals(0, result.getOffset());
628   
629    // This namespace does not exist so same as root
630  1 result = this.installedExtensionRepository.searchInstalledExtensions(null, "notnamespace", 0, -1);
631   
632  1 assertEquals(9, result.getTotalHits());
633  1 assertEquals(9, result.getSize());
634  1 assertEquals(0, result.getOffset());
635    }
636   
 
637  1 toggle @Test
638    public void testgetInstalledExtensionFeatureNamespace()
639    {
640  1 InstalledExtension extension;
641   
642    // installed extension
643   
644  1 extension = this.installedExtensionRepository.getInstalledExtension(TestResources.INSTALLED_ID.getId(),
645    TestResources.INSTALLED_ID.getVersion().toString());
646   
647  1 assertNotNull(extension);
648  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
649   
650    // installed feature
651   
652  1 extension = this.installedExtensionRepository.getInstalledExtension(
653    TestResources.INSTALLED_ID.getId() + "-feature", TestResources.INSTALLED_ID.getVersion().toString());
654   
655  1 assertNotNull(extension);
656  1 assertEquals(TestResources.INSTALLED_ID, extension.getId());
657    }
658    }