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

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

HIGHLIGHTS:

  • add auto loading and saving algorithms between

frams files format and Java classes

  • respect ValueChange? events in GUI (do not reload object)
  • support results of procedures in Java server
  • make Experiment automatically convert between frams file and NetFile? object
  • add MessageLogger? (compatible with original frams server messages)
  • WorkPackageLogic? now validates results, is able to discard them, reschedule

whole package, or only uncomputed remainder

CHANGELOG:
Show just a short description in PrimeExperiment?.

Add primes_changed event to the PrimeExperiment?.

Make WorkPackageLogic? robust to frams server returning invalid results.

Add MessageLogger? to logics.

Add NetFile? interface. Support Messages from server.

Minor changes to connections.

Merge results in the PrimeExperiment?.

More netload class->file conversion to Simulator.

Move netsave parsing to Simulator.

Fix bug with inverted ordering of events firing in Experiment.

Minor changes.

Minor logging changes.

Use AccessOperations?.convert in NetLoadSaveLogic?

NetLoadSaveLogic? now encloses the conversion.

Use more generic AccessOperations? saveAll and loadAll in PrimePackage?.

Add Result class for enclosing of call invocations' results.

Improve feature request handling in Connections.

Use AccessOperations?.convert in RemoteTree? events parsing.

Minor change.

Add some information params to Java server root and CLI objects.

A draft implementation of loadAll algorithm.

That algorithm tries to load objects into a tree structure.

Add AccessOperationsTest? test.

Develop WorkPackageLogic?.

  • add state tracking fields
  • add work package generation

Add utility class SimplePrimitive?.

Meant for Java backend classes, enclose a single primitive value
and set of listeners.

Improve primitive value refresh in GUI.

When ValueChange? found in called event, do not reload whole
object, but only update GUI (no communication is performed).

Use ValueChange? in the TestClass? test.

Minor changes.

Sending all packages in PrimeExperiment? to the frams servers.

Develop AccessOperations?.loadComposites().

Remove addAccess from MultiParamLoader? interface.

There is now no default AccessProvider? in MultiParamLoader?.
User must explicitely set AccessStash? or Registry.

Improve saving algorithms in AccessOperations?.

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