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