1 package org.apache.turbine.services.velocity;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.commons.collections.ExtendedProperties;
23 import org.apache.commons.configuration.Configuration;
24
25 import org.apache.turbine.Turbine;
26 import org.apache.turbine.services.TurbineServices;
27 import org.apache.turbine.test.BaseTurbineTest;
28
29 /***
30 * Tests startup of the Velocity Service and translation of various
31 * path patterns.
32 *
33 * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
34 * @version $Id: PathConverterTest.java 264148 2005-08-29 14:21:04Z henning $
35 */
36 public class PathConverterTest
37 extends BaseTurbineTest
38 {
39 private static VelocityService vs = null;
40 private static String fileSeperator = System.getProperty("file.separator");
41
42 public PathConverterTest(String name)
43 throws Exception
44 {
45 super(name, "/conf/test/TemplateService.properties");
46
47 vs = (VelocityService) TurbineServices.getInstance().getService(VelocityService.SERVICE_NAME);
48 }
49
50 public static Test suite()
51 {
52 return new TestSuite(PathConverterTest.class);
53 }
54
55 public void testService()
56 throws Exception
57 {
58
59
60 assertNotNull("Could not load Service!", vs);
61 }
62
63 public void testPathTranslation()
64 throws Exception
65 {
66 Configuration conf = vs.getConfiguration();
67 ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
68
69 String rootPath = Turbine.getRealPath("");
70
71 String [] test1 = ep.getStringArray("test1.resource.loader.path");
72 assertEquals("No Test1 Property found", 1, test1.length);
73 assertEquals("Test1 Path translation failed", rootPath
74 +fileSeperator+"relative"+fileSeperator+"path" , test1[0]);
75
76 String [] test2 = ep.getStringArray("test2.resource.loader.path");
77 assertEquals("No Test2 Property found", 1, test2.length);
78 assertEquals("Test2 Path translation failed", rootPath
79 +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]);
80
81 String [] test3 = ep.getStringArray("test3.resource.loader.path");
82 assertEquals("No Test3 Property found", 1, test2.length);
83 assertEquals("Test3 Path translation failed", rootPath
84 +fileSeperator+"jar-file.jar!/", test3[0]);
85
86 String [] test4 = ep.getStringArray("test4.resource.loader.path");
87 assertEquals("No Test4 Property found", 1, test4.length);
88 assertEquals("Test4 Path translation failed", rootPath
89 +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]);
90
91 String [] test5 = ep.getStringArray("test5.resource.loader.path");
92 assertEquals("No Test5 Property found", 1, test5.length);
93 assertEquals("Test5 Path translation failed", rootPath
94 +fileSeperator+"jar-file.jar" , test5[0]);
95
96 String [] test6 = ep.getStringArray("test6.resource.loader.path");
97 assertEquals("No Test6 Property found", 1, test6.length);
98 assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]);
99
100 String [] test7 = ep.getStringArray("test7.resource.loader.path");
101 assertEquals("No Test7 Property found", 1, test7.length);
102 assertEquals("Test7 Path translation failed", rootPath
103 +fileSeperator+"file"+fileSeperator
104 +"system"+fileSeperator+"reference" , test7[0]);
105
106 String [] test8 = ep.getStringArray("test8.resource.loader.path");
107 assertEquals("No Test8 Property found", 1, test8.length);
108 assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]);
109
110 }
111 }