KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > ContextImplTest


1 package org.sapia.soto.state;
2
3 import junit.framework.TestCase;
4
5
6 /**
7  * @author Yanick Duchesne
8  * <dl>
9  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
10  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
11  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
12  * </dl>
13  */

14 public class ContextImplTest extends TestCase {
15   /**
16    *
17    */

18   public ContextImplTest(String JavaDoc name) {
19     super(name);
20   }
21
22   public void testPutGet() {
23     ContextImpl ctx = new ContextImpl();
24     Scope sc = new MapScope();
25     sc.putVal("key", "value");
26     ctx.addScope("request", sc);
27     super.assertEquals("value", ctx.get("key"));
28     super.assertEquals("value", ctx.get("key", "request"));
29   }
30
31   public void testPush() {
32     ContextImpl ctx = new ContextImpl();
33     ctx.push("test");
34     super.assertEquals("test", ctx.currentObject());
35     super.assertEquals("test", ctx.get("test", "."));
36   }
37
38   public void testPutScopedGet() {
39     ContextImpl ctx = new ContextImpl();
40     Scope req = new MapScope();
41     Scope ses = new MapScope();
42     req.putVal("key", "value");
43     ctx.addScope("request", req);
44     ctx.addScope("session", ses);
45     super.assertTrue(ctx.get("key", new String JavaDoc[] { "session" }) == null);
46     super.assertEquals("value", ctx.get("key", new String JavaDoc[] { "request" }));
47   }
48
49   public void testPushPop() {
50     ContextImpl ctx = new ContextImpl();
51     ctx.push("foo");
52     super.assertEquals("foo", ctx.pop());
53   }
54
55   public void testCurrentObject() throws Exception JavaDoc {
56     ContextImpl ctx = new ContextImpl();
57     ctx.push("foo");
58     super.assertEquals("foo", ctx.currentObject());
59     ctx.pop();
60
61     try {
62       ctx.currentObject();
63       throw new Exception JavaDoc("Object should not be on stack");
64     } catch (IllegalStateException JavaDoc e) {
65       // ok
66
}
67   }
68 }
69
Popular Tags