1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.macro.groovy; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
|
24 |
|
import org.junit.Test; |
25 |
|
import org.xwiki.rendering.block.MacroBlock; |
26 |
|
import org.xwiki.rendering.macro.Macro; |
27 |
|
import org.xwiki.rendering.macro.script.JSR223ScriptMacroParameters; |
28 |
|
import org.xwiki.rendering.macro.script.ScriptMockSetup; |
29 |
|
import org.xwiki.rendering.syntax.Syntax; |
30 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
31 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 5 |
Complexity Density: 0.24 |
|
39 |
|
public class ClassLoadingTest extends AbstractComponentTestCase |
40 |
|
{ |
41 |
|
private ScriptMockSetup mockSetup; |
42 |
|
|
43 |
|
private Macro<JSR223ScriptMacroParameters> macro; |
44 |
|
|
45 |
|
private MacroTransformationContext context; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
47 |
4 |
@Override... |
48 |
|
protected void registerComponents() throws Exception |
49 |
|
{ |
50 |
4 |
super.registerComponents(); |
51 |
4 |
this.mockSetup = new ScriptMockSetup(getComponentManager()); |
52 |
|
|
53 |
4 |
this.macro = getComponentManager().getInstance(Macro.class, "groovy"); |
54 |
|
|
55 |
4 |
this.context = new MacroTransformationContext(); |
56 |
|
|
57 |
4 |
this.context.setCurrentMacroBlock(new MacroBlock("groovy", Collections.<String, String>emptyMap(), false)); |
58 |
|
|
59 |
4 |
this.context.setSyntax(Syntax.XWIKI_2_0); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
62 |
1 |
@Test... |
63 |
|
public void testDefineClassInOneExecutionAndUseInAnother() throws Exception |
64 |
|
{ |
65 |
|
|
66 |
1 |
JSR223ScriptMacroParameters params = new JSR223ScriptMacroParameters(); |
67 |
1 |
this.macro.execute(params, "class MyClass {}", this.context); |
68 |
|
|
69 |
|
|
70 |
1 |
this.macro.execute(params, "def var = new MyClass()", this.context); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testExtraJarLocatedAtURL() throws Exception |
75 |
|
{ |
76 |
|
|
77 |
|
|
78 |
1 |
JSR223ScriptMacroParameters params = new JSR223ScriptMacroParameters(); |
79 |
1 |
params.setJars(getClass().getClassLoader().getResource("dummy.jar").toString()); |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
1 |
this.macro.execute(params, "def var = new Dummy()", this.context); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testJarParamsInSecondMacro() throws Exception |
92 |
|
{ |
93 |
1 |
JSR223ScriptMacroParameters params = new JSR223ScriptMacroParameters(); |
94 |
|
|
95 |
|
|
96 |
1 |
this.macro.execute(params, "def var", this.context); |
97 |
|
|
98 |
|
|
99 |
1 |
params.setJars(getClass().getClassLoader().getResource("dummy.jar").toString()); |
100 |
1 |
this.macro.execute(params, "def var = new Dummy()", this.context); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
public void testDefineClassInFirstExecutionAndJarParamsInAnother() throws Exception |
111 |
|
{ |
112 |
1 |
this.macro.execute(new JSR223ScriptMacroParameters(), "class MyClass {}", this.context); |
113 |
|
|
114 |
|
|
115 |
1 |
JSR223ScriptMacroParameters params = new JSR223ScriptMacroParameters(); |
116 |
1 |
params.setJars(getClass().getClassLoader().getResource("dummy.jar").toString()); |
117 |
1 |
this.macro.execute(params, "def var = new MyClass()", this.context); |
118 |
|
|
119 |
|
|
120 |
1 |
this.macro.execute(new JSR223ScriptMacroParameters(), "def var = new MyClass()", this.context); |
121 |
|
} |
122 |
|
} |