1 16 package org.apache.catalina.storeconfig; 17 18 import java.io.PrintWriter ; 19 import java.io.StringWriter ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.catalina.Lifecycle; 24 import org.apache.catalina.LifecycleListener; 25 import org.apache.catalina.core.StandardServer; 26 import org.apache.catalina.core.StandardService; 27 import org.apache.catalina.deploy.NamingResources; 28 import org.apache.catalina.storeconfig.StandardServerSF; 29 import org.apache.catalina.storeconfig.StoreDescription; 30 import org.apache.catalina.storeconfig.StoreRegistry; 31 32 36 public class ServerChildsTest extends TestCase { 37 38 StoreRegistry registry; 39 40 StringWriter writer = new StringWriter (); 41 42 PrintWriter pWriter = new PrintWriter (writer); 43 44 StandardServer standardServer = new StandardServer(); 45 46 StandardServerSF factory; 47 48 StoreDescription desc; 49 50 55 protected void setUp() throws Exception { 56 57 super.setUp(); 58 registry = new StoreRegistry(); 59 desc = new StoreDescription(); 60 desc.setTag("Server"); 61 desc.setTagClass("org.apache.catalina.core.StandardServer"); 62 desc.setStandard(true); 63 desc 64 .setStoreFactoryClass("org.apache.catalina.storeconfig.StandardServerSF"); 65 registry.registerDescription(desc); 66 factory = new StandardServerSF(); 67 desc.setStoreFactory(factory); 68 factory.setRegistry(registry); 69 StoreDescription listdesc = registerDescriptor("Listener", 70 LifecycleListener.class); 71 listdesc 72 .addTransientChild("org.apache.catalina.core.NamingContextListener"); 73 listdesc 74 .addTransientChild("org.apache.catalina.mbeans.ServerLifecycleListener"); 75 standardServer 76 .addLifecycleListener(new org.apache.catalina.mbeans.ServerLifecycleListener()); 77 DescriptorHelper.registerDescriptor(desc, registry, 79 NamingResources.class.getName() + ".[GlobalNamingResources]", 80 "GlobalNamingResources", NamingResources.class.getName(), 81 "org.apache.catalina.storeconfig.GlobalNamingResourcesSF", 82 true, false); 83 DescriptorHelper.registerNamingDescriptor(desc, registry); 84 registerDescriptor("Service", StandardService.class, 85 "org.apache.catalina.storeconfig.StandardServiceSF", true, 86 false); 87 DescriptorHelper.registerDescriptor(desc, registry, 88 StandardServer.class.getName() + ".[ServerLifecycleListener]", 89 "ServerLifecycleListener", StandardServer.class.getName(), 90 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 91 false); 92 standardServer.addService(new StandardService()); 93 94 } 95 96 private StoreDescription registerDescriptor(String tag, Class aClass) { 97 return registerDescriptor(tag, aClass, 98 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 99 false); 100 } 101 102 private StoreDescription registerDescriptor(String tag, Class aClass, 103 String factoryClass, boolean fstandard, boolean fdefault) { 104 return DescriptorHelper.registerDescriptor(desc, registry, aClass 105 .getName(), tag, aClass.getName(), factoryClass, fstandard, 106 fdefault); 107 } 108 109 public void testSaveListenerAddServer() throws Exception { 110 assertTrue(standardServer instanceof Lifecycle); 111 assertNotNull( 112 "No Listener Descriptor", 113 registry 114 .findDescription("org.apache.catalina.mbeans.ServerLifecycleListener")); 115 assertNotNull( 116 "No Listener StoreFactory", 117 registry 118 .findStoreFactory("org.apache.catalina.mbeans.ServerLifecycleListener")); 119 factory.store(pWriter, -2, standardServer); 120 121 String aspectedResult = "<?xml version=\"1.0\" encoding=\"" 122 + registry.getEncoding() 123 + "\"?>" 124 + LF.LINE_SEPARATOR 125 + "<Server>" 126 + LF.LINE_SEPARATOR 127 + " <Listener className=\"org.apache.catalina.mbeans.ServerLifecycleListener\"/>" 128 + LF.LINE_SEPARATOR + " <GlobalNamingResources>" 129 + LF.LINE_SEPARATOR + " </GlobalNamingResources>" 130 + LF.LINE_SEPARATOR + " <Service/>" + LF.LINE_SEPARATOR 131 + "</Server>" + LF.LINE_SEPARATOR; 132 assertEquals(aspectedResult, writer.toString()); 133 } 134 } | Popular Tags |