KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > config > GlobalsTest


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

22 public class GlobalsTest extends TestCase {
23   /**
24    * @param arg0
25    */

26   public GlobalsTest(String JavaDoc arg0) {
27     super(arg0);
28   }
29
30   public void testApplyRestriction() {
31     Globals g = new Globals();
32     g.createPrivate().createInclude().setPattern("do**");
33
34     TestState priv = new TestState(true);
35     priv.setId("doFoo");
36
37     TestState pub = new TestState(true);
38     pub.setId("Foo");
39     super.assertTrue("State should not be public", !g.applyRestriction(priv));
40     super.assertTrue("State should be public", g.applyRestriction(pub));
41   }
42
43   public void testIllegalAccess() throws Exception JavaDoc {
44     Globals g = new Globals();
45     g.createPrivate().createInclude().setPattern("do**");
46
47     TestState priv = new TestState(true);
48     priv.setId("doFoo");
49
50     StepState pub = new StepState();
51     pub.setId("Foo");
52
53     StateRef ref = new StateRef();
54     ref.setId("doFoo");
55     pub.addExecutable(ref);
56
57     StateMachine stm = new StateMachine();
58     stm.addGlobals(g);
59     stm.addState(priv);
60     stm.addState(pub);
61     stm.init();
62     stm.execute("Foo", new ContextImpl());
63     super.assertTrue(priv.exec);
64
65     try {
66       stm.execute("doFoo", new ContextImpl());
67       throw new Exception JavaDoc("Private state should not have been executed");
68     } catch (StateAccessException e) {
69       // ok
70
}
71   }
72 }
73
Popular Tags