KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.catalina.core.StandardEngine;
26 import org.apache.catalina.core.StandardService;
27
28 /**
29  * @author Peter Rossbach
30  *
31  */

32 public class StandardServiceSFTest extends TestCase {
33     StoreRegistry registry;
34
35     StringWriter JavaDoc writer = new StringWriter JavaDoc();
36
37     PrintWriter JavaDoc pWriter = new PrintWriter JavaDoc(writer);
38
39     StandardService standardService = new StandardService();
40
41     StandardServiceSF factory;
42
43     StoreDescription desc;
44
45     /*
46      * create registry and register Service and all direct subelement
47      * descriptors
48      *
49      * @see junit.framework.TestCase#setUp()
50      */

51     protected void setUp() throws Exception JavaDoc {
52
53         super.setUp();
54         registry = new StoreRegistry();
55         desc = new StoreDescription();
56         desc.setTag("Service");
57         desc.setTagClass("org.apache.catalina.core.StandardService");
58         desc.setStandard(true);
59         desc.setStoreFactoryClass("org.apache.catalina.core.StandardServiceSF");
60         registry.registerDescription(desc);
61         factory = new StandardServiceSF();
62         desc.setStoreFactory(factory);
63         factory.setRegistry(registry);
64         registerDescriptor("Listener", LifecycleListener.class);
65         registerDescriptor("Engine", StandardEngine.class,
66                 "org.apache.catalina.storeconfig.StoreFactoryBase", true, false);
67         StoreDescription cdesc = registerDescriptor("Connector",
68                 Connector.class, "org.apache.catalina.storeconfig.ConnectorSF",
69                 true, true);
70         cdesc.getStoreFactory().setStoreAppender(new ConnectorStoreAppender());
71         StoreDescription pdesc = DescriptorHelper
72                 .registerDescriptor(null, registry, Connector.class.getName()
73                         + ".[ProtocolHandler]", "ProtocolHandler",
74                         Connector.class.getName(),
75                         "org.apache.catalina.storeconfig.StoreFactoryBase",
76                         true, false);
77         pdesc.addTransientAttribute("keystore");
78         pdesc.addTransientAttribute("keypass");
79         pdesc.addTransientAttribute("keytype");
80         pdesc.addTransientAttribute("randomfile");
81         pdesc.addTransientAttribute("protocols");
82         pdesc.addTransientAttribute("clientauth");
83         pdesc.addTransientAttribute("protocol");
84         pdesc.addTransientAttribute("port");
85         pdesc.addTransientAttribute("secure");
86
87     }
88
89     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass) {
90         return registerDescriptor(tag, aClass,
91                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
92                 false);
93     }
94
95     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass,
96             String JavaDoc factoryClass, boolean fstandard, boolean fdefault) {
97         return DescriptorHelper.registerDescriptor(desc, registry, aClass
98                 .getName(), tag, aClass.getName(), factoryClass, fstandard,
99                 fdefault);
100     }
101
102     public void testStoreAJP() throws Exception JavaDoc {
103         standardService
104                 .addLifecycleListener(new org.apache.catalina.mbeans.ServerLifecycleListener());
105         Connector connector = new Connector();
106         standardService.addConnector(connector);
107         standardService.setContainer(new StandardEngine());
108         String JavaDoc aspectedResult = "<Service>"
109                 + LF.LINE_SEPARATOR
110                 + " <Listener className=\"org.apache.catalina.mbeans.ServerLifecycleListener\"/>"
111                 + LF.LINE_SEPARATOR + " <Connector/>" + LF.LINE_SEPARATOR
112                 + " <Engine/>" + LF.LINE_SEPARATOR + "</Service>"
113                 + LF.LINE_SEPARATOR;
114         check(aspectedResult);
115     }
116
117     public void testStoreEmpty() throws Exception JavaDoc {
118         String JavaDoc aspectedResult = "<Service>" + LF.LINE_SEPARATOR + "</Service>"
119                 + LF.LINE_SEPARATOR;
120         check(aspectedResult);
121     }
122
123     protected void check(String JavaDoc aspectedResult) throws Exception JavaDoc {
124         factory.store(pWriter, -2, standardService);
125         assertEquals(aspectedResult, writer.toString());
126     }
127
128 }
Popular Tags