1 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 ; 32 import java.util.Iterator ; 33 34 public class BoundedPoolTest extends TestCase { 35 36 public BoundedPoolTest(String 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 c = pool.values(); 50 for (Iterator itr=c.iterator(); itr.hasNext();) { 51 Object 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 val4 = pool.get("key4"); 67 assertTrue(val4.equals("val4")); 68 System.out.println("Get Test Passed"); 69 70 Object 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 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 args[]) { 91 junit.textui.TestRunner.run(BoundedPoolTest.class); 92 } 93 } 94 | Popular Tags |