KickJava   Java API By Example, From Geeks To Geeks.

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


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.Valve;
25 import org.apache.catalina.core.StandardEngine;
26 import org.apache.catalina.core.StandardHost;
27 import org.apache.catalina.realm.JAASRealm;
28 import org.apache.catalina.storeconfig.StandardEngineSF;
29 import org.apache.catalina.storeconfig.StoreDescription;
30 import org.apache.catalina.storeconfig.StoreRegistry;
31
32 /**
33  * @author Peter Rossbach
34  *
35  */

36 public class StandardEngineSFTest extends TestCase {
37     StoreRegistry registry;
38
39     StringWriter JavaDoc writer = new StringWriter JavaDoc();
40
41     PrintWriter JavaDoc pWriter = new PrintWriter JavaDoc(writer);
42
43     StandardEngine standardEngine;
44
45     StandardEngineSF factory;
46
47     StoreDescription desc;
48
49     /*
50      * create registery and register Engine and direct subelement descriptors
51      *
52      * @see junit.framework.TestCase#setUp()
53      */

54     protected void setUp() throws Exception JavaDoc {
55
56         super.setUp();
57         registry = new StoreRegistry();
58         desc = new StoreDescription();
59         desc.setTag("Engine");
60         desc.setTagClass("org.apache.catalina.core.StandardEngine");
61         desc.setStandard(true);
62         desc
63                 .setStoreFactoryClass("org.apache.catalina.storeconfig.StandardEngineSF");
64         desc.addTransientAttribute("domain");
65         registry.registerDescription(desc);
66         factory = new StandardEngineSF();
67         desc.setStoreFactory(factory);
68         factory.setRegistry(registry);
69         StoreDescription listenerdesc = registerDescriptor("Listener",
70                 LifecycleListener.class);
71
72         String JavaDoc listenerskippables[] = {
73                 "org.apache.catalina.core.NamingContextListener",
74                 "org.apache.catalina.startup.ContextConfig",
75                 "org.apache.catalina.startup.EngineConfig",
76                 "org.apache.catalina.startup.HostConfig", };
77         for (int i = 0; i < listenerskippables.length; i++)
78             listenerdesc.addTransientChild(listenerskippables[i]);
79
80         StoreDescription realmdesc = registerDescriptor("Realm",
81                 JAASRealm.class,
82                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
83         StoreDescription hostdesc = registerDescriptor("Host",
84                 StandardHost.class,
85                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
86         hostdesc.addTransientAttribute("domain");
87         StoreDescription valvedesc = registerDescriptor("Valve", Valve.class,
88                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
89                 false);
90
91         String JavaDoc skippables[] = {
92                 "org.apache.catalina.authenticator.BasicAuthenticator",
93                 "org.apache.catalina.authenticator.DigestAuthenticator",
94                 "org.apache.catalina.authenticator.FormAuthenticator",
95                 "org.apache.catalina.authenticator.NonLoginAuthenticator",
96                 "org.apache.catalina.authenticator.SSLAuthenticator",
97                 "org.apache.catalina.core.StandardContextValve",
98                 "org.apache.catalina.core.StandardEngineValve",
99                 "org.apache.catalina.core.StandardHostValve",
100                 "org.apache.catalina.valves.CertificatesValve",
101                 "org.apache.catalina.valves.ErrorReportValve",
102                 "org.apache.catalina.valves.RequestListenerValve", };
103         for (int i = 0; i < skippables.length; i++)
104             valvedesc.addTransientChild(skippables[i]);
105
106         standardEngine = new StandardEngine();
107         standardEngine.setName("Catalina");
108
109     }
110
111     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass) {
112         return registerDescriptor(tag, aClass,
113                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
114                 false);
115     }
116
117     /**
118      *
119      */

120     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass,
121             String JavaDoc factoryClass, boolean fstandard, boolean fdefault) {
122         return DescriptorHelper.registerDescriptor(desc, registry, aClass
123                 .getName(), tag, aClass.getName(), factoryClass, fstandard,
124                 fdefault);
125     }
126
127     public void testStore() throws Exception JavaDoc {
128         standardEngine
129                 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener());
130         StandardHost host = new StandardHost();
131         host.setName("localhost");
132         standardEngine.addChild(host);
133         String JavaDoc aspectedResult = "<Engine"
134                 + LF.LINE_SEPARATOR
135                 + " name=\"Catalina\">"
136                 + LF.LINE_SEPARATOR
137                 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>"
138                 + LF.LINE_SEPARATOR + " <Realm" + LF.LINE_SEPARATOR
139                 + " appName=\"Catalina\"/>" + LF.LINE_SEPARATOR + " <Host"
140                 + LF.LINE_SEPARATOR + " name=\"localhost\"/>"
141                 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR;
142
143         check(aspectedResult);
144     }
145
146     public void testElements() throws Exception JavaDoc {
147         standardEngine.setName("Catalina");
148         standardEngine
149                 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener());
150         standardEngine
151                 .addLifecycleListener(new org.apache.catalina.startup.EngineConfig());
152         StandardHost host = new StandardHost();
153         host.setName("localhost");
154         standardEngine.addChild(host);
155         String JavaDoc aspectedResult = "<Engine"
156                 + LF.LINE_SEPARATOR
157                 + " name=\"Catalina\">"
158                 + LF.LINE_SEPARATOR
159                 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>"
160                 + LF.LINE_SEPARATOR + " <Realm" + LF.LINE_SEPARATOR
161                 + " appName=\"Catalina\"/>" + LF.LINE_SEPARATOR + " <Host"
162                 + LF.LINE_SEPARATOR + " name=\"localhost\"/>"
163                 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR;
164         check(aspectedResult);
165     }
166
167     public void testValve() throws Exception JavaDoc {
168         standardEngine.setName("Catalina");
169         standardEngine
170                 .addLifecycleListener(new org.apache.catalina.storeconfig.InfoLifecycleListener());
171         standardEngine
172                 .addLifecycleListener(new org.apache.catalina.startup.EngineConfig());
173         StandardHost host = new StandardHost();
174         host.setName("localhost");
175         standardEngine.addChild(host);
176         standardEngine
177                 .addValve(new org.apache.catalina.valves.ErrorReportValve());
178         standardEngine
179                 .addValve(new org.apache.catalina.valves.RequestDumperValve());
180         String JavaDoc aspectedResult = "<Engine"
181                 + LF.LINE_SEPARATOR
182                 + " name=\"Catalina\">"
183                 + LF.LINE_SEPARATOR
184                 + " <Listener className=\"org.apache.catalina.storeconfig.InfoLifecycleListener\"/>"
185                 + LF.LINE_SEPARATOR
186                 + " <Realm"
187                 + LF.LINE_SEPARATOR
188                 + " appName=\"Catalina\"/>"
189                 + LF.LINE_SEPARATOR
190                 + " <Valve className=\"org.apache.catalina.valves.RequestDumperValve\"/>"
191                 + LF.LINE_SEPARATOR + " <Host" + LF.LINE_SEPARATOR
192                 + " name=\"localhost\"/>" + LF.LINE_SEPARATOR + "</Engine>"
193                 + LF.LINE_SEPARATOR;
194         check(aspectedResult);
195     }
196
197     public void testStoreEmpty() throws Exception JavaDoc {
198         String JavaDoc aspectedResult = "<Engine" + LF.LINE_SEPARATOR
199                 + " name=\"Catalina\">" + LF.LINE_SEPARATOR + " <Realm"
200                 + LF.LINE_SEPARATOR + " appName=\"Catalina\"/>"
201                 + LF.LINE_SEPARATOR + "</Engine>" + LF.LINE_SEPARATOR;
202         check(aspectedResult);
203     }
204
205     protected void check(String JavaDoc aspectedResult) throws Exception JavaDoc {
206         factory.store(pWriter, -2, standardEngine);
207         assertEquals(aspectedResult, writer.toString());
208     }
209
210 }
Popular Tags