001: package org.apache.turbine.services.pull.tools;
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 UIToolTest extends BaseTurbineTest {
031: public UIToolTest(String name) throws Exception {
032: super (name, "conf/test/TurbineResources.properties");
033: }
034:
035: public static Test suite() {
036: return new TestSuite(UIToolTest.class);
037: }
038:
039: private UITool getTool() {
040: PullService pullService = TurbinePull.getService();
041: assertNotNull(pullService);
042:
043: Context globalContext = pullService.getGlobalContext();
044: assertNotNull(globalContext);
045:
046: return (UITool) globalContext.get("ui");
047: }
048:
049: public void testTool() {
050: UITool ui = getTool();
051: assertNotNull(ui);
052: }
053:
054: public void testCssSlashes() {
055: UITool 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: UITool 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: UITool 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:
114: public void testGetSkinNames() {
115: UITool ui = getTool();
116:
117: String[] skinNames = ui.getSkinNames();
118: // two real skins + ".svn"
119: assertEquals(3, skinNames.length);
120:
121: // Not completely sure this will always be in the same order.
122: assertEquals(".svn", skinNames[0]); // Not actually a skin
123: assertEquals("myotherskin", skinNames[1]);
124: assertEquals("myskin", skinNames[2]);
125: }
126:
127: public void testSkinValues() {
128: UITool ui = getTool();
129:
130: // Default skin
131: //skin_property_1 = skin_property_1_my_skin
132: assertEquals("skin_property_1_my_skin", ui
133: .get("skin_property_1"));
134:
135: ui.setSkin("myotherskin");
136: //skin_property_1 = skin_property_1_my_other_skin
137: assertEquals("skin_property_1_my_other_skin", ui
138: .get("skin_property_1"));
139: }
140: }
|