KickJava   Java API By Example, From Geeks To Geeks.

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


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.Manager;
24 import org.apache.catalina.session.StandardManager;
25
26 /**
27  * @author Peter Rossbach
28  *
29  */

30 public class ManagerSFTest extends TestCase {
31     StoreRegistry registry;
32
33     StringWriter JavaDoc writer = new StringWriter JavaDoc();
34
35     PrintWriter JavaDoc pWriter = new PrintWriter JavaDoc(writer);
36
37     StandardManager manager;
38
39     ManagerSF factory;
40
41     StoreDescription desc;
42
43     /*
44      * create registery and register Manager descriptor
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 = DescriptorHelper.registerDescriptor(null, registry,
53                 Manager.class.getName(), "Manager",
54                 Manager.class.getName(),
55                 "org.apache.catalina.storeconfig.ManagerSF", false, false);
56         desc.addTransientAttribute("entropy");
57         desc.addTransientAttribute("distributable");
58         factory = (ManagerSF) desc.getStoreFactory();
59         manager = new StandardManager();
60
61     }
62
63     public void testFindStandardManager() {
64         StoreDescription managerdesc = registry.findDescription(manager.getClass());
65         assertEquals(desc,managerdesc);
66     }
67     
68     public void testManagerNonStandardStore() throws Exception JavaDoc {
69         assertTrue(factory.isDefaultManager(manager));
70         manager.setMaxActiveSessions(100);
71         assertFalse(factory.isDefaultManager(manager));
72         String JavaDoc aspectedResult = "<Manager className=\"org.apache.catalina.session.StandardManager\""
73                 + LF.LINE_SEPARATOR
74                 + " maxActiveSessions=\"100\"/>"
75                 + LF.LINE_SEPARATOR;
76         check(aspectedResult);
77     }
78
79     public void testStoreEmpty() throws Exception JavaDoc {
80         assertTrue(factory.isDefaultManager(manager));
81         String JavaDoc aspectedResult = "";
82         check(aspectedResult);
83     }
84
85     protected void check(String JavaDoc aspectedResult) throws Exception JavaDoc {
86         factory.store(pWriter, -2, manager);
87         assertEquals(aspectedResult, writer.toString());
88     }
89
90 }
Popular Tags