1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.testing.jupiter; |
20 |
|
|
21 |
|
import java.io.File; |
22 |
|
import java.io.InputStream; |
23 |
|
|
24 |
|
import org.codehaus.plexus.ContainerConfiguration; |
25 |
|
import org.codehaus.plexus.DefaultContainerConfiguration; |
26 |
|
import org.codehaus.plexus.DefaultPlexusContainer; |
27 |
|
import org.codehaus.plexus.PlexusContainer; |
28 |
|
import org.codehaus.plexus.PlexusContainerException; |
29 |
|
import org.codehaus.plexus.configuration.PlexusConfiguration; |
30 |
|
import org.codehaus.plexus.context.Context; |
31 |
|
import org.codehaus.plexus.context.DefaultContext; |
32 |
|
import org.junit.jupiter.api.AfterEach; |
33 |
|
import org.junit.jupiter.api.Assertions; |
34 |
|
|
35 |
|
|
36 |
|
@author |
37 |
|
@since |
38 |
|
|
|
|
| 5,3% |
Uncovered Elements: 90 (95) |
Complexity: 34 |
Complexity Density: 0,63 |
|
39 |
|
public abstract class PlexusTestCase extends TestCase { |
40 |
|
|
41 |
|
private PlexusContainer container; |
42 |
|
|
43 |
|
private static String basedirPath; |
44 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
45 |
2 |
public PlexusTestCase() {... |
46 |
|
} |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 5 |
Complexity Density: 0,25 |
|
48 |
0 |
public void setupContainer() {... |
49 |
|
|
50 |
0 |
final DefaultContext context = new DefaultContext(); |
51 |
|
|
52 |
0 |
context.put("basedir", getBasedir()); |
53 |
|
|
54 |
0 |
customizeContext(context); |
55 |
|
|
56 |
0 |
final boolean hasPlexusHome = context.contains("plexus.home"); |
57 |
|
|
58 |
0 |
if (!hasPlexusHome) { |
59 |
0 |
final File f = getTestFile("target/plexus-home"); |
60 |
|
|
61 |
0 |
if (!f.isDirectory()) { |
62 |
0 |
f.mkdir(); |
63 |
|
} |
64 |
|
|
65 |
0 |
context.put("plexus.home", f.getAbsolutePath()); |
66 |
|
} |
67 |
|
|
68 |
0 |
final String config = getCustomConfigurationName(); |
69 |
|
|
70 |
0 |
final ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setName("test") |
71 |
|
.setContext(context.getContextData()); |
72 |
|
|
73 |
0 |
if (config != null) { |
74 |
0 |
containerConfiguration.setContainerConfiguration(config); |
75 |
|
} else { |
76 |
0 |
final String resource = getConfigurationName(null); |
77 |
|
|
78 |
0 |
containerConfiguration.setContainerConfiguration(resource); |
79 |
|
} |
80 |
|
|
81 |
0 |
customizeContainerConfiguration(containerConfiguration); |
82 |
|
|
83 |
0 |
try { |
84 |
0 |
container = new DefaultPlexusContainer(containerConfiguration); |
85 |
|
} catch (final PlexusContainerException e) { |
86 |
0 |
e.printStackTrace(); |
87 |
0 |
Assertions.fail("Failed to create plexus container."); |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
96 |
0 |
protected void customizeContainerConfiguration(final ContainerConfiguration containerConfiguration) {... |
97 |
|
} |
98 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
99 |
0 |
protected void customizeContext(final Context context) {... |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
protected PlexusConfiguration customizeComponentConfiguration() {... |
103 |
0 |
return null; |
104 |
|
} |
105 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
106 |
2 |
@AfterEach... |
107 |
|
public void tearDown() throws Exception { |
108 |
2 |
if (container != null) { |
109 |
0 |
container.dispose(); |
110 |
|
} |
111 |
2 |
container = null; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
114 |
0 |
protected PlexusContainer getContainer() {... |
115 |
0 |
if (container == null) { |
116 |
0 |
setupContainer(); |
117 |
|
} |
118 |
|
|
119 |
0 |
return container; |
120 |
|
} |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
protected InputStream getConfiguration() throws Exception {... |
123 |
0 |
return getConfiguration(null); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
protected InputStream getConfiguration(final String subname) throws Exception {... |
127 |
0 |
return getResourceAsStream(getConfigurationName(subname)); |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
protected String getCustomConfigurationName() {... |
131 |
0 |
return null; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@param |
140 |
|
|
141 |
|
@return |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
protected String getConfigurationName(final String subname) {... |
144 |
0 |
return getClass().getName().replace('.', '/') + ".xml"; |
145 |
|
} |
146 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
0 |
protected InputStream getResourceAsStream(final String resource) {... |
148 |
0 |
return getClass().getResourceAsStream(resource); |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0 |
protected ClassLoader getClassLoader() {... |
152 |
0 |
return getClass().getClassLoader(); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
0 |
@SuppressWarnings("unchecked")... |
160 |
|
protected <T> T lookup(final String componentKey) throws Exception { |
161 |
0 |
return (T) getContainer().lookup(componentKey); |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
0 |
@SuppressWarnings("unchecked")... |
165 |
|
protected <T> T lookup(final String role, final String roleHint) throws Exception { |
166 |
0 |
return (T) getContainer().lookup(role, roleHint); |
167 |
|
} |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
0 |
protected <T> T lookup(final Class<T> componentClass) throws Exception {... |
170 |
0 |
return getContainer().lookup(componentClass); |
171 |
|
} |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
0 |
protected <T> T lookup(final Class<T> componentClass, final String roleHint) throws Exception {... |
174 |
0 |
return getContainer().lookup(componentClass, roleHint); |
175 |
|
} |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
0 |
protected void release(final Object component) throws Exception {... |
178 |
0 |
getContainer().release(component); |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
0 |
public static File getTestFile(final String path) {... |
186 |
0 |
return new File(getBasedir(), path); |
187 |
|
} |
188 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
189 |
0 |
public static File getTestFile(final String basedir, final String path) {... |
190 |
0 |
File basedirFile = new File(basedir); |
191 |
|
|
192 |
0 |
if (!basedirFile.isAbsolute()) { |
193 |
0 |
basedirFile = getTestFile(basedir); |
194 |
|
} |
195 |
|
|
196 |
0 |
return new File(basedirFile, path); |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
0 |
public static String getTestPath(final String path) {... |
200 |
0 |
return getTestFile(path).getAbsolutePath(); |
201 |
|
} |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
203 |
0 |
public static String getTestPath(final String basedir, final String path) {... |
204 |
0 |
return getTestFile(basedir, path).getAbsolutePath(); |
205 |
|
} |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0,5 |
|
207 |
0 |
public static String getBasedir() {... |
208 |
0 |
if (basedirPath != null) { |
209 |
0 |
return basedirPath; |
210 |
|
} |
211 |
|
|
212 |
0 |
basedirPath = System.getProperty("basedir"); |
213 |
0 |
if (basedirPath == null) { |
214 |
0 |
basedirPath = new File("").getAbsolutePath(); |
215 |
|
} |
216 |
0 |
return basedirPath; |
217 |
|
} |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0 |
public String getTestConfiguration() {... |
220 |
0 |
return getTestConfiguration(getClass()); |
221 |
|
} |
222 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
223 |
0 |
public static String getTestConfiguration(final Class<?> clazz) {... |
224 |
0 |
final String s = clazz.getName().replace('.', '/'); |
225 |
|
|
226 |
0 |
return s.substring(0, s.indexOf("$")) + ".xml"; |
227 |
|
} |
228 |
|
} |