1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository; |
21 |
|
|
22 |
|
import java.net.URI; |
23 |
|
import java.net.URISyntaxException; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Iterator; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.component.manager.ComponentLookupException; |
34 |
|
import org.xwiki.extension.DefaultExtensionDependency; |
35 |
|
import org.xwiki.extension.Extension; |
36 |
|
import org.xwiki.extension.ResolveException; |
37 |
|
import org.xwiki.extension.repository.internal.DefaultExtensionRepositoryManager; |
38 |
|
import org.xwiki.extension.version.internal.DefaultVersionConstraint; |
39 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
40 |
|
|
41 |
|
import static org.junit.Assert.assertSame; |
42 |
|
import static org.mockito.ArgumentMatchers.same; |
43 |
|
import static org.mockito.Mockito.mock; |
44 |
|
import static org.mockito.Mockito.when; |
45 |
|
|
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (66) |
Complexity: 11 |
Complexity Density: 0.2 |
|
51 |
|
public class DefaultExtensionRepositoryManagerTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public MockitoComponentMockingRule<ExtensionRepositoryManager> mocker = |
55 |
|
new MockitoComponentMockingRule<ExtensionRepositoryManager>(DefaultExtensionRepositoryManager.class); |
56 |
|
|
57 |
|
private ExtensionRepository testRepository; |
58 |
|
|
59 |
|
private ExtensionRepositoryDescriptor descriptor; |
60 |
|
|
61 |
|
private ExtensionRepositoryDescriptor unsupportedDescriptor; |
62 |
|
|
63 |
|
private DefaultExtensionDependency dependency; |
64 |
|
|
65 |
|
private Extension testExtension; |
66 |
|
|
67 |
|
private ExtensionRepositoryFactory factory; |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
69 |
10 |
@Before... |
70 |
|
public void before() throws Exception |
71 |
|
{ |
72 |
10 |
this.factory = this.mocker.registerMockComponent(ExtensionRepositoryFactory.class, "test"); |
73 |
10 |
this.testRepository = mock(ExtensionRepository.class); |
74 |
|
|
75 |
10 |
this.descriptor = |
76 |
|
new DefaultExtensionRepositoryDescriptor("id", "test", new URI("http", "host", "/path", "fragment")); |
77 |
|
|
78 |
10 |
this.unsupportedDescriptor = new DefaultExtensionRepositoryDescriptor("unsupported", "unsupported", |
79 |
|
new URI("http", "unsupported", "/unsupported", "unsupported")); |
80 |
|
|
81 |
10 |
when(factory.createRepository(same(this.descriptor))).thenReturn(this.testRepository); |
82 |
10 |
when(this.testRepository.getDescriptor()).thenReturn(this.descriptor); |
83 |
|
|
84 |
10 |
this.dependency = new DefaultExtensionDependency("id", new DefaultVersionConstraint("version")); |
85 |
|
|
86 |
10 |
this.testExtension = mock(Extension.class); |
87 |
10 |
when(this.testRepository.resolve(this.dependency)).thenReturn(testExtension); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
92 |
1 |
@Test... |
93 |
|
public void addRepository() throws ExtensionRepositoryException, ComponentLookupException |
94 |
|
{ |
95 |
1 |
ExtensionRepository repository = this.mocker.getComponentUnderTest().addRepository(this.descriptor); |
96 |
|
|
97 |
1 |
Assert.assertSame(this.testRepository, repository); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
100 |
1 |
@Test(expected = ExtensionRepositoryException.class)... |
101 |
|
public void addRepository_unsuported() throws ComponentLookupException, ExtensionRepositoryException |
102 |
|
{ |
103 |
1 |
this.mocker.getComponentUnderTest().addRepository(this.unsupportedDescriptor); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
106 |
1 |
@Test... |
107 |
|
public void getRepository() throws ExtensionRepositoryException, ComponentLookupException |
108 |
|
{ |
109 |
1 |
this.mocker.getComponentUnderTest().addRepository(this.descriptor); |
110 |
|
|
111 |
1 |
ExtensionRepository repository = this.mocker.getComponentUnderTest().getRepository("id"); |
112 |
|
|
113 |
1 |
Assert.assertSame(this.testRepository, repository); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
116 |
1 |
@Test... |
117 |
|
public void getRepository_doesnotexists() throws ComponentLookupException |
118 |
|
{ |
119 |
1 |
ExtensionRepository repository = this.mocker.getComponentUnderTest().getRepository("id"); |
120 |
|
|
121 |
1 |
Assert.assertNull(repository); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void removeRepository() throws ExtensionRepositoryException, ComponentLookupException |
126 |
|
{ |
127 |
1 |
this.mocker.getComponentUnderTest().addRepository(this.descriptor); |
128 |
|
|
129 |
1 |
this.mocker.getComponentUnderTest().removeRepository(this.descriptor.getId()); |
130 |
|
|
131 |
1 |
ExtensionRepository repository = this.mocker.getComponentUnderTest().getRepository("id"); |
132 |
|
|
133 |
1 |
Assert.assertNull(repository); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
136 |
1 |
@Test... |
137 |
|
public void getRepositories() throws ExtensionRepositoryException, ComponentLookupException |
138 |
|
{ |
139 |
1 |
this.mocker.getComponentUnderTest().addRepository(this.descriptor); |
140 |
|
|
141 |
1 |
Collection<ExtensionRepository> repositorties = this.mocker.getComponentUnderTest().getRepositories(); |
142 |
|
|
143 |
1 |
Assert.assertEquals(Arrays.asList(this.testRepository), new ArrayList<ExtensionRepository>(repositorties)); |
144 |
|
} |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
146 |
1 |
@Test(expected = ResolveException.class)... |
147 |
|
public void resolveDependencyWithNoRegisteredRepository() throws ResolveException, ComponentLookupException |
148 |
|
{ |
149 |
1 |
this.mocker.getComponentUnderTest().resolve(this.dependency); |
150 |
|
} |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
152 |
1 |
@Test... |
153 |
|
public void resolveDependencyWithEmbeddedRepository() throws ResolveException, ComponentLookupException |
154 |
|
{ |
155 |
1 |
this.dependency.addRepository(this.testRepository.getDescriptor()); |
156 |
|
|
157 |
1 |
assertSame(this.testExtension, this.mocker.getComponentUnderTest().resolve(this.dependency)); |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
160 |
1 |
@Test... |
161 |
|
public void resolveDependencyWithRegisteredRepository() throws ResolveException, ComponentLookupException |
162 |
|
{ |
163 |
1 |
this.mocker.getComponentUnderTest().addRepository(this.testRepository); |
164 |
|
|
165 |
1 |
assertSame(this.testExtension, this.mocker.getComponentUnderTest().resolve(this.dependency)); |
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
168 |
1 |
@Test... |
169 |
|
public void repositoryOrder() throws URISyntaxException, ExtensionRepositoryException, ComponentLookupException |
170 |
|
{ |
171 |
1 |
ExtensionRepositoryDescriptor repDescriptor0 = |
172 |
|
new DefaultExtensionRepositoryDescriptor("id0", "test", new URI("http", "host", "/path", "fragment")); |
173 |
1 |
ExtensionRepository rep0 = mock(ExtensionRepository.class, "repo0"); |
174 |
1 |
when(this.factory.createRepository(same(repDescriptor0))).thenReturn(rep0); |
175 |
1 |
when(rep0.getDescriptor()).thenReturn(repDescriptor0); |
176 |
1 |
ExtensionRepositoryDescriptor repDescriptor1 = |
177 |
|
new DefaultExtensionRepositoryDescriptor("id1", "test", new URI("http", "host", "/path", "fragment")); |
178 |
1 |
ExtensionRepository rep1 = mock(ExtensionRepository.class, "repo1"); |
179 |
1 |
when(this.factory.createRepository(same(repDescriptor1))).thenReturn(rep1); |
180 |
1 |
when(rep1.getDescriptor()).thenReturn(repDescriptor1); |
181 |
1 |
ExtensionRepositoryDescriptor repDescriptor2 = |
182 |
|
new DefaultExtensionRepositoryDescriptor("id2", "test", new URI("http", "host", "/path", "fragment")); |
183 |
1 |
ExtensionRepository rep2 = mock(ExtensionRepository.class, "repo2"); |
184 |
1 |
when(this.factory.createRepository(same(repDescriptor2))).thenReturn(rep2); |
185 |
1 |
when(rep2.getDescriptor()).thenReturn(repDescriptor2); |
186 |
1 |
ExtensionRepositoryDescriptor repDescriptor3 = |
187 |
|
new DefaultExtensionRepositoryDescriptor("id3", "test", new URI("http", "host", "/path", "fragment")); |
188 |
1 |
ExtensionRepository rep3 = mock(ExtensionRepository.class, "repo3"); |
189 |
1 |
when(this.factory.createRepository(same(repDescriptor3))).thenReturn(rep3); |
190 |
1 |
when(rep3.getDescriptor()).thenReturn(repDescriptor3); |
191 |
|
|
192 |
1 |
this.mocker.getComponentUnderTest().addRepository(repDescriptor3, 3); |
193 |
1 |
this.mocker.getComponentUnderTest().addRepository(repDescriptor2, 2); |
194 |
1 |
this.mocker.getComponentUnderTest().addRepository(repDescriptor1, 1); |
195 |
1 |
this.mocker.getComponentUnderTest().addRepository(repDescriptor0, 0); |
196 |
|
|
197 |
1 |
Collection<ExtensionRepository> repositories = this.mocker.getComponentUnderTest().getRepositories(); |
198 |
1 |
Iterator<ExtensionRepository> it = repositories.iterator(); |
199 |
|
|
200 |
1 |
assertSame(rep0, it.next()); |
201 |
1 |
assertSame(rep1, it.next()); |
202 |
1 |
assertSame(rep2, it.next()); |
203 |
1 |
assertSame(rep3, it.next()); |
204 |
|
} |
205 |
|
} |