| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.velocity; |
| 21 |
|
|
| 22 |
|
import java.io.StringWriter; |
| 23 |
|
import java.util.Properties; |
| 24 |
|
|
| 25 |
|
import javax.servlet.ServletContext; |
| 26 |
|
|
| 27 |
|
import org.apache.velocity.VelocityContext; |
| 28 |
|
import org.junit.Assert; |
| 29 |
|
import org.junit.Test; |
| 30 |
|
import org.xwiki.environment.Environment; |
| 31 |
|
import org.xwiki.environment.internal.ServletEnvironment; |
| 32 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@link |
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
@since |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 40 |
|
public class XWikiWebappResourceLoaderTest extends AbstractComponentTestCase |
| 41 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
| 42 |
1 |
@Test... |
| 43 |
|
public void testVelocityInitialization() throws Exception |
| 44 |
|
{ |
| 45 |
|
|
| 46 |
1 |
ServletEnvironment environment = (ServletEnvironment) getComponentManager().getInstance(Environment.class); |
| 47 |
1 |
environment.setServletContext(getMockery().mock(ServletContext.class)); |
| 48 |
|
|
| 49 |
1 |
Properties properties = new Properties(); |
| 50 |
1 |
properties.setProperty("resource.loader", "xwiki"); |
| 51 |
1 |
properties.setProperty("xwiki.resource.loader.class", XWikiWebappResourceLoader.class.getName()); |
| 52 |
|
|
| 53 |
1 |
VelocityFactory factory = getComponentManager().getInstance(VelocityFactory.class); |
| 54 |
1 |
VelocityEngine engine = factory.createVelocityEngine("key", properties); |
| 55 |
|
|
| 56 |
|
|
| 57 |
1 |
StringWriter out = new StringWriter(); |
| 58 |
1 |
engine.evaluate(new VelocityContext(), out, "template", "#set ($var = 'value')$var"); |
| 59 |
1 |
Assert.assertEquals("value", out.toString()); |
| 60 |
|
} |
| 61 |
|
} |