KickJava   Java API By Example, From Geeks To Geeks.

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


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.PrintWriter JavaDoc;
19 import java.io.StringWriter JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.apache.catalina.LifecycleListener;
24 import org.apache.catalina.connector.Connector;
25
26 /**
27  * @author Peter Rossbach
28  *
29  */

30 public class ConnectorSFTest extends TestCase {
31     StoreRegistry registry;
32
33     StringWriter JavaDoc writer = new StringWriter JavaDoc();
34
35     PrintWriter JavaDoc pWriter = new PrintWriter JavaDoc(writer);
36
37     Connector connector;
38
39     ConnectorSF factory;
40
41     StoreDescription desc;
42
43     /*
44      * (non-Javadoc)
45      *
46      * @see junit.framework.TestCase#setUp()
47      */

48     protected void setUp() throws Exception JavaDoc {
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 JavaDoc tag, Class JavaDoc aClass) {
70         return registerDescriptor(tag, aClass,
71                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
72                 false);
73     }
74
75     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass,
76             String JavaDoc 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 JavaDoc {
83         connector
84                 .addLifecycleListener(new org.apache.catalina.mbeans.ServerLifecycleListener());
85         String JavaDoc 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 JavaDoc {
93         connector.setProperty("acceptCount", "10");
94         connector.setProperty("maxSpareThreads", "74");
95         String JavaDoc 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 JavaDoc {
103         connector.setProtocol("AJP/1.3");
104         String JavaDoc 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 JavaDoc {
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 JavaDoc 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 JavaDoc {
138         String JavaDoc aspectedResult = "<Connector>" + LF.LINE_SEPARATOR
139                 + "</Connector>" + LF.LINE_SEPARATOR;
140         check(aspectedResult);
141     }
142
143     protected void check(String JavaDoc aspectedResult) throws Exception JavaDoc {
144         factory.store(pWriter, -2, connector);
145         assertEquals(aspectedResult, writer.toString());
146     }
147
148 }
Popular Tags