1   package org.apache.turbine.services.pull.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.Test;
23  import junit.framework.TestSuite;
24  
25  import org.apache.turbine.services.pull.PullService;
26  import org.apache.turbine.services.pull.TurbinePull;
27  import org.apache.turbine.test.BaseTurbineTest;
28  import org.apache.velocity.context.Context;
29  
30  
31  public class UIManagerTest
32          extends BaseTurbineTest
33  {
34      public UIManagerTest(String name)
35              throws Exception
36      {
37          super(name, "conf/test/TurbineResources.properties");
38      }
39  
40      public static Test suite()
41      {
42          return new TestSuite(UIManagerTest.class);
43      }
44  
45      private UIManager getTool()
46      {
47          PullService pullService = TurbinePull.getService();
48          assertNotNull(pullService);
49  
50          Context globalContext = pullService.getGlobalContext();
51          assertNotNull(globalContext);
52  
53          return (UIManager) globalContext.get("uimanager");
54      }
55  
56      public void testTool()
57      {
58          UIManager ui = getTool();
59          assertNotNull(ui);
60      }
61  
62      public void testCssSlashes()
63      {
64          UIManager ui = getTool();
65  
66          String cssUrl = ui.getStylecss();
67          assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
68      }
69  
70      public void testImageSlashes()
71      {
72          UIManager ui = getTool();
73  
74          String img = "myimage.gif";
75  
76          String imgUrl = ui.image(img);
77          assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl);
78  
79          String img2 = "foo/myimage.gif";
80  
81          String imgUrl2 = ui.image(img2);
82          assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2);
83  
84          String img3 = "/foo/myimage.gif";
85  
86          String imgUrl3 = ui.image(img3);
87          assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3);
88      }
89  
90      public void testPathologicalCases()
91      {
92      	UIManager ui = getTool();
93  
94      	String img = "";
95          String imgUrl = ui.image(img);
96          assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
97  
98      	img = "/";
99          imgUrl = ui.image(img);
100         assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
101 
102     	img = "//";
103         imgUrl = ui.image(img);
104         assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
105     }
106 }