1 16 package org.apache.catalina.storeconfig; 17 18 import java.io.IOException ; 19 import java.io.PrintWriter ; 20 import java.io.StringReader ; 21 import java.io.StringWriter ; 22 23 import junit.framework.TestCase; 24 25 import org.apache.catalina.cluster.tcp.ReplicationTransmitter; 26 import org.apache.catalina.core.StandardServer; 27 import org.apache.catalina.deploy.ContextResource; 28 import org.apache.catalina.startup.SetAllPropertiesRule; 29 import org.apache.tomcat.util.digester.Digester; 30 import org.xml.sax.SAXException ; 31 32 35 public class StoreAppenderTest extends TestCase { 36 37 40 protected Digester createDigester() { 41 Digester digester = new Digester(); 42 digester.setValidating(false); 43 digester.addObjectCreate("Resource", 44 "org.apache.catalina.deploy.ContextResource"); 45 digester.addRule("Resource", new SetAllPropertiesRule()); 46 return digester; 47 } 48 49 public void testNormalResource() throws IOException , SAXException { 50 Digester digester = createDigester(); 51 String example = "<Resource auth=\"Container\" name=\"jdbc/Emp\" type=\"javax.sql.DataSource\"/>"; 52 StringReader reader = new StringReader (example); 53 ContextResource resource = (ContextResource) digester.parse(reader); 54 assertNotNull(resource); 55 assertEquals("javax.sql.DataSource", resource.getType()); 56 } 57 58 public void testPropertyResouce() throws IOException , SAXException { 59 Digester digester = createDigester(); 60 String example = "<Resource auth=\"Container\" name=\"mail/MailSession\" type=\"javax.mail.session\" mail.host=\"localhost\"/>"; 61 StringReader reader = new StringReader (example); 62 ContextResource resource = (ContextResource) digester.parse(reader); 63 assertNotNull(resource); 64 assertEquals("localhost", resource.getProperty("mail.host")); 65 } 66 67 public void testStoreStandard() throws Exception { 68 StoreDescription desc = new StoreDescription(); 69 desc.setStandard(true); 70 PrintWriter writer = new PrintWriter (new StringWriter ()); 71 StandardServer bean = new StandardServer(); 72 new StoreAppender().printAttributes(writer, 0, true, bean, desc); 73 } 74 75 public void testStoreReplicationTransmitter() throws Exception { 76 StoreDescription desc = new StoreDescription(); 77 desc.setStandard(true); 78 StringWriter swriter = new StringWriter (); 79 PrintWriter writer = new PrintWriter (swriter); 80 ReplicationTransmitter bean = new ReplicationTransmitter(); 81 bean.setReplicationMode("asynchronous"); 82 bean.setProperty("keepAliveTimeout","80000"); 83 new ReplicationTransmitterStoreAppender().printAttributes(writer, 0, true, bean, desc); 84 String aspectedResult =LF.LINE_SEPARATOR 85 + " replicationMode=\"asynchronous\"" + LF.LINE_SEPARATOR 86 + " keepAliveTimeout=\"80000\"" ; 87 assertEquals(aspectedResult, swriter.getBuffer().toString()); 88 89 } 90 91 } | Popular Tags |