1 5 package com.opensymphony.workflow; 6 7 import com.opensymphony.module.propertyset.memory.MemoryPropertySet; 8 9 import com.opensymphony.workflow.util.ScriptVariableParser; 10 11 import junit.framework.TestCase; 12 13 import java.util.HashMap ; 14 15 16 22 public class TestAbstractWorkflow extends TestCase { 23 25 AbstractWorkflow wf = new AbstractWorkflow(); 26 27 29 public void testVariableTranslation() { 30 HashMap transients = new HashMap (); 31 MemoryPropertySet ps = new MemoryPropertySet(); 32 ps.init(null, null); 33 34 A a = new A("aName", new B(100, "bName")); 35 A a2 = new A("biff", new B(-1, "jack")); 36 transients.put("a", a); 37 transients.put("blah", "blah"); 38 ps.setString("blah", "NOT BLAH"); 39 ps.setObject("a2", a2); 40 ps.setString("foo", "bar"); 41 42 assertEquals("aName", ScriptVariableParser.getVariableFromMaps("a.name", transients, ps)); 43 assertEquals(a, ScriptVariableParser.getVariableFromMaps("a", transients, ps)); 44 assertEquals("blah", ScriptVariableParser.getVariableFromMaps("blah", transients, ps)); 45 assertEquals("jack", ScriptVariableParser.getVariableFromMaps("a2.b.name", transients, ps)); 46 assertEquals(new Integer (-1), ScriptVariableParser.getVariableFromMaps("a2.b.age", transients, ps)); 47 assertEquals("bar", ScriptVariableParser.getVariableFromMaps("foo", transients, ps)); 48 49 assertEquals("hello, jack, what is your age? -1", ScriptVariableParser.translateVariables("hello, ${a2.b.name}, what is your age? ${a2.b.age}", transients, ps)); 50 assertEquals("hello, , what is your age? -1", ScriptVariableParser.translateVariables("hello, ${I.Don't.EXIST}, what is your age? ${a2.b.age}", transients, ps)); 51 } 52 53 55 public class A { 56 B b; 57 String name; 58 59 public A(String name, B b) { 60 this.name = name; 61 this.b = b; 62 } 63 64 public B getB() { 65 return b; 66 } 67 68 public String getName() { 69 return name; 70 } 71 } 72 73 public class B { 74 String name; 75 int age; 76 77 public B(int age, String name) { 78 this.age = age; 79 this.name = name; 80 } 81 82 public int getAge() { 83 return age; 84 } 85 86 public String getName() { 87 return name; 88 } 89 } 90 } 91 | Popular Tags |