1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.internal; |
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 |
|
|
28 |
|
import org.junit.Assert; |
29 |
|
import org.junit.Before; |
30 |
|
import org.junit.Rule; |
31 |
|
import org.junit.Test; |
32 |
|
import org.xwiki.configuration.internal.MemoryConfigurationSource; |
33 |
|
import org.xwiki.environment.Environment; |
34 |
|
import org.xwiki.extension.ExtensionManagerConfiguration; |
35 |
|
import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor; |
36 |
|
import org.xwiki.extension.repository.ExtensionRepositoryDescriptor; |
37 |
|
import org.xwiki.test.LogRule; |
38 |
|
import org.xwiki.test.annotation.BeforeComponent; |
39 |
|
import org.xwiki.test.annotation.ComponentList; |
40 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
|
47 |
|
@ComponentList({ DefaultExtensionManagerConfiguration.class, ExtensionFactory.class }) |
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 6 |
Complexity Density: 0.26 |
|
48 |
|
public class DefaultExtensionManagerConfigurationTest |
49 |
|
{ |
50 |
|
@Rule |
51 |
|
public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule(); |
52 |
|
|
53 |
|
@Rule |
54 |
|
public final LogRule logCapture = new LogRule() |
55 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
3 |
{... |
57 |
3 |
record(LogLevel.WARN); |
58 |
3 |
recordLoggingForType(DefaultExtensionManagerConfiguration.class); |
59 |
|
} |
60 |
|
}; |
61 |
|
|
62 |
|
private ExtensionManagerConfiguration configuration; |
63 |
|
|
64 |
|
private MemoryConfigurationSource source; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
3 |
@BeforeComponent... |
67 |
|
public void registerComponents() throws Exception |
68 |
|
{ |
69 |
|
|
70 |
3 |
this.componentManager.registerMockComponent(Environment.class); |
71 |
|
|
72 |
|
|
73 |
3 |
this.source = this.componentManager.registerMemoryConfigurationSource(); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
3 |
@Before... |
77 |
|
public void setUp() throws Exception |
78 |
|
{ |
79 |
3 |
this.configuration = this.componentManager.getInstance(ExtensionManagerConfiguration.class); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void testGetRepositoriesWithInvalid() throws Exception |
84 |
|
{ |
85 |
|
|
86 |
|
|
87 |
1 |
this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url", "invalid")); |
88 |
|
|
89 |
1 |
Assert.assertEquals( |
90 |
|
Arrays.asList(new DefaultExtensionRepositoryDescriptor("id", "type", new URI("http://url"))), |
91 |
|
new ArrayList<ExtensionRepositoryDescriptor>(this.configuration.getExtensionRepositoryDescriptors())); |
92 |
1 |
Assert.assertEquals(1, this.logCapture.size()); |
93 |
1 |
Assert.assertEquals("Ignoring invalid repository configuration [invalid]. Root cause " |
94 |
|
+ "[ExtensionManagerConfigurationException: Invalid repository configuration format for [invalid]. Should " |
95 |
|
+ "have been matching [([^:]+):([^:]+):(.+)].]", this.logCapture.getMessage(0)); |
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void testGetExtensionRepositoryDescriptorsEmpty() |
100 |
|
{ |
101 |
1 |
Assert.assertEquals(null, this.configuration.getExtensionRepositoryDescriptors()); |
102 |
1 |
Assert.assertEquals(0, this.logCapture.size()); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
105 |
1 |
@Test... |
106 |
|
public void testGetExtensionRepositoryDescriptorsWithProperties() throws URISyntaxException |
107 |
|
{ |
108 |
1 |
this.source.setProperty("extension.repositories", Arrays.asList("id:type:http://url")); |
109 |
1 |
this.source.setProperty("extension.repositories.id.property", "value"); |
110 |
1 |
this.source.setProperty("extension.repositories.id.property.with.dots", "other value"); |
111 |
|
|
112 |
1 |
Collection<ExtensionRepositoryDescriptor> descriptors = this.configuration.getExtensionRepositoryDescriptors(); |
113 |
|
|
114 |
1 |
Assert.assertFalse(descriptors.isEmpty()); |
115 |
|
|
116 |
1 |
ExtensionRepositoryDescriptor descriptor = descriptors.iterator().next(); |
117 |
|
|
118 |
1 |
Assert.assertEquals("id", descriptor.getId()); |
119 |
1 |
Assert.assertEquals("type", descriptor.getType()); |
120 |
1 |
Assert.assertEquals(new URI("http://url"), descriptor.getURI()); |
121 |
1 |
Assert.assertEquals("value", descriptor.getProperty("property")); |
122 |
1 |
Assert.assertEquals("other value", descriptor.getProperty("property.with.dots")); |
123 |
1 |
Assert.assertEquals(0, this.logCapture.size()); |
124 |
|
} |
125 |
|
} |