KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

49     protected void setUp() throws Exception JavaDoc {
50
51         super.setUp();
52         registry = new StoreRegistry();
53         desc = new StoreDescription();
54         desc.setTag("Connector");
55         desc.setTagClass("org.apache.catalina.connector.Connector");
56         desc.setStandard(false);
57         desc
58                 .setStoreFactoryClass("org.apache.catalina.storeconfig.ConnectorSF");
59         registry.registerDescription(desc);
60         factory = new ConnectorSF();
61         desc.setStoreFactory(factory);
62         desc.getStoreFactory().setStoreAppender(new ConnectorStoreAppender());
63         factory.setRegistry(registry);
64         registerDescriptor("Listener", LifecycleListener.class);
65         connector = new Connector("HTTP/1.1");
66     }
67
68     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass) {
69         return registerDescriptor(tag, aClass,
70                 "org.apache.catalina.storeconfig.StoreFactoryBase", false,
71                 false);
72     }
73
74     private StoreDescription registerDescriptor(String JavaDoc tag, Class JavaDoc aClass,
75             String JavaDoc factoryClass, boolean fstandard, boolean fdefault) {
76         return DescriptorHelper.registerDescriptor(desc, registry, aClass
77                 .getName(), tag, aClass.getName(), factoryClass, fstandard,
78                 fdefault);
79     }
80
81     public void testGetProperties() throws Exception JavaDoc {
82         ConnectorStoreAppender appender = new ConnectorStoreAppender();
83         List JavaDoc properties = appender.getPropertyKeys(connector);
84         assertTrue(properties.contains("emptySessionPath"));
85         assertFalse(properties.contains("protocol"));
86         assertFalse(properties.contains("protocolHandlerClassName"));
87         // HTTP/1.1 SSL Protocol Test
88
connector.setProperty("sslProtocol", "TLS");
89         properties = appender.getPropertyKeys(connector);
90         assertTrue(properties.contains("protocol"));
91     }
92
93     public void testPrintAttributes() throws Exception JavaDoc {
94         ConnectorStoreAppender appender = new ConnectorStoreAppender();
95         connector.setProxyPort(80);
96         connector.setProperty("acceptCount", "110");
97         appender.printAttributes(pWriter, -2, false, connector, desc);
98
99         String JavaDoc aspectedResult = LF.LINE_SEPARATOR + " proxyPort=\"80\""
100                 + LF.LINE_SEPARATOR + " acceptCount=\"110\"";
101         assertEquals(aspectedResult, writer.toString());
102     }
103
104 }
Popular Tags