|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
Fixture.java | 64.3% | 91.3% | 88.9% | 82.6% |
|
1 |
package abbot.script;
|
|
2 |
|
|
3 |
import java.awt.Component;
|
|
4 |
import java.util.*;
|
|
5 |
import java.util.Map;
|
|
6 |
import abbot.Log;
|
|
7 |
import abbot.finder.Hierarchy;
|
|
8 |
import abbot.i18n.Strings;
|
|
9 |
import abbot.script.Launch.ThreadedLaunchListener;
|
|
10 |
|
|
11 |
/** Provides a method of defining a single script as the UI application test
|
|
12 |
* context for multiple scripts. A script which uses a fixture step (as
|
|
13 |
* opposed to an explicit launch) will only instantiate the fixture if it does
|
|
14 |
* not already exist.<p>
|
|
15 |
* A Fixture will only be run once for any consecutive group of
|
|
16 |
* <code>Script</code>s that refer to it. The {@link StepRunner} class is
|
|
17 |
* normally used to control execution and will manage fixture setup/teardown
|
|
18 |
* as needed.
|
|
19 |
*/
|
|
20 |
public class Fixture extends Script implements UIContext { |
|
21 |
|
|
22 |
private static Fixture currentFixture = null; |
|
23 |
|
|
24 | 0 |
public Fixture(String filename, Hierarchy h) {
|
25 | 0 |
super(filename, h);
|
26 |
} |
|
27 |
|
|
28 |
/** Construct a <code>Fixture</code> from its XML attributes. */
|
|
29 | 32 |
public Fixture(Resolver parent, Map attributes) {
|
30 | 32 |
super(parent, attributes);
|
31 | 32 |
setHierarchy(parent.getHierarchy()); |
32 |
} |
|
33 |
|
|
34 |
/** Run the entire fixture, using the given runner as a controller/monitor. */
|
|
35 | 3 |
public void launch(StepRunner runner) throws Throwable { |
36 | 3 |
runner.run(this);
|
37 |
} |
|
38 |
|
|
39 |
/** @return Whether this fixture is currently launched. */
|
|
40 | 19 |
public boolean isLaunched() { |
41 | 19 |
return equivalent(currentFixture);
|
42 |
} |
|
43 |
|
|
44 |
/** Don't re-run if already launched. */
|
|
45 | 7 |
protected void runStep(StepRunner runner) throws Throwable { |
46 | 7 |
if (!isLaunched()) {
|
47 | 7 |
if (currentFixture != null) |
48 | 0 |
currentFixture.terminate(); |
49 | 7 |
currentFixture = this;
|
50 | 7 |
super.runStep(runner);
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 | 43 |
public void terminate() { |
55 | 43 |
Log.debug("fixture terminate");
|
56 | 43 |
if (equivalent(currentFixture)) {
|
57 | 13 |
if (currentFixture != this) { |
58 | 6 |
currentFixture.terminate(); |
59 |
} |
|
60 |
else {
|
|
61 | 7 |
UIContext context = getUIContext(); |
62 | 7 |
if (context != null) |
63 | 7 |
context.terminate(); |
64 | 7 |
currentFixture = null;
|
65 |
} |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 | 62 |
public String getXMLTag() { return TAG_FIXTURE; } |
70 |
|
|
71 | 63 |
public String getDefaultDescription() {
|
72 | 63 |
String ext = isForked() ? " &" : ""; |
73 | 63 |
String desc = Strings.get("fixture.desc",
|
74 |
new Object[] { getFilename(), ext });
|
|
75 | 63 |
return desc.indexOf(UNTITLED_FILE) != -1 ? UNTITLED : desc;
|
76 |
} |
|
77 |
|
|
78 |
/** Two fixtures are equivalent if they have the same XML representation. */
|
|
79 | 71 |
public boolean equivalent(UIContext f) { |
80 | 71 |
return f instanceof Fixture |
81 |
&& (equals(f) || getFullXMLString().equals(((Fixture)f).getFullXMLString())); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|