1 package org.sapia.soto.state; 2 3 import junit.framework.TestCase; 4 5 6 14 public class ContextImplTest extends TestCase { 15 18 public ContextImplTest(String 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 [] { "session" }) == null); 46 super.assertEquals("value", ctx.get("key", new String [] { "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 { 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 ("Object should not be on stack"); 64 } catch (IllegalStateException e) { 65 } 67 } 68 } 69 | Popular Tags |