1 16 package org.apache.catalina.storeconfig; 17 18 import java.io.PrintWriter ; 19 import java.io.StringWriter ; 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.catalina.LifecycleListener; 25 import org.apache.catalina.connector.Connector; 26 27 31 public class ConnectorStoreAppenderTest extends TestCase { 32 StoreRegistry registry; 33 34 StringWriter writer = new StringWriter (); 35 36 PrintWriter pWriter = new PrintWriter (writer); 37 38 Connector connector; 39 40 ConnectorSF factory; 41 42 StoreDescription desc; 43 44 49 protected void setUp() throws Exception { 50 51 super.setUp(); 52 registry = new StoreRegistry(); 53 desc = new StoreDescription(); 54 desc.setTag("Connector"); 55 desc.setTagClass("org.apache.catalina.connector.Connector"); 56 desc.setStandard(false); 57 desc 58 .setStoreFactoryClass("org.apache.catalina.storeconfig.ConnectorSF"); 59 registry.registerDescription(desc); 60 factory = new ConnectorSF(); 61 desc.setStoreFactory(factory); 62 desc.getStoreFactory().setStoreAppender(new ConnectorStoreAppender()); 63 factory.setRegistry(registry); 64 registerDescriptor("Listener", LifecycleListener.class); 65 connector = new Connector("HTTP/1.1"); 66 } 67 68 private StoreDescription registerDescriptor(String tag, Class aClass) { 69 return registerDescriptor(tag, aClass, 70 "org.apache.catalina.storeconfig.StoreFactoryBase", false, 71 false); 72 } 73 74 private StoreDescription registerDescriptor(String tag, Class aClass, 75 String factoryClass, boolean fstandard, boolean fdefault) { 76 return DescriptorHelper.registerDescriptor(desc, registry, aClass 77 .getName(), tag, aClass.getName(), factoryClass, fstandard, 78 fdefault); 79 } 80 81 public void testGetProperties() throws Exception { 82 ConnectorStoreAppender appender = new ConnectorStoreAppender(); 83 List properties = appender.getPropertyKeys(connector); 84 assertTrue(properties.contains("emptySessionPath")); 85 assertFalse(properties.contains("protocol")); 86 assertFalse(properties.contains("protocolHandlerClassName")); 87 connector.setProperty("sslProtocol", "TLS"); 89 properties = appender.getPropertyKeys(connector); 90 assertTrue(properties.contains("protocol")); 91 } 92 93 public void testPrintAttributes() throws Exception { 94 ConnectorStoreAppender appender = new ConnectorStoreAppender(); 95 connector.setProxyPort(80); 96 connector.setProperty("acceptCount", "110"); 97 appender.printAttributes(pWriter, -2, false, connector, desc); 98 99 String aspectedResult = LF.LINE_SEPARATOR + " proxyPort=\"80\"" 100 + LF.LINE_SEPARATOR + " acceptCount=\"110\""; 101 assertEquals(aspectedResult, writer.toString()); 102 } 103 104 } | Popular Tags |