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.task; |
35 |
|
|
36 |
|
import static info.magnolia.module.groovy.GroovyModule.SCRIPTS_REPOSITORY_NAME; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
import static org.mockito.BDDMockito.given; |
39 |
|
import static org.mockito.Mockito.mock; |
40 |
|
|
41 |
|
import info.magnolia.context.MgnlContext; |
42 |
|
import info.magnolia.context.SystemContext; |
43 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
44 |
|
import info.magnolia.module.InstallContext; |
45 |
|
import info.magnolia.module.InstallContext.Message; |
46 |
|
import info.magnolia.module.InstallContext.MessagePriority; |
47 |
|
import info.magnolia.module.InstallContextImpl; |
48 |
|
import info.magnolia.module.ModuleRegistryImpl; |
49 |
|
import info.magnolia.module.delta.TaskExecutionException; |
50 |
|
import info.magnolia.test.ComponentsTestUtil; |
51 |
|
import info.magnolia.ui.framework.message.MessagesManager; |
52 |
|
|
53 |
|
import java.io.IOException; |
54 |
|
import java.util.List; |
55 |
|
import java.util.Map; |
56 |
|
|
57 |
|
import javax.jcr.Session; |
58 |
|
|
59 |
|
import org.junit.After; |
60 |
|
import org.junit.Before; |
61 |
|
import org.junit.Test; |
62 |
|
|
63 |
|
import groovy.lang.GroovyRuntimeException; |
64 |
|
|
65 |
|
|
|
|
| 94.1% |
Uncovered Elements: 3 (51) |
Complexity: 11 |
Complexity Density: 0.26 |
|
66 |
|
public class ExecuteGroovyFileTaskTest { |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
68 |
5 |
@Before... |
69 |
|
public void setUp() throws Exception { |
70 |
5 |
SystemContext context = mock(SystemContext.class); |
71 |
5 |
Session session = mock(Session.class); |
72 |
5 |
given(context.getJCRSession(SCRIPTS_REPOSITORY_NAME)).willReturn(session); |
73 |
5 |
ComponentsTestUtil.setInstance(SystemContext.class, context); |
74 |
5 |
ComponentsTestUtil.setInstance(MessagesManager.class, mock(MessagesManager.class)); |
75 |
5 |
ComponentsTestUtil.setInstance(SimpleTranslator.class, mock(SimpleTranslator.class)); |
76 |
5 |
MgnlContext.setInstance(context); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
79 |
5 |
@After... |
80 |
|
public void tearDown() throws Exception { |
81 |
5 |
ComponentsTestUtil.setInstance(SystemContext.class, null); |
82 |
5 |
MgnlContext.setInstance(null); |
83 |
|
} |
84 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
public void inputFileNotExisting() throws Exception { |
87 |
|
|
88 |
1 |
String inputFilename = "info/magnolia/module/groovy/test/notExisting.groovy"; |
89 |
1 |
try { |
90 |
|
|
91 |
1 |
doTestExecuteTask(inputFilename); |
92 |
|
|
93 |
0 |
fail("Should have faced an exception of type IOException"); |
94 |
|
} catch (TaskExecutionException tee) { |
95 |
1 |
Throwable throwable = tee.getCause(); |
96 |
|
|
97 |
1 |
assertTrue("Exception should be of a subtype of IOException ", throwable instanceof IOException); |
98 |
|
} |
99 |
|
} |
100 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void inputFileNull() throws Exception { |
103 |
|
|
104 |
1 |
String inputFilename = null; |
105 |
1 |
try { |
106 |
|
|
107 |
1 |
doTestExecuteTask(inputFilename); |
108 |
|
|
109 |
0 |
fail("Should have faced an exception of type IOException"); |
110 |
|
} catch (TaskExecutionException tee) { |
111 |
1 |
Throwable throwable = tee.getCause(); |
112 |
|
|
113 |
1 |
assertTrue("Exception should be of a subtype of IOException ", throwable instanceof IOException); |
114 |
|
} |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
117 |
1 |
@Test... |
118 |
|
public void inputFileEmpty() throws Exception { |
119 |
|
|
120 |
1 |
String inputFilename = "info/magnolia/module/groovy/test/task/Empty.groovy"; |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
InstallContext installContext = doTestExecuteTask(inputFilename); |
125 |
|
|
126 |
|
|
127 |
1 |
Map<String, List<Message>> messages = installContext.getMessages(); |
128 |
1 |
assertNotNull("Should have messages", messages); |
129 |
1 |
assertEquals("Message should be of priority Info", messages.get("General messages").get(0).getPriority(), MessagePriority.info); |
130 |
1 |
assertEquals("This message should be empty ", messages.get("General messages").get(0).getMessage().length(), 0); |
131 |
|
} |
132 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void inputFileGeneratingGroovyException() throws Exception { |
135 |
|
|
136 |
1 |
String inputFilename = "info/magnolia/module/groovy/test/Buggy.groovy"; |
137 |
1 |
try { |
138 |
|
|
139 |
1 |
doTestExecuteTask(inputFilename); |
140 |
|
|
141 |
0 |
fail("Should have faced an exception of type GroovyRuntimeException"); |
142 |
|
} catch (TaskExecutionException tee) { |
143 |
1 |
Throwable throwable = tee.getCause(); |
144 |
|
|
145 |
1 |
assertTrue("Exception should be of a subtype of GroovyRuntimeException ", throwable instanceof GroovyRuntimeException); |
146 |
|
} |
147 |
|
} |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
149 |
1 |
@Test... |
150 |
|
public void inputFileHappyFlow() throws Exception { |
151 |
|
|
152 |
1 |
String inputFilename = "info/magnolia/module/groovy/test/task/Dummy.groovy"; |
153 |
|
|
154 |
|
|
155 |
1 |
InstallContext installContext = doTestExecuteTask(inputFilename); |
156 |
|
|
157 |
1 |
Map<String, List<Message>> messages = installContext.getMessages(); |
158 |
1 |
assertNotNull("Should have messages", messages); |
159 |
1 |
assertEquals("Message should be of priority Info", messages.get("General messages").get(0).getPriority(), MessagePriority.info); |
160 |
1 |
assertEquals("This message should be 'Init dialog map' ", messages.get("General messages").get(0).getMessage(), "Init dialog map\n"); |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
163 |
5 |
private InstallContext doTestExecuteTask(String fileName) throws TaskExecutionException {... |
164 |
5 |
final InstallContext installCtx = new InstallContextImpl(new ModuleRegistryImpl()); |
165 |
|
|
166 |
5 |
final ExecuteGroovyFileTask task = new ExecuteGroovyFileTask("Test", "Description", fileName); |
167 |
5 |
task.execute(installCtx); |
168 |
|
|
169 |
2 |
return installCtx; |
170 |
|
} |
171 |
|
} |