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.LifecycleListener; 24 import org.apache.catalina.Valve; 25 import org.apache.catalina.core.StandardEngine; 26 import org.apache.catalina.core.StandardHost; 27 import org.apache.catalina.realm.JAASRealm; 28 import org.apache.catalina.storeconfig.StandardEngineSF; 29 import org.apache.catalina.storeconfig.StoreDescription; 30 import org.apache.catalina.storeconfig.StoreRegistry; 31 32 36 public class StandardEngineSFTest extends TestCase { 37 StoreRegistry registry; 38 39 StringWriter writer = new StringWriter (); 40 41 PrintWriter pWriter = new PrintWriter (writer); 42 43 StandardEngine standardEngine; 44 45 StandardEngineSF factory; 46 47 StoreDescription desc; 48 49 54 protected void setUp() throws Exception { 55 56 super.setUp(); 57 registry = new StoreRegistry(); 58 desc = new StoreDescription(); 59 desc.setTag("Engine"); 60 desc.setTagClass("org.apache.catalina.core.StandardEngine"); 61 desc.setStandard(true); 62 desc 63 .setStoreFactoryClass("org.apache.catalina.storeconfig.StandardEngineSF"); 64 desc.addTransientAttribute("domain"); 65 registry.registerDescription(desc); 66 factory = new StandardEngineSF(); 67 desc.setStoreFactory(factory); 68 factory.setRegistry(registry); 69 StoreDescription listenerdesc = registerDescriptor("Listener", 70 LifecycleListener.class); 71 72 String listenerskippables[] = { 73 "org.apache.catalina.core.NamingContextListener", 74 "org.apache.catalina.startup.ContextConfig", 75 "org.apache.catalina.startup.EngineConfig", 76 "org.apache.catalina.startup.HostConfig", }; 77 for (int i = 0; i < listenerskippables.length; i++) 78 listenerdesc.addTransientChild(listenerskippables[i]); 79 80 StoreDescription realmdesc = registerDescriptor("Realm", 81 JAASRealm.class, 82 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false); 83 StoreDescription hostdesc = registerDescriptor("Host", 84 StandardHost.class, 85 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false); 86 hostdesc.addTransientAttribute("domain"); 87 StoreDescription valvedesc = registerDescriptor("Valve", Valve.class, 88 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 89 false); 90 91 String skippables[] = { 92 "org.apache.catalina.authenticator.BasicAuthenticator", 93 "org.apache.catalina.authenticator.DigestAuthenticator", 94 "org.apache.catalina.authenticator.FormAuthenticator", 95 "org.apache.catalina.authenticator.NonLoginAuthenticator", 96 "org.apache.catalina.authenticator.SSLAuthenticator", 97 "org.apache.catalina.core.StandardContextValve", 98 "org.apache.catalina.core.StandardEngineValve", 99 "org.apache.catalina.core.StandardHostValve", 100 "org.apache.catalina.valves.CertificatesValve", 101 "org.apache.catalina.valves.ErrorReportValve", 102 "org.apache.catalina.valves.RequestListenerValve", }; 103 for (int i = 0; i < skippables.length; i++) 104 valvedesc.addTransientChild(skippables[i]); 105 106 standardEngine = new StandardEngine(); 107 standardEngine.setName("Catalina"); 108 109 } 110 111 private StoreDescription registerDescriptor(String tag, Class aClass) { 112 return registerDescriptor(tag, aClass, 113 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 114 false); 115 } 116 117 120 private StoreDescription registerDescriptor(String tag, Class aClass, 121 String factoryClass, boolean fstandard, boolean fdefault) { 122 return DescriptorHelper.registerDescriptor(desc, registry, aClass 123 .getName(), tag, aClass.getName(), factoryClass, fstandard, 124 fdefault); 125 } 126 127 public void testStore() throws Exception { 128 standardEngine 129 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener()); 130 StandardHost host = new StandardHost(); 131 host.setName("localhost"); 132 standardEngine.addChild(host); 133 String aspectedResult = "<Engine" 134 + LF.LINE_SEPARATOR 135 + " name=\"Catalina\">" 136 + LF.LINE_SEPARATOR 137 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>" 138 + LF.LINE_SEPARATOR + " <Realm" + LF.LINE_SEPARATOR 139 + " appName=\"Catalina\"/>" + LF.LINE_SEPARATOR + " <Host" 140 + LF.LINE_SEPARATOR + " name=\"localhost\"/>" 141 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR; 142 143 check(aspectedResult); 144 } 145 146 public void testElements() throws Exception { 147 standardEngine.setName("Catalina"); 148 standardEngine 149 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener()); 150 standardEngine 151 .addLifecycleListener(new org.apache.catalina.startup.EngineConfig()); 152 StandardHost host = new StandardHost(); 153 host.setName("localhost"); 154 standardEngine.addChild(host); 155 String aspectedResult = "<Engine" 156 + LF.LINE_SEPARATOR 157 + " name=\"Catalina\">" 158 + LF.LINE_SEPARATOR 159 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>" 160 + LF.LINE_SEPARATOR + " <Realm" + LF.LINE_SEPARATOR 161 + " appName=\"Catalina\"/>" + LF.LINE_SEPARATOR + " <Host" 162 + LF.LINE_SEPARATOR + " name=\"localhost\"/>" 163 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR; 164 check(aspectedResult); 165 } 166 167 public void testValve() throws Exception { 168 standardEngine.setName("Catalina"); 169 standardEngine 170 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener()); 171 standardEngine 172 .addLifecycleListener(new org.apache.catalina.startup.EngineConfig()); 173 StandardHost host = new StandardHost(); 174 host.setName("localhost"); 175 standardEngine.addChild(host); 176 standardEngine 177 .addValve(new org.apache.catalina.valves.ErrorReportValve()); 178 standardEngine 179 .addValve(new org.apache.catalina.valves.RequestDumperValve()); 180 String aspectedResult = "<Engine" 181 + LF.LINE_SEPARATOR 182 + " name=\"Catalina\">" 183 + LF.LINE_SEPARATOR 184 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>" 185 + LF.LINE_SEPARATOR 186 + " <Realm" 187 + LF.LINE_SEPARATOR 188 + " appName=\"Catalina\"/>" 189 + LF.LINE_SEPARATOR 190 + " <Valve className=\"org.apache.catalina.valves.RequestDumperValve\"/>" 191 + LF.LINE_SEPARATOR + " <Host" + LF.LINE_SEPARATOR 192 + " name=\"localhost\"/>" + LF.LINE_SEPARATOR + "</Engine>" 193 + LF.LINE_SEPARATOR; 194 check(aspectedResult); 195 } 196 197 public void testStoreEmpty() throws Exception { 198 String aspectedResult = "<Engine" + LF.LINE_SEPARATOR 199 + " name=\"Catalina\">" + LF.LINE_SEPARATOR + " <Realm" 200 + LF.LINE_SEPARATOR + " appName=\"Catalina\"/>" 201 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR; 202 check(aspectedResult); 203 } 204 205 protected void check(String aspectedResult) throws Exception { 206 factory.store(pWriter, -2, standardEngine); 207 assertEquals(aspectedResult, writer.toString()); 208 } 209 210 } | Popular Tags |