1 package org.apache.turbine.services.pull.tools;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.commons.lang.ArrayUtils;
26 import org.apache.turbine.services.pull.PullService;
27 import org.apache.turbine.services.pull.TurbinePull;
28 import org.apache.turbine.test.BaseTurbineTest;
29 import org.apache.velocity.context.Context;
30
31
32 public class UIToolTest
33 extends BaseTurbineTest
34 {
35 public UIToolTest(String name)
36 throws Exception
37 {
38 super(name, "conf/test/TurbineResources.properties");
39 }
40
41 public static Test suite()
42 {
43 return new TestSuite(UIToolTest.class);
44 }
45
46 private UITool getTool()
47 {
48 PullService pullService = TurbinePull.getService();
49 assertNotNull(pullService);
50
51 Context globalContext = pullService.getGlobalContext();
52 assertNotNull(globalContext);
53
54 return (UITool) globalContext.get("ui");
55 }
56
57 public void testTool()
58 {
59 UITool ui = getTool();
60 assertNotNull(ui);
61 }
62
63 public void testCssSlashes()
64 {
65 UITool ui = getTool();
66
67 String cssUrl = ui.getStylecss();
68 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
69 }
70
71 public void testImageSlashes()
72 {
73 UITool ui = getTool();
74
75 String img = "myimage.gif";
76
77 String imgUrl = ui.image(img);
78 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl);
79
80 String img2 = "foo/myimage.gif";
81
82 String imgUrl2 = ui.image(img2);
83 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2);
84
85 String img3 = "/foo/myimage.gif";
86
87 String imgUrl3 = ui.image(img3);
88 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3);
89 }
90
91 public void testPathologicalCases()
92 {
93 UITool ui = getTool();
94
95 String img = "";
96 String imgUrl = ui.image(img);
97 assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
98
99 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
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
126
127 assertEquals("skin_property_1_my_skin", ui.get("skin_property_1"));
128
129 ui.setSkin("myotherskin");
130
131 assertEquals("skin_property_1_my_other_skin", ui.get("skin_property_1"));
132 }
133 }