1 16 17 package org.apache.jetspeed.capability; 18 19 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 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 41 42 public class TestCapabilityMap extends JetspeedTestCase 43 { 44 45 50 public TestCapabilityMap( String name ) 51 { 52 super( name ); 53 } 54 55 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 75 public static Test suite() 76 { 77 return new TestSuite( TestCapabilityMap.class ); 79 } 80 81 public void testRegistry() throws Exception 82 { 83 try 84 { 85 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 assertNotNull(errmsg, null); 95 } 96 } 97 98 public void testDefaultMap() throws Exception 99 { 100 try 101 { 102 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 assertNotNull(errmsg, null); 112 } 113 } 114 115 public void testStandardMap() throws Exception 116 { 117 try 118 { 119 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 assertNotNull(errmsg, null); 131 } 132 } 133 134 public void testCapabilityCheck() throws Exception 135 { 136 try 137 { 138 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 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 165 private static TurbineConfig config = null; 166 167 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 } 184 | Popular Tags |