1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.test; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.mockito.Mockito; |
26 |
|
import org.xwiki.component.annotation.ComponentAnnotationLoader; |
27 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
28 |
|
import org.xwiki.component.descriptor.DefaultComponentDescriptor; |
29 |
|
import org.xwiki.configuration.internal.MemoryConfigurationSource; |
30 |
|
import org.xwiki.environment.Environment; |
31 |
|
import org.xwiki.extension.handler.ExtensionInitializer; |
32 |
|
import org.xwiki.extension.repository.CoreExtensionRepository; |
33 |
|
import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor; |
34 |
|
import org.xwiki.extension.repository.ExtensionRepositoryManager; |
35 |
|
import org.xwiki.extension.version.internal.DefaultVersion; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
37 |
|
|
38 |
|
import static org.mockito.ArgumentMatchers.any; |
39 |
|
|
|
|
| 97.6% |
Uncovered Elements: 1 (42) |
Complexity: 9 |
Complexity Density: 0.31 |
|
40 |
|
public class MockitoRepositoryUtils extends RepositoryUtils |
41 |
|
{ |
42 |
|
protected final MockitoComponentManagerRule componentManager; |
43 |
|
|
44 |
|
private FileExtensionRepository remoteRepository; |
45 |
|
|
46 |
|
private ComponentAnnotationLoader componentLoader; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
160 |
public MockitoRepositoryUtils(MockitoComponentManagerRule componentManager)... |
49 |
|
{ |
50 |
160 |
this.componentManager = componentManager; |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 4 |
Complexity Density: 0.19 |
|
53 |
160 |
@Override... |
54 |
|
public void setup() throws Exception |
55 |
|
{ |
56 |
160 |
super.setup(); |
57 |
|
|
58 |
|
|
59 |
160 |
MemoryConfigurationSource memoryConfigurationSource = this.componentManager.registerMemoryConfigurationSource(); |
60 |
160 |
memoryConfigurationSource.setProperty("extension.repositories", Arrays.asList("")); |
61 |
|
|
62 |
160 |
final Environment environment = this.componentManager.registerMockComponent(Environment.class); |
63 |
160 |
Mockito.when(environment.getPermanentDirectory()).thenReturn(getPermanentDirectory()); |
64 |
160 |
Mockito.when(environment.getTemporaryDirectory()).thenReturn(getTemporaryDirectory()); |
65 |
160 |
Mockito.when(environment.getResourceAsStream(any())).thenReturn(null); |
66 |
|
|
67 |
160 |
DefaultComponentDescriptor<Environment> dcd = new DefaultComponentDescriptor<Environment>(); |
68 |
160 |
dcd.setRoleType(Environment.class); |
69 |
160 |
this.componentManager.registerComponent(dcd, environment); |
70 |
|
|
71 |
|
|
72 |
160 |
registerComponent(ConfigurableDefaultCoreExtensionRepository.class); |
73 |
160 |
((ConfigurableDefaultCoreExtensionRepository) this.componentManager.getInstance(CoreExtensionRepository.class)) |
74 |
|
.addExtensions("coreextension", new DefaultVersion("version")); |
75 |
|
|
76 |
|
|
77 |
160 |
ExtensionRepositoryManager repositoryManager = |
78 |
|
this.componentManager.getInstance(ExtensionRepositoryManager.class); |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
160 |
if (copyResourceFolder(getRemoteRepository(), "repository.remote") > 0) { |
83 |
138 |
this.remoteRepository = new FileExtensionRepository(getRemoteRepository(), this.componentManager); |
84 |
138 |
repositoryManager.addRepository(this.remoteRepository); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
160 |
if (getMavenRepository().exists()) { |
90 |
20 |
repositoryManager.addRepository(new DefaultExtensionRepositoryDescriptor(MAVENREPOSITORY_ID, "maven", |
91 |
|
getMavenRepository().toURI())); |
92 |
|
} |
93 |
|
|
94 |
160 |
if (getMaven2Repository().exists()) { |
95 |
20 |
repositoryManager.addRepository(new DefaultExtensionRepositoryDescriptor(MAVEN2REPOSITORY_ID, "maven", |
96 |
|
getMaven2Repository().toURI())); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
160 |
this.componentManager.<ExtensionInitializer>getInstance(ExtensionInitializer.class).initialize(); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
172 |
public MockitoComponentManagerRule getComponentManager()... |
105 |
|
{ |
106 |
172 |
return this.componentManager; |
107 |
|
} |
108 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
109 |
160 |
public ComponentAnnotationLoader getComponentLoader()... |
110 |
|
{ |
111 |
160 |
if (this.componentLoader == null) { |
112 |
160 |
this.componentLoader = new ComponentAnnotationLoader(); |
113 |
|
} |
114 |
|
|
115 |
160 |
return this.componentLoader; |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
118 |
160 |
private void registerComponent(Class<?> componentClass) throws Exception... |
119 |
|
{ |
120 |
160 |
List<ComponentDescriptor> descriptors = getComponentLoader().getComponentsDescriptors(componentClass); |
121 |
|
|
122 |
160 |
for (ComponentDescriptor<?> descriptor : descriptors) { |
123 |
160 |
this.componentManager.registerComponent(descriptor); |
124 |
|
} |
125 |
|
} |
126 |
|
} |