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

File DefaultExtensionManagerTest.java

 

Code metrics

0
33
5
1
138
83
5
0.15
6.6
5
1

Classes

Class Line # Actions
DefaultExtensionManagerTest 51 33 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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.internal;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.extension.ExtensionDependency;
26    import org.xwiki.extension.ExtensionId;
27    import org.xwiki.extension.ExtensionManager;
28    import org.xwiki.extension.InstalledExtension;
29    import org.xwiki.extension.ResolveException;
30    import org.xwiki.extension.repository.CoreExtensionRepository;
31    import org.xwiki.extension.repository.ExtensionRepository;
32    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
33    import org.xwiki.extension.repository.InstalledExtensionRepository;
34    import org.xwiki.extension.repository.LocalExtensionRepository;
35    import org.xwiki.extension.version.Version;
36    import org.xwiki.extension.version.VersionConstraint;
37    import org.xwiki.test.mockito.MockitoComponentMockingRule;
38   
39    import static org.junit.Assert.assertNull;
40    import static org.junit.Assert.assertSame;
41    import static org.mockito.Mockito.doThrow;
42    import static org.mockito.Mockito.mock;
43    import static org.mockito.Mockito.when;
44   
45    /**
46    * Unit tests for {@link DefaultExtensionManager}.
47    *
48    * @version $Id: 9c990c3e144eba376daf4bdf0ea4a9a16b730a9c $
49    * @since 5.3M1
50    */
 
51    public class DefaultExtensionManagerTest
52    {
53    @Rule
54    public final MockitoComponentMockingRule<ExtensionManager> mocker =
55    new MockitoComponentMockingRule<ExtensionManager>(DefaultExtensionManager.class);
56   
57    private CoreExtensionRepository coreExtensionRepository;
58   
59    private LocalExtensionRepository localExtensionRepository;
60   
61    private InstalledExtensionRepository installedExtensionRepository;
62   
 
63  3 toggle @Before
64    public void setUp() throws Exception
65    {
66  3 this.coreExtensionRepository = this.mocker.getInstance(CoreExtensionRepository.class);
67  3 mockExtensionRepositoryDescriptor(this.coreExtensionRepository, "core");
68   
69  3 this.localExtensionRepository = this.mocker.getInstance(LocalExtensionRepository.class);
70  3 mockExtensionRepositoryDescriptor(this.localExtensionRepository, "local");
71   
72  3 this.installedExtensionRepository = this.mocker.getInstance(InstalledExtensionRepository.class);
73  3 mockExtensionRepositoryDescriptor(this.installedExtensionRepository, "installed");
74    }
75   
 
76  9 toggle private ExtensionRepositoryDescriptor mockExtensionRepositoryDescriptor(ExtensionRepository repository, String id)
77    {
78  9 ExtensionRepositoryDescriptor descriptor = mock(ExtensionRepositoryDescriptor.class, id);
79  9 when(repository.getDescriptor()).thenReturn(descriptor);
80  9 when(descriptor.getId()).thenReturn(id);
81  9 return descriptor;
82    }
83   
84    /**
85    * Unit test for {@link ExtensionManager#resolveExtension(org.xwiki.extension.ExtensionDependency, String)}.
86    */
 
87  1 toggle @Test
88    public void resolveMissingExtensionDependencyOnNamespace() throws Exception
89    {
90  1 ExtensionDependency extensionDependency = mock(ExtensionDependency.class);
91   
92  1 doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency);
93  1 doThrow(ResolveException.class).when(this.localExtensionRepository).resolve(extensionDependency);
94   
95  1 assertNull(this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, "wiki:math"));
96    }
97   
98    /**
99    * Unit test for {@link ExtensionManager#resolveExtension(org.xwiki.extension.ExtensionDependency, String)}.
100    */
 
101  1 toggle @Test
102    public void resolveInstalledExtensionDependencyOnNamespace() throws Exception
103    {
104  1 String namespace = "wiki:math";
105  1 String extensionId = "test:extension";
106   
107  1 ExtensionDependency extensionDependency = mock(ExtensionDependency.class);
108  1 doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionDependency);
109   
110  1 InstalledExtension extension = mock(InstalledExtension.class);
111  1 when(extensionDependency.getId()).thenReturn(extensionId);
112  1 when(this.installedExtensionRepository.getInstalledExtension(extensionId, namespace)).thenReturn(extension);
113   
114  1 Version version = mock(Version.class);
115  1 when(extension.getId()).thenReturn(new ExtensionId(extensionId, version));
116   
117  1 VersionConstraint versionConstraint = mock(VersionConstraint.class);
118  1 when(extensionDependency.getVersionConstraint()).thenReturn(versionConstraint);
119  1 when(versionConstraint.containsVersion(version)).thenReturn(true);
120   
121  1 assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionDependency, namespace));
122    }
123   
 
124  1 toggle @Test
125    public void resolveInstalledExtensionId() throws Exception
126    {
127  1 ExtensionId extensionId = new ExtensionId("extension", "version");
128   
129  1 doThrow(ResolveException.class).when(this.coreExtensionRepository).resolve(extensionId);
130   
131  1 InstalledExtension extension = mock(InstalledExtension.class);
132  1 when(this.installedExtensionRepository.resolve(extensionId)).thenReturn(extension);
133   
134  1 when(extension.getId()).thenReturn(extensionId);
135   
136  1 assertSame(extension, this.mocker.getComponentUnderTest().resolveExtension(extensionId));
137    }
138    }