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

File DefaultCoreExtensionRepositoryTest.java

 

Code metrics

0
24
5
1
131
75
7
0.29
4.8
5
1.4

Classes

Class Line # Actions
DefaultCoreExtensionRepositoryTest 41 24 0% 7 2
0.931034593.1%
 

Contributing tests

This file is covered by 4 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.core;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.environment.Environment;
27    import org.xwiki.extension.Extension;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.ResolveException;
30    import org.xwiki.extension.repository.CoreExtensionRepository;
31    import org.xwiki.extension.repository.result.IterableResult;
32    import org.xwiki.extension.repository.search.SearchException;
33    import org.xwiki.extension.test.ConfigurableDefaultCoreExtensionRepository;
34    import org.xwiki.extension.version.internal.DefaultVersion;
35    import org.xwiki.test.annotation.AllComponents;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import static org.junit.Assert.assertEquals;
39   
40    @AllComponents
 
41    public class DefaultCoreExtensionRepositoryTest
42    {
43    @Rule
44    public MockitoComponentMockingRule<CoreExtensionRepository> mocker =
45    new MockitoComponentMockingRule<CoreExtensionRepository>(ConfigurableDefaultCoreExtensionRepository.class);
46   
47    private ConfigurableDefaultCoreExtensionRepository coreExtensionRepository;
48   
49    /**
50    * Validate core extension loading and others initializations.
51    */
 
52  1 toggle @Test
53    public void testInit()
54    {
55  1 Assert.assertTrue(this.coreExtensionRepository.countExtensions() > 0);
56    }
57   
 
58  4 toggle @Before
59    public void before() throws Exception
60    {
61  4 this.mocker.registerMockComponent(Environment.class);
62   
63  4 this.coreExtensionRepository =
64    (ConfigurableDefaultCoreExtensionRepository) this.mocker.getInstance(CoreExtensionRepository.class);
65    }
66   
67    /**
68    * Validate {@link CoreExtensionRepository#getCoreExtension(String)}
69    */
 
70  1 toggle @Test
71    public void testGetCoreExtension()
72    {
73  1 Assert.assertNull(this.coreExtensionRepository.getCoreExtension("unexistingextension"));
74   
75  1 this.coreExtensionRepository.addExtensions("existingextension", new DefaultVersion("version"));
76   
77  1 Extension extension = this.coreExtensionRepository.getCoreExtension("existingextension");
78   
79  1 Assert.assertNotNull(extension);
80  1 Assert.assertEquals("existingextension", extension.getId().getId());
81  1 Assert.assertEquals("version", extension.getId().getVersion().getValue());
82    }
83   
84    /**
85    * Validate {@link CoreExtensionRepository#resolve(ExtensionId)}
86    */
 
87  1 toggle @Test
88    public void testResolve() throws ResolveException
89    {
90  1 try {
91  1 this.coreExtensionRepository.resolve(new ExtensionId("unexistingextension", "version"));
92   
93  0 Assert.fail("Resolve should have failed");
94    } catch (ResolveException expected) {
95    // expected
96    }
97   
98  1 this.coreExtensionRepository.addExtensions("existingextension", new DefaultVersion("version"));
99   
100  1 try {
101  1 this.coreExtensionRepository.resolve(new ExtensionId("existingextension", "wrongversion"));
102   
103  0 Assert.fail("Resolve should have failed");
104    } catch (ResolveException expected) {
105    // expected
106    }
107   
108  1 Extension extension = this.coreExtensionRepository.resolve(new ExtensionId("existingextension", "version"));
109   
110  1 Assert.assertNotNull(extension);
111  1 Assert.assertEquals("existingextension", extension.getId().getId());
112  1 Assert.assertEquals("version", extension.getId().getVersion().getValue());
113    }
114   
115    /**
116    * Make sure only one result is returned for an extension having several features.
117    *
118    * @throws SearchException
119    */
 
120  1 toggle @Test
121    public void testSearchWithSeveralFeatures() throws SearchException
122    {
123  1 this.coreExtensionRepository.addExtensions("extension", new DefaultVersion("version"),
124    new ExtensionId("testfeature1"), new ExtensionId("testfeature2"));
125   
126  1 IterableResult<Extension> result = this.coreExtensionRepository.search("testfeature", 0, -1);
127   
128  1 assertEquals(1, result.getTotalHits());
129  1 assertEquals(1, result.getSize());
130    }
131    }