1 package org.codehaus.plexus.velocity;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import javax.inject.Inject;
20
21 import java.io.StringWriter;
22
23 import org.apache.velocity.Template;
24 import org.apache.velocity.VelocityContext;
25 import org.codehaus.plexus.testing.PlexusTest;
26 import org.junit.jupiter.api.Test;
27
28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 import static org.junit.jupiter.api.Assertions.assertNotNull;
30
31 @PlexusTest
32 public class DefaultVelocityComponentTest {
33
34 @Inject
35 private VelocityComponent velocity;
36
37 @Test
38 public void testBasic() {
39
40
41 String value = (String) velocity.getEngine().getProperty("hello");
42
43 assertNotNull(value);
44 assertEquals("world", value);
45
46
47 VelocityContext context = new VelocityContext();
48
49 context.put("variable", "Value from context");
50
51 Template template =
52 velocity.getEngine().getTemplate("org/codehaus/plexus/velocity/DefaultVelocityComponentTest.vm");
53
54 StringWriter writer = new StringWriter();
55
56 template.merge(context, writer);
57
58 assertEquals("Static text -- Value from context -- More static text", writer.toString());
59 }
60 }