1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.context.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import javax.inject.Provider; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.component.util.ReflectionUtils; |
32 |
|
import org.xwiki.context.Execution; |
33 |
|
import org.xwiki.context.ExecutionContext; |
34 |
|
import org.xwiki.context.ExecutionContextException; |
35 |
|
import org.xwiki.context.ExecutionContextInitializer; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@SuppressWarnings("unchecked") |
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 3 |
Complexity Density: 0.16 |
|
44 |
|
public class DefaultExecutionContextManagerTest |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void cloneExecutionContext() throws Exception |
51 |
|
{ |
52 |
1 |
Execution execution = new DefaultExecution(); |
53 |
1 |
ExecutionContext context = new ExecutionContext(); |
54 |
1 |
execution.setContext(context); |
55 |
|
|
56 |
1 |
Map<Object, Object> xwikicontext = new HashMap<>(); |
57 |
1 |
context.newProperty("property1").initial(xwikicontext).inherited().declare(); |
58 |
1 |
context.newProperty("property2").initial(xwikicontext).inherited().makeFinal().cloneValue().declare(); |
59 |
|
|
60 |
1 |
DefaultExecutionContextManager contextManager = new DefaultExecutionContextManager(); |
61 |
1 |
ReflectionUtils.setFieldValue(contextManager, "execution", execution); |
62 |
|
|
63 |
|
|
64 |
1 |
final ExecutionContextInitializer initializer = new ExecutionContextInitializer() |
65 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
1 |
@Override... |
67 |
|
public void initialize(ExecutionContext context) throws ExecutionContextException |
68 |
|
{ |
69 |
1 |
context.setProperty("key", Arrays.asList("value")); |
70 |
|
} |
71 |
|
}; |
72 |
1 |
Provider<List<ExecutionContextInitializer>> provider = new Provider<List<ExecutionContextInitializer>>() |
73 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
1 |
@Override... |
75 |
|
public List<ExecutionContextInitializer> get() |
76 |
|
{ |
77 |
1 |
return Arrays.asList(initializer); |
78 |
|
} |
79 |
|
}; |
80 |
1 |
ReflectionUtils.setFieldValue(contextManager, "initializerProvider", provider); |
81 |
|
|
82 |
1 |
ExecutionContext clonedContext = contextManager.clone(context); |
83 |
|
|
84 |
1 |
Assert.assertSame(context, execution.getContext()); |
85 |
1 |
Assert.assertEquals("value", ((List<String>) clonedContext.getProperty("key")).get(0)); |
86 |
1 |
Assert.assertNotSame(context.getProperty("key"), clonedContext.getProperty("key")); |
87 |
1 |
Assert.assertSame(xwikicontext, clonedContext.getProperty("property1")); |
88 |
1 |
Assert.assertNotSame(xwikicontext, clonedContext.getProperty("property2")); |
89 |
|
} |
90 |
|
} |