1   package org.apache.turbine.services.pull.util;
2   
3   /*
4    * Copyright 2001-2005 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.turbine.services.pull.PullService;
23  import org.apache.turbine.services.pull.TurbinePull;
24  import org.apache.turbine.test.BaseTurbineTest;
25  import org.apache.velocity.context.Context;
26  
27  
28  public class UIManagerTest
29          extends BaseTurbineTest
30  {
31      public UIManagerTest(String name)
32              throws Exception
33      {
34          super(name, "conf/test/TurbineResources.properties");
35      }
36  
37      public static Test suite()
38      {
39          return new TestSuite(UIManagerTest.class);
40      }
41  
42      private UIManager getTool()
43      {
44          PullService pullService = TurbinePull.getService();
45          assertNotNull(pullService);
46  
47          Context globalContext = pullService.getGlobalContext();
48          assertNotNull(globalContext);
49  
50          return (UIManager) globalContext.get("ui");
51      }
52  
53      public void testTool()
54      {
55          UIManager ui = getTool();
56          assertNotNull(ui);
57      }
58  
59      public void testCssSlashes()
60      {
61          UIManager ui = getTool();
62  
63          String cssUrl = ui.getStylecss();
64          assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
65      }
66  
67      public void testImageSlashes()
68      {
69          UIManager ui = getTool();
70  
71          String img = "myimage.gif";
72  
73          String imgUrl = ui.image(img);
74          assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl);
75  
76          String img2 = "foo/myimage.gif";
77  
78          String imgUrl2 = ui.image(img2);
79          assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2);
80  
81          String img3 = "/foo/myimage.gif";
82  
83          String imgUrl3 = ui.image(img3);
84          assertEquals("CSS URL does not match", "http:///turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3);
85      }
86  
87      public void testPathologicalCases()
88      {
89      	UIManager ui = getTool();
90  
91      	String img = "";
92          String imgUrl = ui.image(img);
93          assertEquals("Could not strip empty String", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
94  
95      	img = "/";
96          imgUrl = ui.image(img);
97          assertEquals("Could not strip single Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
98  
99      	img = "//";
100         imgUrl = ui.image(img);
101         assertEquals("Could not strip double Slash", "http:///turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
102     }
103 }