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 22 public class GlobalsTest extends TestCase { 23 26 public GlobalsTest(String 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 { 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 ("Private state should not have been executed"); 68 } catch (StateAccessException e) { 69 } 71 } 72 } 73 | Popular Tags |