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.commons.lang.ArrayUtils; 026 import org.apache.turbine.services.pull.PullService; 027 import org.apache.turbine.services.pull.TurbinePull; 028 import org.apache.turbine.test.BaseTurbineTest; 029 import org.apache.velocity.context.Context; 030 031 032 public class UIToolTest 033 extends BaseTurbineTest 034 { 035 public UIToolTest(String name) 036 throws Exception 037 { 038 super(name, "conf/test/CompleteTurbineResources.properties"); 039 } 040 041 public static Test suite() 042 { 043 return new TestSuite(UIToolTest.class); 044 } 045 046 private UITool getTool() 047 { 048 PullService pullService = TurbinePull.getService(); 049 assertNotNull(pullService); 050 051 Context globalContext = pullService.getGlobalContext(); 052 assertNotNull(globalContext); 053 054 return (UITool) globalContext.get("ui"); 055 } 056 057 public void testTool() 058 { 059 UITool ui = getTool(); 060 assertNotNull(ui); 061 } 062 063 public void testCssSlashes() 064 { 065 UITool ui = getTool(); 066 067 String cssUrl = ui.getStylecss(); 068 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl); 069 } 070 071 public void testImageSlashes() 072 { 073 UITool ui = getTool(); 074 075 String img = "myimage.gif"; 076 077 String imgUrl = ui.image(img); 078 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl); 079 080 String img2 = "foo/myimage.gif"; 081 082 String imgUrl2 = ui.image(img2); 083 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2); 084 085 String img3 = "/foo/myimage.gif"; 086 087 String imgUrl3 = ui.image(img3); 088 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3); 089 } 090 091 public void testPathologicalCases() 092 { 093 UITool ui = getTool(); 094 095 String img = ""; 096 String imgUrl = ui.image(img); 097 assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); 098 099 img = "/"; 100 imgUrl = ui.image(img); 101 assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); 102 103 img = "//"; 104 imgUrl = ui.image(img); 105 assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl); 106 } 107 108 public void testGetSkinNames() 109 { 110 UITool ui = getTool(); 111 112 String[] skinNames = ui.getSkinNames(); 113 // Remove the ".svn" dir that may be present. 114 skinNames = (String[]) ArrayUtils.removeElement(skinNames, ".svn"); 115 assertEquals(2, skinNames.length); 116 117 assertTrue(ArrayUtils.contains(skinNames, "myotherskin")); 118 assertTrue(ArrayUtils.contains(skinNames, "myskin")); 119 } 120 121 public void testSkinValues() 122 { 123 UITool ui = getTool(); 124 125 // Default skin 126 //skin_property_1 = skin_property_1_my_skin 127 assertEquals("skin_property_1_my_skin", ui.get("skin_property_1")); 128 129 ui.setSkin("myotherskin"); 130 //skin_property_1 = skin_property_1_my_other_skin 131 assertEquals("skin_property_1_my_other_skin", ui.get("skin_property_1")); 132 } 133 }