1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.groovy.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Collections; |
24 |
|
|
25 |
|
import javax.script.ScriptEngine; |
26 |
|
import javax.script.ScriptEngineFactory; |
27 |
|
import javax.script.ScriptEngineManager; |
28 |
|
import javax.script.ScriptException; |
29 |
|
|
30 |
|
import org.jmock.Expectations; |
31 |
|
import org.junit.Assert; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.configuration.ConfigurationSource; |
34 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 3 |
Complexity Density: 0.21 |
|
42 |
|
public class TimedInterruptGroovyCompilationCustomizerTest extends AbstractComponentTestCase |
43 |
|
{ |
44 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1PASS
|
|
45 |
1 |
@Test(timeout = 10000)... |
46 |
|
public void executeWithTimedInterruptCustomizer() throws Exception |
47 |
|
{ |
48 |
1 |
final ConfigurationSource source = registerMockComponent(ConfigurationSource.class); |
49 |
|
|
50 |
1 |
getMockery().checking(new Expectations() |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
51 |
1 |
{{... |
52 |
1 |
oneOf(source).getProperty("groovy.compilationCustomizers", Collections.emptyList()); |
53 |
1 |
will(returnValue(Arrays.asList("timedInterrupt"))); |
54 |
1 |
oneOf(source).getProperty("groovy.customizer.timedInterrupt.timeout", 60L); |
55 |
1 |
will(returnValue(1L)); |
56 |
|
}}); |
57 |
|
|
58 |
1 |
ScriptEngineManager manager = new ScriptEngineManager(); |
59 |
1 |
ScriptEngineFactory groovyScriptEngineFactory = |
60 |
|
getComponentManager().getInstance(ScriptEngineFactory.class, "groovy"); |
61 |
1 |
manager.registerEngineName("groovy", groovyScriptEngineFactory); |
62 |
|
|
63 |
1 |
final ScriptEngine engine = manager.getEngineByName("groovy"); |
64 |
|
|
65 |
|
|
66 |
1 |
try { |
67 |
1 |
engine.eval("while (true) {}"); |
68 |
0 |
Assert.fail("Should have thrown an exception here"); |
69 |
|
} catch (ScriptException e) { |
70 |
1 |
Assert.assertTrue(e.getMessage().contains("Execution timed out after 1 units.")); |
71 |
|
} |
72 |
|
} |
73 |
|
} |