1 16 package org.apache.catalina.storeconfig; 17 18 import java.io.IOException ; 19 import java.io.StringReader ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.catalina.cluster.tcp.ReplicationTransmitter; 24 import org.apache.catalina.core.StandardContext; 25 import org.apache.catalina.core.StandardServer; 26 import org.apache.catalina.mbeans.ServerLifecycleListener; 27 import org.apache.tomcat.util.digester.Digester; 28 import org.xml.sax.SAXException ; 29 30 34 public class StoreLoaderTest extends TestCase { 35 36 public void testDigester() throws IOException , SAXException { 37 Digester digester = StoreLoader.createDigester(); 38 String example = "<Registry name=\"Tomcat\" version=\"5.5.0\" encoding=\"UTF-8\" >" 39 + " <Description " 40 + " tag=\"Server\"" 41 + " standard=\"true\"" 42 + " default=\"true\"" 43 + " tagClass=\"org.apache.catalina.core.StandardServer\"" 44 + " storeFactoryClass=\"org.apache.catalina.storeconfig.StandardServerSF\">" 45 + " </Description>" + "</Registry>"; 46 StringReader reader = new StringReader (example); 47 StoreRegistry registry = (StoreRegistry) digester.parse(reader); 48 assertNotNull(registry); 49 assertEquals("Tomcat", registry.getName()); 50 assertEquals("5.5.0", registry.getVersion()); 51 StoreDescription desc = registry.findDescription(StandardServer.class); 52 assertNotNull(desc); 53 assertEquals("org.apache.catalina.core.StandardServer", desc 54 .getTagClass()); 55 assertEquals("Server", desc.getTag()); 56 } 57 58 public void testLoadRegistry() { 59 StoreLoader loader = new StoreLoader(); 60 loader.load(); 61 StoreRegistry registry = loader.getRegistry(); 62 assertNotNull(registry); 63 assertEquals("UTF-8", registry.getEncoding()); 64 StoreDescription desc = registry.findDescription(StandardServer.class); 65 assertNotNull(desc); 66 assertEquals("org.apache.catalina.core.StandardServer", desc 67 .getTagClass()); 68 desc = registry.findDescription(StandardContext.class); 69 assertNotNull(desc); 70 assertEquals(StandardContext.class.getName(), desc.getTagClass()); 71 assertTrue(desc.isStoreSeparate()); 72 assertNotNull(desc.getStoreFactory()); 73 assertEquals(registry, desc.getStoreFactory().getRegistry()); 74 assertEquals(StandardContextSF.class, desc.getStoreFactory().getClass()); 75 desc = registry 76 .findDescription("org.apache.catalina.core.StandardServer.[ServerLifecycleListener]"); 77 assertEquals(ServerLifecycleListener.class.getName(), desc 78 .getTagClass()); 79 desc = registry.findDescription(ReplicationTransmitter.class); 80 assertNotNull(desc); 81 assertEquals(ReplicationTransmitter.class.getName(), desc 82 .getTagClass()); 83 assertNotNull(desc.getStoreFactory()); 84 assertEquals(ReplicationTransmitterStoreAppender.class, desc.getStoreFactory().getStoreAppender().getClass() 85 ); 86 87 } 88 } | Popular Tags |