[90] | 1 | |
---|
| 2 | package com.framsticks.gui; |
---|
| 3 | |
---|
| 4 | import static org.fest.assertions.Assertions.assertThat; |
---|
| 5 | |
---|
| 6 | import org.fest.swing.fixture.JPanelFixture; |
---|
| 7 | import org.testng.annotations.Test; |
---|
| 8 | |
---|
[100] | 9 | import com.framsticks.params.Access; |
---|
[99] | 10 | import com.framsticks.params.EventListener; |
---|
[90] | 11 | import com.framsticks.params.ReflectionAccess; |
---|
[99] | 12 | import com.framsticks.params.types.EventParam; |
---|
[90] | 13 | import com.framsticks.params.types.StringParam; |
---|
| 14 | import com.framsticks.parsers.XmlLoader; |
---|
[105] | 15 | import com.framsticks.structure.LocalTree; |
---|
| 16 | import com.framsticks.structure.Path; |
---|
| 17 | import com.framsticks.structure.Tree; |
---|
| 18 | import com.framsticks.structure.messages.ValueChange; |
---|
[90] | 19 | import com.framsticks.test.TestClass; |
---|
[105] | 20 | import com.framsticks.util.dispatching.Future; |
---|
[97] | 21 | // import com.framsticks.util.dispatching.Dispatching; |
---|
[90] | 22 | import com.framsticks.util.dispatching.RunAt; |
---|
[105] | 23 | import static com.framsticks.params.ParamsUtil.getParam; |
---|
| 24 | import static com.framsticks.structure.TreeOperations.*; |
---|
[90] | 25 | |
---|
| 26 | @Test |
---|
| 27 | public class ProcedureBrowserTest extends BrowserBaseTest { |
---|
| 28 | |
---|
[99] | 29 | LocalTree tree; |
---|
[90] | 30 | |
---|
| 31 | @Override |
---|
| 32 | protected void configureBrowser() { |
---|
| 33 | browser = new XmlLoader().load(Browser.class, getClass().getResourceAsStream("/configs/ProcedureBrowserTest.xml")); |
---|
| 34 | |
---|
[97] | 35 | assertThat(browser.getTrees().size()).isEqualTo(1); |
---|
[99] | 36 | assertThat(browser.getTrees().get("test")).isInstanceOf(LocalTree.class); |
---|
[90] | 37 | |
---|
[99] | 38 | tree = (LocalTree) browser.getTrees().get("test"); |
---|
[90] | 39 | } |
---|
| 40 | |
---|
| 41 | @Test(timeOut = 10000) |
---|
| 42 | public void testShow() { |
---|
[97] | 43 | tree.dispatch(new RunAt<Tree>(failOnException) { |
---|
[90] | 44 | @Override |
---|
[97] | 45 | protected void runAt() { |
---|
| 46 | assertThat(tree.getRootObject()).isInstanceOf(TestClass.class); |
---|
[90] | 47 | } |
---|
| 48 | }); |
---|
| 49 | |
---|
| 50 | clickAndExpandPath("test"); |
---|
| 51 | |
---|
[97] | 52 | tree.dispatch(new RunAt<Tree>(failOnException) { |
---|
[90] | 53 | @Override |
---|
[97] | 54 | protected void runAt() { |
---|
[105] | 55 | assertThat(getParam(bindAccess(tree, "/"), "history")).isInstanceOf(StringParam.class); |
---|
[90] | 56 | } |
---|
| 57 | }); |
---|
| 58 | |
---|
| 59 | // monitor.useFor(4.0); |
---|
| 60 | |
---|
[97] | 61 | tree.dispatch(new RunAt<Tree>(failOnException) { |
---|
[90] | 62 | @Override |
---|
[97] | 63 | protected void runAt() { |
---|
[100] | 64 | Access access = bindAccess(tree, "/"); |
---|
[90] | 65 | assertThat(access).isInstanceOf(ReflectionAccess.class); |
---|
[105] | 66 | assertThat(getParam(access, 0).getId()).isEqualTo("name"); |
---|
| 67 | assertThat(getParam(access, 1).getId()).isEqualTo("history"); |
---|
| 68 | assertThat(getParam(access, 2).getId()).isEqualTo("history_changed"); |
---|
| 69 | assertThat(getParam(access, 3).getId()).isEqualTo("appendHistory"); |
---|
| 70 | assertThat(getParam(access, 4).getId()).isEqualTo("resetHistory"); |
---|
[90] | 71 | |
---|
[97] | 72 | assertThat(access.get("history", String.class)).isEqualTo("initial|"); |
---|
[90] | 73 | } |
---|
| 74 | }); |
---|
| 75 | |
---|
| 76 | // frame.panel("TestClass"); |
---|
[97] | 77 | final JPanelFixture appendHistory = frame.panel("TestClass").panel("appendHistory"); |
---|
| 78 | appendHistory.panel("arg0").textBox("value").enterText("Żółw"); |
---|
| 79 | assertThat(appendHistory.panel("arg0").textBox("value").text()).isEqualTo("Żółw"); |
---|
| 80 | clickButton(appendHistory.button("call")); |
---|
[90] | 81 | waitForIdle(); |
---|
| 82 | |
---|
[103] | 83 | final EventListener<ValueChange> listener = new EventListener<ValueChange>() { |
---|
[97] | 84 | |
---|
[99] | 85 | @Override |
---|
[103] | 86 | public void action(ValueChange argument) { |
---|
| 87 | assertThat(argument.value).isEqualTo(""); |
---|
[99] | 88 | } |
---|
| 89 | }; |
---|
| 90 | |
---|
[97] | 91 | tree.dispatch(new RunAt<Tree>(failOnException) { |
---|
[90] | 92 | @Override |
---|
[97] | 93 | protected void runAt() { |
---|
[100] | 94 | Access access = bindAccess(tree, "/"); |
---|
[99] | 95 | assertThat(access.get("history", String.class)).isEqualTo("initial|Żółw|"); |
---|
| 96 | |
---|
[105] | 97 | tree.addListener(Path.to(tree, "/"), getParam(access, "history_changed", EventParam.class), listener, ValueChange.class, Future.doNothing(Void.class, failOnException)); |
---|
[90] | 98 | } |
---|
| 99 | }); |
---|
| 100 | |
---|
[97] | 101 | clickButton(frame.panel("TestClass").panel("resetHistory").button("call")); |
---|
[90] | 102 | waitForIdle(); |
---|
| 103 | |
---|
[97] | 104 | tree.dispatch(new RunAt<Tree>(failOnException) { |
---|
[90] | 105 | @Override |
---|
[97] | 106 | protected void runAt() { |
---|
[100] | 107 | Access access = bindAccess(tree, "/"); |
---|
[99] | 108 | assertThat(access.get("history", String.class)).isEqualTo(""); |
---|
| 109 | |
---|
[105] | 110 | tree.removeListener(Path.to(tree, "/"), getParam(access, "history_changed", EventParam.class), listener, Future.doNothing(Void.class, failOnException)); |
---|
[90] | 111 | } |
---|
| 112 | }); |
---|
| 113 | } |
---|
| 114 | } |
---|