1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.groovy.console; |
35 |
|
|
36 |
|
import static org.mockito.Matchers.*; |
37 |
|
import static org.mockito.Mockito.*; |
38 |
|
|
39 |
|
import info.magnolia.context.Context; |
40 |
|
import info.magnolia.context.MgnlContext; |
41 |
|
import info.magnolia.context.SystemContext; |
42 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
43 |
|
import info.magnolia.module.groovy.console.MgnlGroovyConsole.ScriptCallback; |
44 |
|
import info.magnolia.objectfactory.ComponentProvider; |
45 |
|
import info.magnolia.test.ComponentsTestUtil; |
46 |
|
import info.magnolia.ui.framework.message.MessagesManager; |
47 |
|
|
48 |
|
import javax.jcr.Session; |
49 |
|
|
50 |
|
import org.junit.After; |
51 |
|
import org.junit.Before; |
52 |
|
import org.junit.Test; |
53 |
|
|
54 |
|
import com.vaadin.event.UIEvents.PollListener; |
55 |
|
import com.vaadin.ui.UI; |
56 |
|
|
57 |
|
import groovy.lang.Binding; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 5 |
Complexity Density: 0.26 |
|
59 |
|
public class MgnlGroovyConsoleTest { |
60 |
|
|
61 |
|
private MgnlGroovyConsole console; |
62 |
|
private ScriptCallback callback; |
63 |
|
private UI ui; |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
65 |
3 |
@Before... |
66 |
|
public void setUp() throws Exception { |
67 |
3 |
MgnlContext.setInstance(mock(Context.class)); |
68 |
3 |
ComponentsTestUtil.setInstance(ComponentProvider.class, mock(ComponentProvider.class)); |
69 |
|
|
70 |
3 |
Session session = mock(Session.class); |
71 |
3 |
when(session.nodeExists(anyString())).thenReturn(false); |
72 |
|
|
73 |
3 |
SystemContext systemContext = mock(SystemContext.class); |
74 |
3 |
when(systemContext.getJCRSession(anyString())).thenReturn(session); |
75 |
3 |
ComponentsTestUtil.setInstance(SystemContext.class, systemContext); |
76 |
|
|
77 |
3 |
console = new MgnlGroovyConsole(new Binding(), mock(MessagesManager.class), mock(SimpleTranslator.class)); |
78 |
3 |
callback = mock(ScriptCallback.class); |
79 |
3 |
ui = mock(UI.class); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
82 |
3 |
@After... |
83 |
|
public void tearDown() throws Exception { |
84 |
3 |
ComponentsTestUtil.clear(); |
85 |
3 |
MgnlContext.setInstance(null); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void fastScriptReturnsWithoutStartingPolling() throws Exception { |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
1 |
console.runAsync("return 'hello'", ui, callback); |
94 |
|
|
95 |
|
|
96 |
1 |
verify(ui, never()).addPollListener(any(PollListener.class)); |
97 |
1 |
verify(callback).onSuccess("hello"); |
98 |
|
} |
99 |
|
|
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void longRunningScriptStartsPolling() throws Exception { |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
1 |
console.runAsync("Thread.sleep(1000); return 'done'", ui, callback); |
107 |
|
|
108 |
|
|
109 |
1 |
verify(ui, times(1)).addPollListener(any(PollListener.class)); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void scriptWithNoReturnStatementDoesNotPrintOutNull() throws Exception { |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
1 |
console.runAsync("for(i=0; i< 3; i++) {}", ui, callback); |
118 |
|
|
119 |
|
|
120 |
1 |
verify(callback).onSuccess(""); |
121 |
|
} |
122 |
|
} |