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

File XarInstalledExtensionRepositoryTest.java

 

Code metrics

0
18
3
1
99
64
3
0.17
6
3
1

Classes

Class Line # Actions
XarInstalledExtensionRepositoryTest 44 18 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.xar.internal.repository;
21   
22    import java.util.Arrays;
23    import java.util.Locale;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.ResolveException;
30    import org.xwiki.extension.repository.InstalledExtensionRepository;
31    import org.xwiki.extension.repository.search.SearchException;
32    import org.xwiki.extension.test.MockitoRepositoryUtilsRule;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.test.annotation.AfterComponent;
35    import org.xwiki.test.annotation.AllComponents;
36    import org.xwiki.test.mockito.MockitoComponentManagerRule;
37    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
38   
39    import static org.junit.Assert.assertEquals;
40    import static org.junit.Assert.assertNotNull;
41    import static org.junit.Assert.assertNull;
42   
43    @AllComponents
 
44    public class XarInstalledExtensionRepositoryTest
45    {
46    protected MockitoComponentManagerRule mocker = new MockitoComponentManagerRule();
47   
48    @Rule
49    public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule(this.mocker);
50   
51    private XarInstalledExtensionRepository installedExtensionRepository;
52   
 
53  1 toggle @AfterComponent
54    public void afterComponent() throws Exception
55    {
56  1 this.repositoryUtil.getComponentManager().registerMockComponent(WikiDescriptorManager.class);
57    }
58   
 
59  1 toggle @Before
60    public void setUp() throws Exception
61    {
62  1 this.installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class, "xar");
63    }
64   
65    // Tests
66   
 
67  1 toggle @Test
68    public void testInit() throws ResolveException, SearchException
69    {
70  1 assertEquals(1, this.installedExtensionRepository.countExtensions());
71   
72  1 XarInstalledExtension xarInstalledExtension =
73    this.installedExtensionRepository.resolve(new ExtensionId("xarinstalledextension", "1.0"));
74  1 assertNotNull(xarInstalledExtension);
75   
76  1 assertNotNull(
77    this.installedExtensionRepository.getInstalledExtension(new ExtensionId("xarinstalledextension", "1.0")));
78  1 assertNotNull(this.installedExtensionRepository.getInstalledExtension("xarinstalledextension", null));
79  1 assertNull(this.installedExtensionRepository.getInstalledExtension("notexisting", null));
80   
81  1 assertEquals(1, this.installedExtensionRepository.getInstalledExtensions().size());
82  1 assertEquals(1, this.installedExtensionRepository.getInstalledExtensions(null).size());
83   
84  1 assertEquals(1, this.installedExtensionRepository.search("xarinstalledextension", 0, -1).getSize());
85  1 assertEquals(1, this.installedExtensionRepository.search(null, 0, -1).getSize());
86  1 assertEquals(1, this.installedExtensionRepository
87    .searchInstalledExtensions("xarinstalledextension", null, 0, -1).getSize());
88  1 assertEquals(1, this.installedExtensionRepository.searchInstalledExtensions(null, null, 0, -1).getSize());
89   
90  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
91    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page")));
92  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
93    .getXarInstalledExtensions(new DocumentReference("wiki2", "space", "page")));
94  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
95    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page", Locale.ROOT)));
96  1 assertEquals(0, this.installedExtensionRepository
97    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page", Locale.ENGLISH)).size());
98    }
99    }