1 package org.apache.turbine.services.pull.util;
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.turbine.services.pull.PullService;
26 import org.apache.turbine.services.pull.TurbinePull;
27 import org.apache.turbine.test.BaseTurbineTest;
28 import org.apache.velocity.context.Context;
29
30
31 public class UIManagerTest
32 extends BaseTurbineTest
33 {
34 public UIManagerTest(String name)
35 throws Exception
36 {
37 super(name, "conf/test/TurbineResources.properties");
38 }
39
40 public static Test suite()
41 {
42 return new TestSuite(UIManagerTest.class);
43 }
44
45 private UIManager getTool()
46 {
47 PullService pullService = TurbinePull.getService();
48 assertNotNull(pullService);
49
50 Context globalContext = pullService.getGlobalContext();
51 assertNotNull(globalContext);
52
53 return (UIManager) globalContext.get("uimanager");
54 }
55
56 public void testTool()
57 {
58 UIManager ui = getTool();
59 assertNotNull(ui);
60 }
61
62 public void testCssSlashes()
63 {
64 UIManager ui = getTool();
65
66 String cssUrl = ui.getStylecss();
67 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/skins.css", cssUrl);
68 }
69
70 public void testImageSlashes()
71 {
72 UIManager ui = getTool();
73
74 String img = "myimage.gif";
75
76 String imgUrl = ui.image(img);
77 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img, imgUrl);
78
79 String img2 = "foo/myimage.gif";
80
81 String imgUrl2 = ui.image(img2);
82 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/" + img2, imgUrl2);
83
84 String img3 = "/foo/myimage.gif";
85
86 String imgUrl3 = ui.image(img3);
87 assertEquals("CSS URL does not match", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images" + img3, imgUrl3);
88 }
89
90 public void testPathologicalCases()
91 {
92 UIManager ui = getTool();
93
94 String img = "";
95 String imgUrl = ui.image(img);
96 assertEquals("Could not strip empty String", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
97
98 img = "/";
99 imgUrl = ui.image(img);
100 assertEquals("Could not strip single Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
101
102 img = "//";
103 imgUrl = ui.image(img);
104 assertEquals("Could not strip double Slash", "http:///conf/test/turbine-resources/turbine-skins/myskin/turbine-images/", imgUrl);
105 }
106 }