01: package abbot.editor;
02:
03: import java.io.*;
04:
05: import junit.extensions.abbot.*;
06: import abbot.script.Script;
07:
08: /** Tests for the script editor proper. */
09:
10: public class ScriptEditorTest extends ComponentTestFixture {
11:
12: ScriptEditor editor;
13:
14: protected void setUp() {
15: editor = new ScriptEditor(new EditorContext()) {
16: protected boolean checkSaveBeforeClose() {
17: return true;
18: }
19: };
20: }
21:
22: protected void tearDown() {
23: if (editor != null) {
24: editor.dispose();
25: }
26: // Make sure we don't have any security managers left around
27: // preventing exits
28: System.setSecurityManager(null);
29: }
30:
31: public void testSaveNestedScripts() throws Throwable {
32: Script s1 = new Script(getHierarchy());
33: Script s2 = new Script(getHierarchy());
34: Script s3 = new Script(getHierarchy());
35: s1.addStep(s2);
36: s2.addStep(s3);
37: s3.addStep(new Script(getHierarchy()));
38: assertTrue("Script 1 should be marked dirty", s1.isDirty());
39: assertTrue("Script 2 should be marked dirty", s2.isDirty());
40: assertTrue("Script 3 should be marked dirty", s3.isDirty());
41: editor.saveNestedScripts(s1);
42: assertTrue("Script 1 should have been saved", !s1.isDirty());
43: assertTrue("Script 2 should have been saved", !s2.isDirty());
44: assertTrue("Script 3 should have been saved", !s3.isDirty());
45: }
46:
47: /** Open a new, empty script. */
48: public void testNewScript() throws Throwable {
49: // Try a file that exists
50: File file = File.createTempFile(getName(), ".xml");
51: file.deleteOnExit();
52: editor.newScript(file, false);
53: // Default script should always get a launch + terminate
54: Script script = (Script) editor.getResolverContext();
55: assertTrue("Script should have a launch step", script
56: .hasLaunch());
57: assertTrue("Script should have a terminate step", script
58: .hasTerminate());
59:
60: // Try a file that doesn't exist
61: file = File.createTempFile(getName(), ".xml");
62: file.delete();
63: editor.newScript(file, false);
64: file.deleteOnExit();
65: script = (Script) editor.getResolverContext();
66: assertTrue("Script should have a launch step", script
67: .hasLaunch());
68: assertTrue("Script should have a terminate step", script
69: .hasTerminate());
70: }
71:
72: /** Construct a test case with the given name. */
73: public ScriptEditorTest(String name) {
74: super (name);
75: }
76:
77: /** Run the default test suite. */
78: public static void main(String[] args) {
79: TestHelper.runTests(args, ScriptEditorTest.class);
80: }
81: }
|