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.connector.Connector; 25 import org.apache.catalina.core.StandardEngine; 26 import org.apache.catalina.core.StandardService; 27 28 32 public class StandardServiceSFTest extends TestCase { 33 StoreRegistry registry; 34 35 StringWriter writer = new StringWriter (); 36 37 PrintWriter pWriter = new PrintWriter (writer); 38 39 StandardService standardService = new StandardService(); 40 41 StandardServiceSF factory; 42 43 StoreDescription desc; 44 45 51 protected void setUp() throws Exception { 52 53 super.setUp(); 54 registry = new StoreRegistry(); 55 desc = new StoreDescription(); 56 desc.setTag("Service"); 57 desc.setTagClass("org.apache.catalina.core.StandardService"); 58 desc.setStandard(true); 59 desc.setStoreFactoryClass("org.apache.catalina.core.StandardServiceSF"); 60 registry.registerDescription(desc); 61 factory = new StandardServiceSF(); 62 desc.setStoreFactory(factory); 63 factory.setRegistry(registry); 64 registerDescriptor("Listener", LifecycleListener.class); 65 registerDescriptor("Engine", StandardEngine.class, 66 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false); 67 StoreDescription cdesc = registerDescriptor("Connector", 68 Connector.class, "org.apache.catalina.storeconfig.ConnectorSF", 69 true, true); 70 cdesc.getStoreFactory().setStoreAppender(new ConnectorStoreAppender()); 71 StoreDescription pdesc = DescriptorHelper 72 .registerDescriptor(null, registry, Connector.class.getName() 73 + ".[ProtocolHandler]", "ProtocolHandler", 74 Connector.class.getName(), 75 "org.apache.catalina.storeconfig.StoreFactoryBase", 76 true, false); 77 pdesc.addTransientAttribute("keystore"); 78 pdesc.addTransientAttribute("keypass"); 79 pdesc.addTransientAttribute("keytype"); 80 pdesc.addTransientAttribute("randomfile"); 81 pdesc.addTransientAttribute("protocols"); 82 pdesc.addTransientAttribute("clientauth"); 83 pdesc.addTransientAttribute("protocol"); 84 pdesc.addTransientAttribute("port"); 85 pdesc.addTransientAttribute("secure"); 86 87 } 88 89 private StoreDescription registerDescriptor(String tag, Class aClass) { 90 return registerDescriptor(tag, aClass, 91 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 92 false); 93 } 94 95 private StoreDescription registerDescriptor(String tag, Class aClass, 96 String factoryClass, boolean fstandard, boolean fdefault) { 97 return DescriptorHelper.registerDescriptor(desc, registry, aClass 98 .getName(), tag, aClass.getName(), factoryClass, fstandard, 99 fdefault); 100 } 101 102 public void testStoreAJP() throws Exception { 103 standardService 104 .addLifecycleListener(new org.apache.catalina.mbeans.ServerLifecycleListener()); 105 Connector connector = new Connector(); 106 standardService.addConnector(connector); 107 standardService.setContainer(new StandardEngine()); 108 String aspectedResult = "<Service>" 109 + LF.LINE_SEPARATOR 110 + " <Listener className=\"org.apache.catalina.mbeans.ServerLifecycleListener\"/>" 111 + LF.LINE_SEPARATOR + " <Connector/>" + LF.LINE_SEPARATOR 112 + " <Engine/>" + LF.LINE_SEPARATOR + "</Service>" 113 + LF.LINE_SEPARATOR; 114 check(aspectedResult); 115 } 116 117 public void testStoreEmpty() throws Exception { 118 String aspectedResult = "<Service>" + LF.LINE_SEPARATOR + "</Service>" 119 + LF.LINE_SEPARATOR; 120 check(aspectedResult); 121 } 122 123 protected void check(String aspectedResult) throws Exception { 124 factory.store(pWriter, -2, standardService); 125 assertEquals(aspectedResult, writer.toString()); 126 } 127 128 } | Popular Tags |