001: package org.apache.turbine.services.pull.util;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import org.apache.turbine.services.pull.PullService;
023: import org.apache.turbine.services.pull.TurbinePull;
024: import org.apache.turbine.test.BaseTurbineTest;
025: import org.apache.velocity.context.Context;
026:
027: public class UIManagerTest extends BaseTurbineTest {
028: public UIManagerTest(String name) throws Exception {
029: super (name, "conf/test/TurbineResources.properties");
030: }
031:
032: public static Test suite() {
033: return new TestSuite(UIManagerTest.class);
034: }
035:
036: private UIManager getTool() {
037: PullService pullService = TurbinePull.getService();
038: assertNotNull(pullService);
039:
040: Context globalContext = pullService.getGlobalContext();
041: assertNotNull(globalContext);
042:
043: return (UIManager) globalContext.get("ui");
044: }
045:
046: public void testTool() {
047: UIManager ui = getTool();
048: assertNotNull(ui);
049: }
050:
051: public void testCssSlashes() {
052: UIManager ui = getTool();
053:
054: String cssUrl = ui.getStylecss();
055: assertEquals(
056: "CSS URL does not match",
057: "http:///turbine-resources/turbine-skins/myskin/skins.css",
058: cssUrl);
059: }
060:
061: public void testImageSlashes() {
062: UIManager ui = getTool();
063:
064: String img = "myimage.gif";
065:
066: String imgUrl = ui.image(img);
067: assertEquals("CSS URL does not match",
068: "http:///turbine-resources/turbine-skins/myskin/turbine-images/"
069: + img, imgUrl);
070:
071: String img2 = "foo/myimage.gif";
072:
073: String imgUrl2 = ui.image(img2);
074: assertEquals("CSS URL does not match",
075: "http:///turbine-resources/turbine-skins/myskin/turbine-images/"
076: + img2, imgUrl2);
077:
078: String img3 = "/foo/myimage.gif";
079:
080: String imgUrl3 = ui.image(img3);
081: assertEquals("CSS URL does not match",
082: "http:///turbine-resources/turbine-skins/myskin/turbine-images"
083: + img3, imgUrl3);
084: }
085:
086: public void testPathologicalCases() {
087: UIManager ui = getTool();
088:
089: String img = "";
090: String imgUrl = ui.image(img);
091: assertEquals(
092: "Could not strip empty String",
093: "http:///turbine-resources/turbine-skins/myskin/turbine-images/",
094: imgUrl);
095:
096: img = "/";
097: imgUrl = ui.image(img);
098: assertEquals(
099: "Could not strip single Slash",
100: "http:///turbine-resources/turbine-skins/myskin/turbine-images/",
101: imgUrl);
102:
103: img = "//";
104: imgUrl = ui.image(img);
105: assertEquals(
106: "Could not strip double Slash",
107: "http:///turbine-resources/turbine-skins/myskin/turbine-images/",
108: imgUrl);
109: }
110: }
|