source: java/main/src/test/java/com/framsticks/hosting/ServerTest.java @ 101

Last change on this file since 101 was 101, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 7.2 KB
Line 
1package com.framsticks.hosting;
2
3// import org.apache.log4j.Logger;
4import java.util.Arrays;
5import java.util.LinkedList;
6import java.util.List;
7
8import org.testng.annotations.Test;
9
10import com.framsticks.core.ListChange;
11import com.framsticks.core.LocalTree;
12import com.framsticks.core.Path;
13import com.framsticks.core.TreeOperations;
14import com.framsticks.core.XmlBasedTest;
15import com.framsticks.remote.RemoteTree;
16
17import com.framsticks.test.TestChangeEvent;
18import com.framsticks.test.TestClass;
19import com.framsticks.core.Tree;
20import com.framsticks.params.FramsClass;
21import com.framsticks.params.Access;
22import com.framsticks.params.EventListener;
23import com.framsticks.params.PrimitiveParam;
24import com.framsticks.params.PropertiesAccess;
25import com.framsticks.params.types.EventParam;
26import com.framsticks.params.types.StringParam;
27// import com.framsticks.params.types.EventParam;
28import com.framsticks.params.types.ProcedureParam;
29import com.framsticks.util.dispatching.Dispatching.Waiter;
30import com.framsticks.util.dispatching.FutureHandler;
31import com.framsticks.util.dispatching.RunAt;
32
33import static com.framsticks.core.TreeOperations.*;
34
35import static org.fest.assertions.Assertions.*;
36
37@Test
38public class ServerTest extends XmlBasedTest {
39
40        protected RemoteTree remote;
41        protected FramsClass remoteTestFramsClass;
42        protected Path remotePath;
43
44        protected Server server;
45        protected LocalTree hosted;
46        protected TestClass hostedObject;
47        protected EventListener<TestChangeEvent> listener;
48        protected EventListener<ListChange> childListener;
49
50        protected List<String> listenerArguments = new LinkedList<>();
51        protected List<ListChange> childrenChanges = new LinkedList<>();
52
53
54
55        @Test
56        public void runServer() {
57                assertThat(framsticks.size()).isEqualTo(2);
58                assertThat(framsticks.get("test")).isInstanceOf(Server.class);
59                assertThat(framsticks.get("remote")).isInstanceOf(RemoteTree.class);
60
61                server = (Server) framsticks.get("test");
62                remote = (RemoteTree) framsticks.get("remote");
63                assertThat(server.getHosted()).isInstanceOf(LocalTree.class);
64                hosted = (LocalTree) server.getHosted();
65                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
66                hostedObject = hosted.getRootObject(TestClass.class);
67        }
68
69        @Test(dependsOnMethods = "runServer")
70        public void fetchInfo() {
71                final Waiter waiter = produceWaiter(1.0);
72
73                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
74                        @Override
75                        protected void result(Path path) {
76                                assertThat(path.isResolved()).isTrue();
77                                remoteTestFramsClass = bindAccess(path).getFramsClass();
78                                assertThat(remoteTestFramsClass.getName()).isEqualTo("TestClass");
79                                waiter.pass();
80                        }
81                });
82
83        }
84
85        @Test(dependsOnMethods = "fetchInfo")
86        public void resolveAndfetchRootObject() {
87                final Waiter waiter = produceWaiter(1.0);
88
89                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
90                        @Override
91                        protected void result(Path path) {
92                                assertThat(path.isResolved()).isTrue();
93                                remotePath = path;
94                                Access access = bindAccess(path);
95                                assertThat(access).isInstanceOf(PropertiesAccess.class);
96                                assertThat(access.get("name", String.class)).isEqualTo("a test name");
97                                waiter.pass();
98                        }
99                });
100        }
101
102        @Test(dependsOnMethods = "resolveAndfetchRootObject")
103        public void setValueName() {
104                final Waiter waiter = produceWaiter(2.0);
105
106                set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) {
107                        @Override
108                        protected void result(Integer flags) {
109                                // assertThat(flags).isEqualTo(0);
110                                /** And now check directly whether it was really set. */
111                                hosted.dispatch(new RunAt<Tree>(failOnException) {
112                                        @Override
113                                        protected void runAt() {
114                                                assertThat(hostedObject.getName()).isEqualTo("new name");
115                                                waiter.pass();
116                                        }
117                                });
118                        }
119                });
120        }
121
122        @Test(dependsOnMethods = "setValueName")
123        public void registerListener() {
124                final Waiter waiter = produceWaiter(1.0);
125                listener = new EventListener<TestChangeEvent>() {
126
127                        @Override
128                        public void action(TestChangeEvent argument) {
129                                listenerArguments.add(argument.history);
130                        }
131                };
132
133                TreeOperations.tryGet(remote, "/cli/events", new FutureHandler<Path>(failOnException) {
134                        @Override
135                        protected void result(Path path) {
136                                waiter.pass();
137                        }
138                });
139
140                addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, TestChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class));
141        }
142
143        @Test(dependsOnMethods = "registerListener")
144        public void callMethod() {
145                final Waiter waiter = produceWaiter(2.0);
146
147                call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, produceWaiter(2.0).passInFuture(Object.class));
148
149                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) {
150                        @Override
151                        protected void result(Object result) {
152                                hosted.dispatch(new RunAt<Tree>(failOnException) {
153                                        @Override
154                                        protected void runAt() {
155                                                assertThat(hostedObject.getHistory()).isEqualTo("next word|");
156                                                waiter.pass();
157                                        }
158                                });
159                        }
160                });
161        }
162
163
164        @Test(dependsOnMethods = "callMethod")
165        public void deregisterListener() {
166                removeListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class));
167
168                assertThat(listenerArguments).isEqualTo(Arrays.asList("", "next word|"));
169        }
170
171
172        @Test(dependsOnMethods = "deregisterListener")
173        public void registerChildListener() {
174
175                childListener = new EventListener<ListChange>() {
176                        @Override
177                        public void action(ListChange listChange) {
178                                childrenChanges.add(listChange);
179                        }
180                };
181
182                addListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, ListChange.class, produceWaiter(1.0).passInFuture(Void.class));
183        }
184
185        @Test(dependsOnMethods = "registerChildListener")
186        public void createChild() {
187                final Waiter waiter = produceWaiter(2.0);
188                call(remotePath, "createChild", new Object[] { "a child" }, produceWaiter(2.0).passInFuture(Object.class));
189                call(remotePath, "createChild", new Object[] { "another child" }, produceWaiter(2.0).passInFuture(Object.class));
190
191                tryGet(remote, "/testClass/children/c0", new FutureHandler<Path>(failOnException) {
192
193                        @Override
194                        protected void result(Path result) {
195                                set(result, getFramsClass(result).getParamEntry("name", StringParam.class), "new_name", new FutureHandler<Integer>(failOnException) {
196
197                                        @Override
198                                        protected void result(Integer result) {
199                                                waiter.pass();
200                                        }
201                                });
202                        }
203                });
204        }
205
206        @Test(dependsOnMethods = "createChild")
207        public void deregisterChildListener() {
208                removeListener(remotePath, remoteTestFramsClass.getParamEntry("children_changed", EventParam.class), childListener, produceWaiter(1.0).passInFuture(Void.class));
209        }
210
211        @Test(dependsOnMethods = "deregisterChildListener")
212        public void checkListChanges() {
213                assertThat(childrenChanges).isEqualTo(Arrays.asList(
214                        new ListChange(ListChange.Action.Add, 0, "c0"),
215                        new ListChange(ListChange.Action.Add, 1, "c1"),
216                        new ListChange(ListChange.Action.Modify, 0, "c0")
217                ));
218        }
219
220        @Test(dependsOnMethods = "checkListChanges")
221        public void endWait() {
222                monitor.useFor(1.0);
223        }
224}
Note: See TracBrowser for help on using the repository browser.