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