001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow;
006:
007: import com.opensymphony.module.propertyset.memory.MemoryPropertySet;
008:
009: import com.opensymphony.workflow.util.DefaultVariableResolver;
010:
011: import junit.framework.TestCase;
012:
013: import java.util.HashMap;
014:
015: /**
016: * This testcase verifies that an AbstractWorkflow provided methods work properly.
017: */
018: public class TestAbstractWorkflow extends TestCase {
019: //~ Instance fields ////////////////////////////////////////////////////////
020:
021: AbstractWorkflow wf = new AbstractWorkflow();
022:
023: //~ Methods ////////////////////////////////////////////////////////////////
024:
025: public void testVariableTranslation() {
026: HashMap transients = new HashMap();
027: MemoryPropertySet ps = new MemoryPropertySet();
028: ps.init(null, null);
029:
030: A a = new A("aName", new B(100, "bName"));
031: A a2 = new A("biff", new B(-1, "jack"));
032: transients.put("a", a);
033: transients.put("blah", "blah");
034: ps.setString("blah", "NOT BLAH");
035: ps.setObject("a2", a2);
036: ps.setString("foo", "bar");
037:
038: DefaultVariableResolver resolver = new DefaultVariableResolver();
039: assertEquals("aName", resolver.getVariableFromMaps("a.name",
040: transients, ps));
041: assertEquals(a, resolver.getVariableFromMaps("a", transients,
042: ps));
043: assertEquals("blah", resolver.getVariableFromMaps("blah",
044: transients, ps));
045: assertEquals("jack", resolver.getVariableFromMaps("a2.b.name",
046: transients, ps));
047: assertEquals(new Integer(-1), resolver.getVariableFromMaps(
048: "a2.b.age", transients, ps));
049: assertEquals("bar", resolver.getVariableFromMaps("foo",
050: transients, ps));
051:
052: assertEquals(
053: "hello, jack, what is your age? -1",
054: resolver
055: .translateVariables(
056: "hello, ${a2.b.name}, what is your age? ${a2.b.age}",
057: transients, ps));
058: assertEquals(
059: "hello, , what is your age? -1",
060: resolver
061: .translateVariables(
062: "hello, ${I.Don't.EXIST}, what is your age? ${a2.b.age}",
063: transients, ps));
064: }
065:
066: //~ Inner Classes //////////////////////////////////////////////////////////
067:
068: public class A {
069: B b;
070: String name;
071:
072: public A(String name, B b) {
073: this .name = name;
074: this .b = b;
075: }
076:
077: public B getB() {
078: return b;
079: }
080:
081: public String getName() {
082: return name;
083: }
084: }
085:
086: public class B {
087: String name;
088: int age;
089:
090: public B(int age, String name) {
091: this .age = age;
092: this .name = name;
093: }
094:
095: public int getAge() {
096: return age;
097: }
098:
099: public String getName() {
100: return name;
101: }
102: }
103: }
|