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 26 30 public class ConnectorSFTest extends TestCase { 31 StoreRegistry registry; 32 33 StringWriter writer = new StringWriter (); 34 35 PrintWriter pWriter = new PrintWriter (writer); 36 37 Connector connector; 38 39 ConnectorSF factory; 40 41 StoreDescription desc; 42 43 48 protected void setUp() throws Exception { 49 50 super.setUp(); 51 registry = new StoreRegistry(); 52 desc = new StoreDescription(); 53 desc.setTag("Connector"); 54 desc.setTagClass("org.apache.catalina.connector.Connector"); 55 desc.setStandard(false); 56 desc 57 .setStoreFactoryClass("org.apache.catalina.storeconfig.ConnectorSF"); 58 registry.registerDescription(desc); 59 factory = new ConnectorSF(); 60 desc.setStoreFactory(factory); 61 desc.getStoreFactory().setStoreAppender(new ConnectorStoreAppender()); 62 factory.setRegistry(registry); 63 desc.addTransientAttribute("minProcessor"); 64 desc.addTransientAttribute("maxProcessor"); 65 registerDescriptor("Listener", LifecycleListener.class); 66 connector = new Connector("HTTP/1.1"); 67 } 68 69 private StoreDescription registerDescriptor(String tag, Class aClass) { 70 return registerDescriptor(tag, aClass, 71 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 72 false); 73 } 74 75 private StoreDescription registerDescriptor(String tag, Class aClass, 76 String factoryClass, boolean fstandard, boolean fdefault) { 77 return DescriptorHelper.registerDescriptor(desc, registry, aClass 78 .getName(), tag, aClass.getName(), factoryClass, fstandard, 79 fdefault); 80 } 81 82 public void testListener() throws Exception { 83 connector 84 .addLifecycleListener(new org.apache.catalina.mbeans.ServerLifecycleListener()); 85 String aspectedResult = "<Connector>" 86 + LF.LINE_SEPARATOR 87 + " <Listener className=\"org.apache.catalina.mbeans.ServerLifecycleListener\"/>" 88 + LF.LINE_SEPARATOR + "</Connector>" + LF.LINE_SEPARATOR; 89 check(aspectedResult); 90 } 91 92 public void testWithProtocolHandler() throws Exception { 93 connector.setProperty("acceptCount", "10"); 94 connector.setProperty("maxSpareThreads", "74"); 95 String aspectedResult = "<Connector" + LF.LINE_SEPARATOR 96 + " maxSpareThreads=\"74\"" + LF.LINE_SEPARATOR 97 + " acceptCount=\"10\">" + LF.LINE_SEPARATOR 98 + "</Connector>" + LF.LINE_SEPARATOR; 99 check(aspectedResult); 100 } 101 102 public void testStoreAJP() throws Exception { 103 connector.setProtocol("AJP/1.3"); 104 String aspectedResult = "<Connector" + LF.LINE_SEPARATOR 105 + " protocol=\"AJP/1.3\">" + LF.LINE_SEPARATOR 106 + "</Connector>" + LF.LINE_SEPARATOR; 107 check(aspectedResult); 108 } 109 110 public void testSSL() throws Exception { 111 connector.setPort(8443); 112 connector.setProperty("minSpareThreads", "30"); 113 connector.setProperty("maxSpareThreads", "175"); 114 connector.setEnableLookups(false); 115 connector.setProperty("disableUploadTimeout", "true"); 116 connector.setSecure(true); 117 connector.setProperty("backlog", "100"); 118 connector.setScheme("https"); 119 connector.setProperty("clientAuth", "false"); 120 connector.setProperty("sslProtocol", "TLS"); 121 connector.setProperty("keystoreFile", "conf/catalina.keystore"); 122 connector.setProperty("keystorePass", "changeit"); 123 124 String aspectedResult = "<Connector" + LF.LINE_SEPARATOR 125 + " port=\"8443\"" + LF.LINE_SEPARATOR 126 + " scheme=\"https\"" + LF.LINE_SEPARATOR 127 + " secure=\"true\"" + LF.LINE_SEPARATOR 128 + " minSpareThreads=\"30\"" + LF.LINE_SEPARATOR 129 + " clientAuth=\"false\"" + LF.LINE_SEPARATOR 130 + " keystorePass=\"changeit\"" + LF.LINE_SEPARATOR 131 + " keystoreFile=\"conf/catalina.keystore\"" 132 + LF.LINE_SEPARATOR + " maxSpareThreads=\"175\">" 133 + LF.LINE_SEPARATOR + "</Connector>" + LF.LINE_SEPARATOR; 134 check(aspectedResult); 135 } 136 137 public void testStoreEmpty() throws Exception { 138 String aspectedResult = "<Connector>" + LF.LINE_SEPARATOR 139 + "</Connector>" + LF.LINE_SEPARATOR; 140 check(aspectedResult); 141 } 142 143 protected void check(String aspectedResult) throws Exception { 144 factory.store(pWriter, -2, connector); 145 assertEquals(aspectedResult, writer.toString()); 146 } 147 148 } | Popular Tags |