1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.xar.internal.repository

File XarInstalledExtensionRepositoryTest.java

 

Code metrics

0
17
2
1
91
57
2
0.12
8.5
2
1

Classes

Class Line # Actions
XarInstalledExtensionRepositoryTest 42 17 0% 2 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.AllComponents;
35    import org.xwiki.test.mockito.MockitoComponentManagerRule;
36   
37    import static org.junit.Assert.assertEquals;
38    import static org.junit.Assert.assertNotNull;
39    import static org.junit.Assert.assertNull;
40   
41    @AllComponents
 
42    public class XarInstalledExtensionRepositoryTest
43    {
44    protected MockitoComponentManagerRule mocker = new MockitoComponentManagerRule();
45   
46    @Rule
47    public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule(this.mocker);
48   
49    private XarInstalledExtensionRepository installedExtensionRepository;
50   
 
51  1 toggle @Before
52    public void setUp() throws Exception
53    {
54  1 this.installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class, "xar");
55    }
56   
57    // Tests
58   
 
59  1 toggle @Test
60    public void testInit() throws ResolveException, SearchException
61    {
62  1 assertEquals(1, this.installedExtensionRepository.countExtensions());
63   
64  1 XarInstalledExtension xarInstalledExtension =
65    this.installedExtensionRepository.resolve(new ExtensionId("xarinstalledextension", "1.0"));
66  1 assertNotNull(xarInstalledExtension);
67   
68  1 assertNotNull(
69    this.installedExtensionRepository.getInstalledExtension(new ExtensionId("xarinstalledextension", "1.0")));
70  1 assertNotNull(this.installedExtensionRepository.getInstalledExtension("xarinstalledextension", null));
71  1 assertNull(this.installedExtensionRepository.getInstalledExtension("notexisting", null));
72   
73  1 assertEquals(1, this.installedExtensionRepository.getInstalledExtensions().size());
74  1 assertEquals(1, this.installedExtensionRepository.getInstalledExtensions(null).size());
75   
76  1 assertEquals(1, this.installedExtensionRepository.search("xarinstalledextension", 0, -1).getSize());
77  1 assertEquals(1, this.installedExtensionRepository.search(null, 0, -1).getSize());
78  1 assertEquals(1, this.installedExtensionRepository
79    .searchInstalledExtensions("xarinstalledextension", null, 0, -1).getSize());
80  1 assertEquals(1, this.installedExtensionRepository.searchInstalledExtensions(null, null, 0, -1).getSize());
81   
82  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
83    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page")));
84  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
85    .getXarInstalledExtensions(new DocumentReference("wiki2", "space", "page")));
86  1 assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository
87    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page", Locale.ROOT)));
88  1 assertEquals(0, this.installedExtensionRepository
89    .getXarInstalledExtensions(new DocumentReference("xwiki", "space", "page", Locale.ENGLISH)).size());
90    }
91    }