1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.capability;
18
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23 import org.apache.turbine.util.TurbineConfig;
24 import org.apache.turbine.util.StringUtils;
25
26
27 import org.apache.jetspeed.test.JetspeedTestCase;
28 import org.apache.jetspeed.capability.CapabilityMapFactory;
29 import org.apache.jetspeed.capability.CapabilityMap;
30 import org.apache.jetspeed.services.Registry;
31 import org.apache.jetspeed.om.registry.ClientRegistry;
32 import org.apache.jetspeed.om.registry.ClientEntry;
33 import org.apache.jetspeed.util.MimeType;
34
35 /***
36 * Unit test for capbility package
37 *
38 * @author <a href="raphael@apache.org">Raphaël Luta</a>
39 * @version $Id: TestCapabilityMap.java,v 1.1 2004/04/07 22:02:42 jford Exp $
40 */
41
42 public class TestCapabilityMap extends JetspeedTestCase
43 {
44
45 /***
46 * Defines the testcase name for JUnit.
47 *
48 * @param name the testcase's name.
49 */
50 public TestCapabilityMap( String name )
51 {
52 super( name );
53 }
54
55 /***
56 * Start the tests.
57 *
58 * @param args the arguments. Not used
59 */
60 public static void main(String args[])
61 {
62 junit.awtui.TestRunner.main( new String[] { TestCapabilityMap.class.getName() } );
63 }
64
65 public void setup()
66 {
67 System.out.println("Setup: Testing CapabilityMap functionality");
68 }
69 /***
70 * Creates the test suite.
71 *
72 * @return a test suite (<code>TestSuite</code>) that includes all methods
73 * starting with "test"
74 */
75 public static Test suite()
76 {
77
78 return new TestSuite( TestCapabilityMap.class );
79 }
80
81 public void testRegistry() throws Exception
82 {
83 try
84 {
85
86 ClientRegistry cr = (ClientRegistry)Registry.get(Registry.CLIENT);
87 ClientEntry ce = (ClientEntry)cr.getEntry("ie5");
88 assertNotNull(ce);
89 }
90 catch (Exception e)
91 {
92 String errmsg = "Error in test: " + e.toString();
93
94 assertNotNull(errmsg, null);
95 }
96 }
97
98 public void testDefaultMap() throws Exception
99 {
100 try
101 {
102
103 CapabilityMap cm = CapabilityMapFactory.getDefaultCapabilityMap();
104 assertNotNull(cm);
105 assertTrue(cm.toString().startsWith("ns4"));
106 }
107 catch (Exception e)
108 {
109 String errmsg = "Error in test: " + e.toString();
110
111 assertNotNull(errmsg, null);
112 }
113 }
114
115 public void testStandardMap() throws Exception
116 {
117 try
118 {
119
120 getUserAgent("ie5","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
121 getUserAgent("ns4","Mozilla/4.78 (Windows 2000; U) Opera 6.01 [fr]");
122 getUserAgent("mozilla","Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0rc1) Gecko/20020417");
123 getUserAgent("nokia_generic","Nokia3330/1.0 (03.05)");
124 getUserAgent("lynx","Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b");
125 }
126 catch (Exception e)
127 {
128 String errmsg = "Error in test: " + e.toString();
129
130 assertNotNull(errmsg, null);
131 }
132 }
133
134 public void testCapabilityCheck() throws Exception
135 {
136 try
137 {
138
139 CapabilityMap cm = CapabilityMapFactory.getCapabilityMap("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0rc1) Gecko/20020417");
140 assertTrue(cm.hasCapability("HTML_DOM_1"));
141 assertTrue(cm.hasCapability("HTML_IFRAME"));
142 assertTrue(cm.supportsMimeType(MimeType.XML));
143 assertTrue(cm.supportsMediaType("html"));
144 }
145 catch (Exception e)
146 {
147 String errmsg = "Error in test: " + e.toString();
148
149 assertNotNull(errmsg, null);
150 }
151 }
152
153 private void getUserAgent(String name, String ua)
154 {
155 CapabilityMap cm = CapabilityMapFactory.getCapabilityMap(ua);
156 assertNotNull(cm);
157 assertNotNull(name);
158 assertTrue(cm.toString().startsWith(name));
159 }
160
161
162
163
164
165 private static TurbineConfig config = null;
166
167
168
169
170
171 static
172 {
173 try
174 {
175 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
176 config.init();
177 }
178 catch (Exception e)
179 {
180 fail(StringUtils.stackTrace(e));
181 }
182 }
183 }