1 | package com.framsticks.gui; |
---|
2 | |
---|
3 | import javax.swing.JFrame; |
---|
4 | |
---|
5 | import org.apache.log4j.Logger; |
---|
6 | import org.fest.swing.edt.FailOnThreadViolationRepaintManager; |
---|
7 | import org.fest.swing.edt.GuiActionRunner; |
---|
8 | import org.fest.swing.edt.GuiQuery; |
---|
9 | import org.fest.swing.edt.GuiTask; |
---|
10 | import org.fest.swing.fixture.FrameFixture; |
---|
11 | import org.fest.swing.fixture.JTreeFixture; |
---|
12 | // import static org.fest.swing.edt.GuiActionRunner.*; |
---|
13 | import org.testng.annotations.*; |
---|
14 | |
---|
15 | import com.framsticks.remote.RemoteInstance; |
---|
16 | import com.framsticks.test.TestConfiguration; |
---|
17 | import com.framsticks.util.dispatching.Dispatching; |
---|
18 | import com.framsticks.util.dispatching.JoinableMonitor; |
---|
19 | // import com.framsticks.util.dispatching.Dispatching; |
---|
20 | |
---|
21 | import static org.fest.assertions.Assertions.*; |
---|
22 | import static org.fest.swing.core.BasicRobot.robotWithNewAwtHierarchy; |
---|
23 | import static org.fest.swing.edt.GuiActionRunner.*; |
---|
24 | import org.fest.swing.core.Robot; |
---|
25 | |
---|
26 | public class BrowserTest extends TestConfiguration { |
---|
27 | private static final Logger log = Logger.getLogger(BrowserTest.class); |
---|
28 | |
---|
29 | JoinableMonitor monitor; |
---|
30 | Browser browser; |
---|
31 | Robot robot; |
---|
32 | FrameFixture frame; |
---|
33 | |
---|
34 | @BeforeClass |
---|
35 | public void setUp() { |
---|
36 | FailOnThreadViolationRepaintManager.install(); |
---|
37 | assertThat(executeInEDT()).isTrue(); |
---|
38 | |
---|
39 | robot = robotWithNewAwtHierarchy(); |
---|
40 | |
---|
41 | browser = new Browser(); |
---|
42 | monitor = new JoinableMonitor(browser); |
---|
43 | |
---|
44 | RemoteInstance localhost = new RemoteInstance(); |
---|
45 | localhost.setName("localhost"); |
---|
46 | localhost.setAddress("localhost:9009"); |
---|
47 | |
---|
48 | browser.addInstance(localhost); |
---|
49 | |
---|
50 | monitor.use(); |
---|
51 | // robot.waitForIdle(); |
---|
52 | frame = new FrameFixture(robot, |
---|
53 | GuiActionRunner.execute(new GuiQuery<JFrame>() { |
---|
54 | @Override |
---|
55 | protected JFrame executeInEDT() throws Throwable { |
---|
56 | return browser.getMainFrame().getSwing(); |
---|
57 | } |
---|
58 | })); |
---|
59 | |
---|
60 | log.info("frame fixture done"); |
---|
61 | // frame.show(); |
---|
62 | // log.info("frame fixture shown"); |
---|
63 | } |
---|
64 | |
---|
65 | public void clickAndExpandPath(JTreeFixture tree, String path) { |
---|
66 | tree.clickPath(path).expandPath(path); |
---|
67 | robot.waitForIdle(); |
---|
68 | } |
---|
69 | |
---|
70 | @Test |
---|
71 | public void testShow() { |
---|
72 | log.info("testing"); |
---|
73 | JTreeFixture tree = frame.tree("tree"); |
---|
74 | tree.clickRow(0).expandRow(0); |
---|
75 | robot.waitForIdle(); |
---|
76 | tree.clickRow(1).expandRow(1); |
---|
77 | robot.waitForIdle(); |
---|
78 | assertThat(tree.valueAt(1)).isEqualTo("simulator"); |
---|
79 | robot.waitForIdle(); |
---|
80 | execute(new GuiTask() { |
---|
81 | @Override |
---|
82 | protected void executeInEDT() throws Throwable { |
---|
83 | assertThat(frame.panel("o Simulator").component().isVisible()) |
---|
84 | .isTrue(); |
---|
85 | } |
---|
86 | }); |
---|
87 | |
---|
88 | clickAndExpandPath(tree, "localhost/simulator/genepools"); |
---|
89 | clickAndExpandPath(tree, "localhost/simulator/genepools/groups"); |
---|
90 | clickAndExpandPath(tree, "localhost/simulator/genepools/groups/Genotypes"); |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | // tree.clickPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); |
---|
98 | // robot.waitForIdle(); |
---|
99 | // sleep(2); |
---|
100 | // tree.expandPath("localhost/simulator/genepools/groups/Genotypes/genotypes"); |
---|
101 | |
---|
102 | // tree.expandRow(tree.component().getLeadSelectionRow() + 1); |
---|
103 | // robot.waitForIdle(); |
---|
104 | |
---|
105 | // sleep(2); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | @AfterClass |
---|
110 | public void tearDown() { |
---|
111 | log.info("before close"); |
---|
112 | |
---|
113 | monitor.drop(); |
---|
114 | |
---|
115 | Dispatching.joinAbsolutely(browser); |
---|
116 | // frame.cleanUp(); |
---|
117 | // log.info("before close"); |
---|
118 | // browser.interrupt(); |
---|
119 | |
---|
120 | // try { |
---|
121 | // // frame.close(); |
---|
122 | // } catch (Throwable t) { |
---|
123 | // log.error("caught ", t); |
---|
124 | // } |
---|
125 | // log.info("after close"); |
---|
126 | // // frame.close(); |
---|
127 | // // frame.cleanUp(); |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | // Dispatching.join(browser); |
---|
132 | } |
---|
133 | |
---|
134 | } |
---|