KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > pool > BoundedPoolTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.pool;
24
25 import com.sun.enterprise.admin.wsmgmt.pool.impl.BoundedPool;
26
27 import junit.framework.TestCase;
28 import junit.framework.TestResult;
29 import junit.framework.TestSuite;
30
31 import java.util.Collection JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 public class BoundedPoolTest extends TestCase {
35    
36     public BoundedPoolTest(String JavaDoc name) {
37         super(name);
38     }
39
40     public void testPool() {
41         try {
42             pool.resize(2);
43             pool.put("key0", "val0");
44             pool.put("key1", "val1");
45             pool.put("key2", "val2");
46             assertTrue(pool.size() == 2);
47             System.out.println("Bounded Test Passed");
48
49             Collection JavaDoc c = pool.values();
50             for (Iterator JavaDoc itr=c.iterator(); itr.hasNext();) {
51                 Object JavaDoc val = itr.next();
52                 System.out.println(val);
53             }
54             pool.resize(10);
55             pool.put("key3", "val3");
56             pool.put("key4", "val4");
57             assertTrue(pool.getMaxSize() == 10);
58             System.out.println("Resize Test Passed");
59
60             boolean keyTF = pool.containsKey("key4");
61             assertTrue(keyTF == true);
62             boolean valTF = pool.containsValue("val4");
63             assertTrue(valTF == true);
64             System.out.println("Contains Test Passed");
65
66             Object JavaDoc val4 = pool.get("key4");
67             assertTrue(val4.equals("val4"));
68             System.out.println("Get Test Passed");
69
70             Object JavaDoc val2 = pool.remove("key2");
71             assertTrue(val2 != null);
72             assertTrue(val2.equals("val2"));
73             System.out.println("Remove Test Passed");
74
75             pool.resize(1);
76
77             pool.clear();
78             assertTrue(pool.size() == 0);
79             System.out.println("Clear Test Passed");
80         } catch (Exception JavaDoc e) {
81             e.printStackTrace();
82         }
83     }
84
85     protected void setUp() {
86         pool = new BoundedPool("Test");
87     }
88     private BoundedPool pool = null;
89
90     public static void main(String JavaDoc args[]) {
91         junit.textui.TestRunner.run(BoundedPoolTest.class);
92     }
93 }
94
Popular Tags