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