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

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

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File size: 5.4 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.LocalTree;
11import com.framsticks.core.Path;
12import com.framsticks.core.TreeOperations;
13import com.framsticks.core.XmlBasedTest;
14import com.framsticks.remote.RemoteTree;
15
16import com.framsticks.test.ChangeEvent;
17import com.framsticks.test.TestClass;
18import com.framsticks.core.Tree;
19import com.framsticks.params.FramsClass;
20import com.framsticks.params.AccessInterface;
21import com.framsticks.params.EventListener;
22import com.framsticks.params.PrimitiveParam;
23import com.framsticks.params.PropertiesAccess;
24import com.framsticks.params.types.EventParam;
25// import com.framsticks.params.types.EventParam;
26import com.framsticks.params.types.ProcedureParam;
27import com.framsticks.util.dispatching.Dispatching.Waiter;
28import com.framsticks.util.dispatching.FutureHandler;
29import com.framsticks.util.dispatching.RunAt;
30
31import static com.framsticks.core.TreeOperations.*;
32
33import static org.fest.assertions.Assertions.*;
34
35@Test
36public class ServerTest extends XmlBasedTest {
37
38        protected RemoteTree remote;
39        protected FramsClass remoteTestFramsClass;
40        protected Path remotePath;
41
42        protected Server server;
43        protected LocalTree hosted;
44        protected TestClass hostedObject;
45        protected EventListener<ChangeEvent> listener;
46        protected List<String> listenerArguments = new LinkedList<>();
47
48        @Override
49        protected String getConfigurationName() {
50                return "ServerTest.xml";
51        }
52
53        @Test
54        public void runServer() {
55                assertThat(framsticks.size()).isEqualTo(2);
56                assertThat(framsticks.get("test")).isInstanceOf(Server.class);
57                assertThat(framsticks.get("remote")).isInstanceOf(RemoteTree.class);
58
59                server = (Server) framsticks.get("test");
60                remote = (RemoteTree) framsticks.get("remote");
61                assertThat(server.getHosted()).isInstanceOf(LocalTree.class);
62                hosted = (LocalTree) server.getHosted();
63                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
64                hostedObject = hosted.getRootObject(TestClass.class);
65        }
66
67        @Test(dependsOnMethods = "runServer")
68        public void fetchInfo() {
69                final Waiter waiter = produceWaiter(1.0);
70
71                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
72                        @Override
73                        protected void result(Path path) {
74                                assertThat(path.isResolved()).isTrue();
75                                remoteTestFramsClass = bindAccess(path).getFramsClass();
76                                assertThat(remoteTestFramsClass.getName()).isEqualTo("TestClass");
77                                waiter.pass();
78                        }
79                });
80
81        }
82
83        @Test(dependsOnMethods = "fetchInfo")
84        public void resolveAndfetchRootObject() {
85                final Waiter waiter = produceWaiter(1.0);
86
87                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
88                        @Override
89                        protected void result(Path path) {
90                                assertThat(path.isResolved()).isTrue();
91                                remotePath = path;
92                                AccessInterface access = bindAccess(path);
93                                assertThat(access).isInstanceOf(PropertiesAccess.class);
94                                assertThat(access.get("name", String.class)).isEqualTo("a test name");
95                                waiter.pass();
96                        }
97                });
98        }
99
100        @Test(dependsOnMethods = "resolveAndfetchRootObject")
101        public void setValueName() {
102                final Waiter waiter = produceWaiter(2.0);
103
104                set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) {
105                        @Override
106                        protected void result(Integer flags) {
107                                // assertThat(flags).isEqualTo(0);
108                                /** And now check directly whether it was really set. */
109                                hosted.dispatch(new RunAt<Tree>(failOnException) {
110                                        @Override
111                                        protected void runAt() {
112                                                assertThat(hostedObject.getName()).isEqualTo("new name");
113                                                waiter.pass();
114                                        }
115                                });
116                        }
117                });
118        }
119
120        @Test(dependsOnMethods = "setValueName")
121        public void registerListener() {
122                final Waiter waiter = produceWaiter(1.0);
123                listener = new EventListener<ChangeEvent>() {
124
125                        @Override
126                        public void action(ChangeEvent argument) {
127                                listenerArguments.add(argument.history);
128                        }
129                };
130
131                TreeOperations.tryGet(remote, "/cli/events", new FutureHandler<Path>(failOnException) {
132                        @Override
133                        protected void result(Path path) {
134                                waiter.pass();
135                        }
136                });
137
138                addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class));
139        }
140
141        @Test(dependsOnMethods = "registerListener")
142        public void callMethod() {
143                final Waiter waiter = produceWaiter(2.0);
144
145                call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, produceWaiter(2.0).passInFuture(Object.class));
146
147                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) {
148                        @Override
149                        protected void result(Object result) {
150                                hosted.dispatch(new RunAt<Tree>(failOnException) {
151                                        @Override
152                                        protected void runAt() {
153                                                assertThat(hostedObject.getHistory()).isEqualTo("next word|");
154                                                waiter.pass();
155                                        }
156                                });
157                        }
158                });
159        }
160
161
162        @Test(dependsOnMethods = "callMethod")
163        public void deregisterListener() {
164                removeListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class));
165
166                assertThat(listenerArguments).isEqualTo(Arrays.asList("", "next word|"));
167        }
168
169        @Test(dependsOnMethods = "callMethod")
170        public void endWait() {
171                monitor.useFor(1.0);
172        }
173}
Note: See TracBrowser for help on using the repository browser.