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
20
21
22
23
24 import org.apache.commons.collections.ExtendedProperties;
25 import org.apache.commons.configuration.Configuration;
26 import org.apache.turbine.Turbine;
27 import org.apache.turbine.services.TurbineServices;
28 import org.apache.turbine.test.BaseTestCase;
29 import org.apache.turbine.util.TurbineConfig;
30
31
32
33
34
35
36
37
38
39 public class PathConverterTest
40 extends BaseTestCase
41 {
42 private static TurbineConfig tc = null;
43 private static VelocityService vs = null;
44 private static String fileSeperator = System.getProperty("file.separator");
45
46 public PathConverterTest(String name)
47 throws Exception
48 {
49 super(name);
50 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties");
51 tc.initialize();
52
53 vs = (VelocityService) TurbineServices.getInstance().getService(VelocityService.SERVICE_NAME);
54 }
55
56
57 public void testService()
58 throws Exception
59 {
60
61
62 assertNotNull("Could not load Service!", vs);
63 }
64
65 public void testPathTranslation()
66 throws Exception
67 {
68 Configuration conf = vs.getConfiguration();
69 ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
70
71 String rootPath = Turbine.getRealPath("");
72
73 String [] test1 = ep.getStringArray("test1.resource.loader.path");
74 assertEquals("No Test1 Property found", 1, test1.length);
75 assertEquals("Test1 Path translation failed", rootPath
76 +fileSeperator+"relative"+fileSeperator+"path" , test1[0]);
77
78 String [] test2 = ep.getStringArray("test2.resource.loader.path");
79 assertEquals("No Test2 Property found", 1, test2.length);
80 assertEquals("Test2 Path translation failed", rootPath
81 +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]);
82
83 String [] test3 = ep.getStringArray("test3.resource.loader.path");
84 assertEquals("No Test3 Property found", 1, test2.length);
85 assertEquals("Test3 Path translation failed", rootPath
86 +fileSeperator+"jar-file.jar!/", test3[0]);
87
88 String [] test4 = ep.getStringArray("test4.resource.loader.path");
89 assertEquals("No Test4 Property found", 1, test4.length);
90 assertEquals("Test4 Path translation failed", rootPath
91 +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]);
92
93 String [] test5 = ep.getStringArray("test5.resource.loader.path");
94 assertEquals("No Test5 Property found", 1, test5.length);
95 assertEquals("Test5 Path translation failed", rootPath
96 +fileSeperator+"jar-file.jar" , test5[0]);
97
98 String [] test6 = ep.getStringArray("test6.resource.loader.path");
99 assertEquals("No Test6 Property found", 1, test6.length);
100 assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]);
101
102 String [] test7 = ep.getStringArray("test7.resource.loader.path");
103 assertEquals("No Test7 Property found", 1, test7.length);
104 assertEquals("Test7 Path translation failed", rootPath
105 +fileSeperator+"file"+fileSeperator
106 +"system"+fileSeperator+"reference" , test7[0]);
107
108 String [] test8 = ep.getStringArray("test8.resource.loader.path");
109 assertEquals("No Test8 Property found", 1, test8.length);
110 assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]);
111
112 }
113 }