01: package abbot.script;
02:
03: import junit.extensions.abbot.*;
04:
05: public class ExpressionTest extends ResolverFixture {
06:
07: public void testFromXML() throws Throwable {
08: String EXPR = "System.out.println(\"hello\");";
09: String XML = "<expression><![CDATA[" + EXPR
10: + "]]></expression>";
11:
12: Expression e = (Expression) Step.createStep(getResolver(), XML);
13: assertEquals("Wrong expression parsed", EXPR, e.getExpression());
14:
15: assertEquals("Wrong encoding", XML, Step.toXMLString(e));
16: }
17:
18: public void testSimpleExpression() throws Throwable {
19: Expression e = new Expression(getResolver(), getName());
20: assertEquals("Default expression should be empty", "", e
21: .getExpression());
22:
23: e.setExpression("i=10;");
24: e.runStep();
25: Interpreter sh = (Interpreter) getResolver().getProperty(
26: Script.INTERPRETER);
27: assertEquals("Wrong value for expression", new Integer(10), sh
28: .get("i"));
29: }
30:
31: public void testVariableExpansion() throws Throwable {
32: Expression e = new Expression(getResolver(), getName());
33: assertEquals("Default expression should be empty", "", e
34: .getExpression());
35:
36: final String NAME = "bloody hell";
37: getResolver().setProperty("name", NAME);
38: e.setExpression("name=\"${name}\";");
39: e.runStep();
40: Interpreter sh = (Interpreter) getResolver().getProperty(
41: Script.INTERPRETER);
42: assertEquals("Wrong value for expression", NAME, sh.get("name"));
43: }
44:
45: public ExpressionTest(String name) {
46: super (name);
47: }
48:
49: public static void main(String[] args) {
50: TestHelper.runTests(args, ExpressionTest.class);
51: }
52: }
|