KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > velocity > PathConverterTest


1 package org.apache.turbine.services.velocity;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.6.2.3 2004/08/14 20:57:59 henning Exp $
35  */

36 public class PathConverterTest
37     extends BaseTurbineTest
38 {
39     private static VelocityService vs = null;
40     private static String JavaDoc fileSeperator = System.getProperty("file.separator");
41
42     public PathConverterTest(String JavaDoc name)
43             throws Exception JavaDoc
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 JavaDoc
57     {
58
59         // Can we start the service?
60
assertNotNull("Could not load Service!", vs);
61     }
62
63     public void testPathTranslation()
64         throws Exception JavaDoc
65     {
66         Configuration conf = vs.getConfiguration();
67         ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
68
69         String JavaDoc rootPath = Turbine.getRealPath("");
70
71         String JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 JavaDoc [] 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 }
112
Popular Tags