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.resources.renderers; |
35 |
|
|
36 |
|
|
37 |
|
import static org.hamcrest.CoreMatchers.is; |
38 |
|
import static org.junit.Assert.assertThat; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
import info.magnolia.cms.beans.config.ServerConfiguration; |
42 |
|
import info.magnolia.cms.i18n.DefaultI18nContentSupport; |
43 |
|
import info.magnolia.cms.i18n.I18nContentSupport; |
44 |
|
import info.magnolia.context.Context; |
45 |
|
import info.magnolia.context.MgnlContext; |
46 |
|
import info.magnolia.freemarker.FreemarkerConfig; |
47 |
|
import info.magnolia.freemarker.FreemarkerHelper; |
48 |
|
import info.magnolia.i18nsystem.LocaleProvider; |
49 |
|
import info.magnolia.i18nsystem.TranslationService; |
50 |
|
import info.magnolia.init.MagnoliaConfigurationProperties; |
51 |
|
import info.magnolia.jcr.util.NodeTypes; |
52 |
|
import info.magnolia.jcr.wrapper.HTMLEscapingNodeWrapper; |
53 |
|
import info.magnolia.link.LinkTransformerManager; |
54 |
|
import info.magnolia.module.resources.ResourcesModule; |
55 |
|
import info.magnolia.module.resources.loaders.ClasspathResourceLoader; |
56 |
|
import info.magnolia.module.resources.loaders.FileSystemResourceLoader; |
57 |
|
import info.magnolia.module.resources.loaders.ResourceLoader; |
58 |
|
import info.magnolia.module.resources.templates.ResourceTemplate; |
59 |
|
import info.magnolia.objectfactory.Components; |
60 |
|
import info.magnolia.objectfactory.guice.GuiceUtils; |
61 |
|
import info.magnolia.rendering.context.RenderingContext; |
62 |
|
import info.magnolia.rendering.engine.DefaultRenderingEngine; |
63 |
|
import info.magnolia.rendering.engine.RenderingEngine; |
64 |
|
import info.magnolia.rendering.model.RenderingModel; |
65 |
|
import info.magnolia.rendering.model.RenderingModelImpl; |
66 |
|
import info.magnolia.rendering.template.RenderableDefinition; |
67 |
|
import info.magnolia.rendering.template.assignment.MetaDataBasedTemplateDefinitionAssignment; |
68 |
|
import info.magnolia.rendering.template.assignment.TemplateDefinitionAssignment; |
69 |
|
import info.magnolia.rendering.template.variation.NoopVariationResolver; |
70 |
|
import info.magnolia.rendering.template.variation.RenderableVariationResolver; |
71 |
|
import info.magnolia.rendering.util.AppendableWriter; |
72 |
|
import info.magnolia.test.ComponentsTestUtil; |
73 |
|
import info.magnolia.test.MgnlTestCase; |
74 |
|
import info.magnolia.test.mock.MockContent; |
75 |
|
import info.magnolia.test.mock.MockWebContext; |
76 |
|
import info.magnolia.test.mock.jcr.MockNode; |
77 |
|
|
78 |
|
import java.io.File; |
79 |
|
import java.io.IOException; |
80 |
|
import java.util.Arrays; |
81 |
|
import java.util.LinkedHashMap; |
82 |
|
import java.util.LinkedList; |
83 |
|
import java.util.List; |
84 |
|
import java.util.Locale; |
85 |
|
import java.util.Map; |
86 |
|
|
87 |
|
import javax.inject.Provider; |
88 |
|
import javax.jcr.Node; |
89 |
|
import javax.servlet.ServletContext; |
90 |
|
import javax.servlet.http.HttpServletRequest; |
91 |
|
import javax.servlet.http.HttpServletResponse; |
92 |
|
|
93 |
|
import org.apache.commons.io.FileUtils; |
94 |
|
import org.junit.Before; |
95 |
|
import org.junit.Test; |
96 |
|
|
97 |
|
import freemarker.cache.ClassTemplateLoader; |
98 |
|
import freemarker.cache.StringTemplateLoader; |
99 |
|
import freemarker.cache.TemplateLoader; |
100 |
|
import junit.framework.Assert; |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@link |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (173) |
Complexity: 11 |
Complexity Density: 0.07 |
|
106 |
|
public class ResourcesTextTemplateRendererTest extends MgnlTestCase { |
107 |
|
|
108 |
|
|
109 |
|
private ResourcesTextTemplateRenderer renderer = null; |
110 |
|
private RenderingContext ctx = null; |
111 |
|
private static final String CONTENT_IDENTIFIER = "12345"; |
112 |
|
private MockNode content; |
113 |
|
private RenderingModel<?> parentModel; |
114 |
|
|
115 |
|
private HttpServletResponse response; |
116 |
|
|
117 |
|
private ResourcesModule resourcesModule; |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
119 |
8 |
@Override... |
120 |
|
@Before |
121 |
|
public void setUp() throws Exception { |
122 |
8 |
super.setUp(); |
123 |
|
|
124 |
8 |
TemplateLoader tplLoader = new StringTemplateLoader(); |
125 |
8 |
FreemarkerConfig fmConfig = new FreemarkerConfig(); |
126 |
8 |
fmConfig.setTemplateLoaders(Arrays.asList(tplLoader, new ClassTemplateLoader(getClass(), "/"))); |
127 |
|
|
128 |
8 |
final FreemarkerHelper fmHelper = new FreemarkerHelper(fmConfig); |
129 |
8 |
ComponentsTestUtil.setImplementation(RenderingEngine.class, DefaultRenderingEngine.class); |
130 |
8 |
ComponentsTestUtil.setImplementation(TemplateDefinitionAssignment.class, MetaDataBasedTemplateDefinitionAssignment.class); |
131 |
8 |
ComponentsTestUtil.setImplementation(RenderableVariationResolver.class, NoopVariationResolver.class); |
132 |
8 |
ComponentsTestUtil.setInstance(Provider.class, mock(Provider.class)); |
133 |
8 |
ComponentsTestUtil.setInstance(TranslationService.class, mock(TranslationService.class)); |
134 |
8 |
ComponentsTestUtil.setInstance(LocaleProvider.class, mock(LocaleProvider.class)); |
135 |
|
|
136 |
8 |
final ServerConfiguration serverConfiguration = new ServerConfiguration(); |
137 |
8 |
serverConfiguration.setDefaultExtension("ext"); |
138 |
8 |
serverConfiguration.setDefaultBaseUrl("/magnolia"); |
139 |
8 |
ComponentsTestUtil.setInstance(ServerConfiguration.class, serverConfiguration); |
140 |
8 |
ComponentsTestUtil.setInstance(LinkTransformerManager.class, new LinkTransformerManager()); |
141 |
8 |
ComponentsTestUtil.setInstance(I18nContentSupport.class, new DefaultI18nContentSupport()); |
142 |
|
|
143 |
8 |
initMagnoliaWebContext(); |
144 |
|
|
145 |
8 |
resourcesModule = new ResourcesModule(); |
146 |
8 |
renderer = new ResourcesTextTemplateRenderer(fmHelper, Components.getComponent(RenderingEngine.class), GuiceUtils.providerForInstance(resourcesModule)); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
152 |
8 |
private void initMagnoliaWebContext(){... |
153 |
|
|
154 |
8 |
MockContent mockContent = new MockContent("mockContent"); |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
8 |
parentModel = mock(RenderingModel.class); |
160 |
8 |
MgnlContext.getInstance().setAttribute(RenderingModel.class.getName(), parentModel, Context.APPLICATION_SCOPE); |
161 |
8 |
MgnlContext.getAggregationState().setMainContent(mockContent); |
162 |
8 |
response = mock(HttpServletResponse.class); |
163 |
8 |
((MockWebContext) MgnlContext.getWebContext()).setResponse(response); |
164 |
|
|
165 |
8 |
((MockWebContext) MgnlContext.getWebContext()).setServletContext(mock(ServletContext.class)); |
166 |
|
|
167 |
8 |
((MockWebContext) MgnlContext.getWebContext()).setLocale(new Locale("en")); |
168 |
8 |
((MockWebContext) MgnlContext.getWebContext()).setRequest(mock(HttpServletRequest.class)); |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
171 |
|
public static class DummyModel extends RenderingModelImpl<RenderableDefinition> { |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
8 |
public DummyModel(Node content, RenderableDefinition definition, RenderingModel<?> parent) {... |
174 |
8 |
super(content, definition, parent); |
175 |
|
} |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
8 |
@Override... |
178 |
|
public String execute() { |
179 |
8 |
return "keepOnGoing"; |
180 |
|
} |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
186 |
8 |
private StringBuilder initRenderingContext(ResourceTemplate resourceTemplate) throws Exception{... |
187 |
|
|
188 |
8 |
StringBuilder builder = new StringBuilder(); |
189 |
8 |
AppendableWriter writer = new AppendableWriter(builder); |
190 |
|
|
191 |
|
|
192 |
8 |
ctx = mock(RenderingContext.class); |
193 |
8 |
when(ctx.getAppendable()).thenReturn(writer); |
194 |
|
|
195 |
8 |
RenderableDefinition definition = resourceTemplate; |
196 |
8 |
RenderingModel newModel = mock(RenderingModel.class); |
197 |
8 |
when(definition.getModelClass()).thenReturn(DummyModel.class); |
198 |
8 |
when(newModel.execute()).thenReturn("keepOnGoing"); |
199 |
8 |
when(ctx.getCurrentContent()).thenReturn(content); |
200 |
8 |
when(ctx.getRenderableDefinition()).thenReturn(definition); |
201 |
|
|
202 |
8 |
return builder; |
203 |
|
} |
204 |
|
|
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
206 |
1 |
@Test... |
207 |
|
public void testOnRenderProcessed() throws Exception{ |
208 |
|
|
209 |
|
|
210 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
211 |
|
|
212 |
1 |
MockNode root = new MockNode(); |
213 |
1 |
content = (MockNode) root.addNode("content"); |
214 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
215 |
1 |
content.setProperty("extension", "css"); |
216 |
1 |
content.setProperty("text", "[#assign textColor=\"#ff0099\"] color = ${textColor} and content.extension = ${content.extension}"); |
217 |
1 |
content.setProperty("modelClass", ""); |
218 |
|
|
219 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
220 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
221 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(true); |
222 |
|
|
223 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
224 |
|
|
225 |
|
|
226 |
1 |
renderer.render(ctx, contextObjects); |
227 |
|
|
228 |
|
|
229 |
1 |
Assert.assertEquals("Output should be the following: "," color = #ff0099 and content.extension = css", builder.toString()); |
230 |
|
} |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
232 |
1 |
@Test... |
233 |
|
public void testOnRenderNoProcessed() throws Exception{ |
234 |
|
|
235 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
236 |
|
|
237 |
1 |
MockNode root = new MockNode(); |
238 |
1 |
content = (MockNode) root.addNode("content"); |
239 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
240 |
1 |
content.setProperty("extension", "css"); |
241 |
1 |
content.setProperty("text", "[#assign textColor=\"#ff0099\"] color = ${textColor} and content.extension = ${content.extension}"); |
242 |
1 |
content.setProperty("modelClass", ""); |
243 |
|
|
244 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
245 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
246 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
247 |
|
|
248 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
249 |
|
|
250 |
|
|
251 |
1 |
renderer.render(ctx, contextObjects); |
252 |
|
|
253 |
|
|
254 |
1 |
Assert.assertEquals("Output should be the following: ","[#assign textColor=\"#ff0099\"] color = ${textColor} and content.extension = ${content.extension}", builder.toString()); |
255 |
1 |
verify(response).setContentType("text/css"); |
256 |
|
} |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
258 |
1 |
@Test... |
259 |
|
public void testOnRenderProcessedByPass() throws Exception{ |
260 |
|
|
261 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
262 |
|
|
263 |
1 |
MockNode root = new MockNode(); |
264 |
|
|
265 |
1 |
content = (MockNode) root.addNode("info").addNode("magnolia").addNode("module").addNode("resource").addNode("test").addNode("template"); |
266 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
267 |
1 |
content.setProperty("extension", "ftl"); |
268 |
1 |
content.setProperty("text", ""); |
269 |
1 |
content.setProperty("modelClass", ""); |
270 |
1 |
content.setProperty("bypass",true); |
271 |
|
|
272 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
273 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
274 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(true); |
275 |
|
|
276 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
277 |
|
|
278 |
|
|
279 |
1 |
renderer.render(ctx, contextObjects); |
280 |
|
|
281 |
|
|
282 |
1 |
Assert.assertEquals("Output should be the following: "," color = #ff0099 and content.extension = ftl", builder.toString()); |
283 |
|
} |
284 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
285 |
1 |
@Test... |
286 |
|
public void testOnRenderNoProcessedByPass() throws Exception{ |
287 |
|
|
288 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
289 |
|
|
290 |
1 |
MockNode root = new MockNode(); |
291 |
1 |
content = (MockNode) root.addNode("info").addNode("magnolia").addNode("module").addNode("resource").addNode("test").addNode("template"); |
292 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
293 |
1 |
content.setProperty("extension", "ftl"); |
294 |
1 |
content.setProperty("text", ""); |
295 |
1 |
content.setProperty("modelClass", ""); |
296 |
1 |
content.setProperty("bypass",true); |
297 |
|
|
298 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
299 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
300 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
301 |
|
|
302 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
303 |
|
|
304 |
1 |
resourcesModule.addResourceLoader(new ClasspathResourceLoader()); |
305 |
|
|
306 |
|
|
307 |
1 |
renderer.render(ctx, contextObjects); |
308 |
|
|
309 |
|
|
310 |
1 |
Assert.assertEquals("Output should be the following: ","[#assign textColor=\"#ff0099\"] color = ${textColor} and content.extension = ${content.extension}", builder.toString()); |
311 |
|
} |
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
313 |
1 |
@Test... |
314 |
|
public void testRenderJavascriptDecoded() throws Exception { |
315 |
|
|
316 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
317 |
|
|
318 |
1 |
content = new MockNode(); |
319 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
320 |
1 |
content.setProperty("text", "alert(\"Hello\");"); |
321 |
1 |
content.setProperty("modelClass", ""); |
322 |
1 |
content.setProperty("bypass", false); |
323 |
|
|
324 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
325 |
1 |
when(resourceTemplate.getContentType()).thenReturn("x-application/javascript"); |
326 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
327 |
|
|
328 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
329 |
|
|
330 |
1 |
HTMLEscapingNodeWrapper wrapped = new HTMLEscapingNodeWrapper(content, true); |
331 |
|
|
332 |
1 |
when(ctx.getCurrentContent()).thenReturn(wrapped); |
333 |
|
|
334 |
|
|
335 |
1 |
renderer.render(ctx, contextObjects); |
336 |
|
|
337 |
|
|
338 |
1 |
Assert.assertEquals("alert(\"Hello\");", builder.toString()); |
339 |
|
} |
340 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
341 |
1 |
@Test... |
342 |
|
public void testRenderCssDecoded() throws Exception { |
343 |
|
|
344 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
345 |
|
|
346 |
1 |
content = new MockNode(); |
347 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
348 |
1 |
content.setProperty("text", "font-family:\"Open Sans\",Verdana,\"Geneva CE\",lucida,sans-serif;"); |
349 |
1 |
content.setProperty("modelClass", ""); |
350 |
1 |
content.setProperty("bypass", false); |
351 |
|
|
352 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
353 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
354 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
355 |
|
|
356 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
357 |
|
|
358 |
1 |
HTMLEscapingNodeWrapper wrapped = new HTMLEscapingNodeWrapper(content, true); |
359 |
|
|
360 |
1 |
when(ctx.getCurrentContent()).thenReturn(wrapped); |
361 |
|
|
362 |
|
|
363 |
1 |
renderer.render(ctx, contextObjects); |
364 |
|
|
365 |
|
|
366 |
1 |
Assert.assertEquals("font-family:\"Open Sans\",Verdana,\"Geneva CE\",lucida,sans-serif;", builder.toString()); |
367 |
|
} |
368 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
369 |
1 |
@Test... |
370 |
|
public void testResourcesAreLoadedFromArbitraryPath() throws Exception { |
371 |
|
|
372 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
373 |
|
|
374 |
1 |
content = new MockNode("style"); |
375 |
1 |
content.setIdentifier(CONTENT_IDENTIFIER); |
376 |
1 |
content.setProperty("modelClass", ""); |
377 |
1 |
content.setProperty("bypass", true); |
378 |
1 |
content.setProperty("extension", "css"); |
379 |
|
|
380 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
381 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
382 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
383 |
|
|
384 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
385 |
|
|
386 |
1 |
when(ctx.getCurrentContent()).thenReturn(content); |
387 |
|
|
388 |
1 |
FileSystemResourceLoader loader = new FileSystemResourceLoader(mock(MagnoliaConfigurationProperties.class)); |
389 |
1 |
loader.setPath(new File("").getAbsolutePath() + "/src/test/resources/my/resources/"); |
390 |
1 |
resourcesModule.addResourceLoader(loader); |
391 |
|
|
392 |
|
|
393 |
1 |
renderer.render(ctx, contextObjects); |
394 |
|
|
395 |
|
|
396 |
1 |
Assert.assertEquals("font-family:\"Open Sans\",Verdana,\"Geneva CE\",lucida,sans-serif;", builder.toString()); |
397 |
|
} |
398 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
399 |
1 |
@Test... |
400 |
|
public void testWhenResourceLoaderThrowsIOExceptionThatNextResourceLoaderIsUsed() throws Exception { |
401 |
|
|
402 |
1 |
Map<String, Object> contextObjects = new LinkedHashMap<String, Object>(); |
403 |
|
|
404 |
1 |
Node root = new MockNode("templating-kit"); |
405 |
1 |
Node content = root.addNode("test", NodeTypes.Resource.NAME); |
406 |
1 |
content.setProperty("modelClass", ""); |
407 |
1 |
content.setProperty("bypass", true); |
408 |
1 |
content.setProperty("extension", "txt"); |
409 |
|
|
410 |
1 |
ResourceTemplate resourceTemplate = mock(ResourceTemplate.class); |
411 |
1 |
when(resourceTemplate.getContentType()).thenReturn("text/css"); |
412 |
1 |
when(resourceTemplate.isProcessed()).thenReturn(false); |
413 |
|
|
414 |
1 |
StringBuilder builder = initRenderingContext(resourceTemplate); |
415 |
|
|
416 |
1 |
when(ctx.getCurrentContent()).thenReturn(content); |
417 |
|
|
418 |
1 |
ResourceLoader loaderThrowingIOException = mock(ResourceLoader.class); |
419 |
1 |
when(loaderThrowingIOException.getStream("/templating-kit/test.txt")).thenThrow(new IOException()); |
420 |
1 |
ResourceLoader loader = new ClasspathResourceLoader(); |
421 |
1 |
List<ResourceLoader> loaders = new LinkedList<ResourceLoader>(); |
422 |
1 |
loaders.add(loaderThrowingIOException); |
423 |
1 |
loaders.add(loader); |
424 |
|
|
425 |
1 |
resourcesModule.setResourceLoaders(loaders); |
426 |
|
|
427 |
|
|
428 |
1 |
renderer.render(ctx, contextObjects); |
429 |
|
|
430 |
|
|
431 |
1 |
verify(loaderThrowingIOException).getStream("/templating-kit/test.txt"); |
432 |
1 |
File file = new File("src/test/resources/templating-kit/test.txt"); |
433 |
1 |
assertThat(FileUtils.readFileToString(file), is(builder.toString())); |
434 |
|
} |
435 |
|
|
436 |
|
} |