KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > param > SessionParamPoolTest


1 package com.tonbeller.wcf.param;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import junit.framework.TestCase;
8
9 public class SessionParamPoolTest extends TestCase {
10
11   SessionParam makeParam(String JavaDoc name, String JavaDoc value) {
12     SessionParam p = new SessionParam();
13     p.setName(name);
14     p.setSqlValue(value);
15     return p;
16   }
17   
18   public void testPool() {
19     SessionParamPool pool = SessionParamPool.instance();
20     
21     SessionParam p1 = makeParam("p1", null);
22     pool.setParam(p1);
23     assertEquals(p1, pool.getParam("p1"));
24   }
25
26   public void testPushPop() throws Exception JavaDoc {
27     SessionParamPool pool = SessionParamPool.instance();
28     
29     SessionParam p1 = makeParam("p1", "p1.value");
30     pool.setParam(p1);
31     SessionParam p2 = makeParam("p2", "p2.value");
32     pool.setParam(p2);
33     
34     assertEquals(p1, pool.getParam("p1"));
35     assertEquals(p2, pool.getParam("p2"));
36     assertNull(pool.getParam("p3"));
37
38     List JavaDoc list = new ArrayList JavaDoc();
39     SessionParam q2 = makeParam("p2", "p2.new");
40     list.add(q2);
41     SessionParam q3 = makeParam("p3", "p3.new");
42     list.add(q3);
43
44     Map JavaDoc state = pool.pushParams(list);
45     
46     assertEquals(p1, pool.getParam("p1"));
47     assertEquals(q2, pool.getParam("p2"));
48     assertEquals(q3, pool.getParam("p3"));
49
50     pool.popParams(state);
51     
52     assertEquals(p1, pool.getParam("p1"));
53     assertEquals(p2, pool.getParam("p2"));
54     assertNull(pool.getParam("p3"));
55   }
56   public void testPushPopDuplicate() throws Exception JavaDoc {
57     SessionParamPool pool = SessionParamPool.instance();
58     
59     SessionParam p1 = makeParam("p1", "p1.value");
60     pool.setParam(p1);
61     assertEquals(p1, pool.getParam("p1"));
62     
63     List JavaDoc list = new ArrayList JavaDoc();
64     SessionParam q1 = makeParam("p1", "p1.new");
65     list.add(q1);
66     SessionParam q2 = makeParam("p1", "p1.duplicate");
67     list.add(q2);
68
69     Map JavaDoc state = pool.pushParams(list);
70     assertEquals(q2, pool.getParam("p1"));
71     pool.popParams(state);
72     assertEquals(p1, pool.getParam("p1"));
73   }
74 }
75
Popular Tags