KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > storeconfig > StoreAppenderTest


1 /*
2  * Copyright 1999-2001,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.catalina.storeconfig;
17
18 import java.io.IOException JavaDoc;
19 import java.io.PrintWriter JavaDoc;
20 import java.io.StringReader JavaDoc;
21 import java.io.StringWriter JavaDoc;
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 JavaDoc;
31
32 /**
33  * @author Peter Rossbach
34  */

35 public class StoreAppenderTest extends TestCase {
36
37     /**
38      * Create the digester which will be used to parse context config files.
39      */

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 JavaDoc, SAXException JavaDoc {
50         Digester digester = createDigester();
51         String JavaDoc example = "<Resource auth=\"Container\" name=\"jdbc/Emp\" type=\"javax.sql.DataSource\"/>";
52         StringReader JavaDoc reader = new StringReader JavaDoc(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 JavaDoc, SAXException JavaDoc {
59         Digester digester = createDigester();
60         String JavaDoc example = "<Resource auth=\"Container\" name=\"mail/MailSession\" type=\"javax.mail.session\" mail.host=\"localhost\"/>";
61         StringReader JavaDoc reader = new StringReader JavaDoc(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 JavaDoc {
68         StoreDescription desc = new StoreDescription();
69         desc.setStandard(true);
70         PrintWriter JavaDoc writer = new PrintWriter JavaDoc(new StringWriter JavaDoc());
71         StandardServer bean = new StandardServer();
72         new StoreAppender().printAttributes(writer, 0, true, bean, desc);
73     }
74
75     public void testStoreReplicationTransmitter() throws Exception JavaDoc {
76         StoreDescription desc = new StoreDescription();
77         desc.setStandard(true);
78         StringWriter JavaDoc swriter = new StringWriter JavaDoc();
79         PrintWriter JavaDoc writer = new PrintWriter JavaDoc(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 JavaDoc 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