1 package org.xmlhammer.gui.acceptance;
2
3 import java.io.File;
4 import java.net.URI;
5 import java.util.List;
6
7 import junit.framework.TestCase;
8
9 import org.xmlhammer.ModuleThread;
10 import org.xmlhammer.PreferencesHandler;
11 import org.xmlhammer.gui.Page;
12 import org.xmlhammer.gui.ProjectView;
13 import org.xmlhammer.gui.input.InputPage;
14 import org.xmlhammer.model.project.Document;
15 import org.xmlhammer.model.project.Project;
16
17 public abstract class ProjectTestCase extends TestCase {
18 private static DummyApplication app = null;
19
20 public ProjectTestCase(String test) {
21 super(test);
22 }
23
24 public DummyApplication getApplication() {
25 if (app == null) {
26 PreferencesHandler.getInstance().useDefaultPreferences();
27 app = new DummyApplication();
28 }
29
30 return app;
31 }
32
33 public void openProject(File file) throws Exception {
34 DummyApplication application = getApplication();
35
36
37
38
39
40
41
42
43 URI uri = file.toURI();
44
45 application.open(file);
46
47 assertEquals(uri, application.getProjectsView().getSelectedView().getURI());
48
49 Project project = application.getProjectsView().getSelectedView().getProject(null);
50
51 List<Document> list = project.getInput().getSourceOrSourceAndResult();
52 if (list.size() > 0) {
53 assertNotNull(list.get(0));
54 } else if (project.getInput().getFilter() != null) {
55 assertNotNull(project.getInput().getFilter().getDir());
56 assertNotNull(project.getInput().getFilter().getPattern());
57 } else {
58 assertTrue(list.size() > 0);
59 }
60 }
61
62 public void initialPage() {
63 ProjectView view = getApplication().getProjectsView().getSelectedView();
64 Page page = view.getSelectedPage();
65
66 assertTrue(page instanceof InputPage);
67 }
68
69 public void hasChanged() {
70 assertFalse(getApplication().getProjectsView().getSelectedView().getFieldManager().isChanged());
71 }
72
73 public void execute() {
74 getApplication().getExecuteAction().run();
75
76 try {
77 ModuleThread thread = getApplication().getExecuteAction().getModuleThread();
78
79 if (thread != null) {
80 while (thread.isAlive()) {
81 Thread.sleep(10);
82 }
83 }
84 } catch (InterruptedException e) {
85 e.printStackTrace();
86 }
87 }
88
89 public void closeProject() throws Exception {
90 getApplication().getCloseAction().run();
91
92 assertNull(getApplication().getProjectsView().getSelectedView());
93 }
94
95 public void closeApplication() {
96 getApplication().getExitAction().run();
97 assertFalse(getApplication().isDisplayable());
98
99 app = null;
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113 }