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

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

HIGHLIGHTS:

  • add proper exception passing between communication sides:

if exception occur during handling client request, it is
automatically passed as comment to error response.

it may be used to snoop communication between peers

  • fix algorithm choosing text controls in GUI
  • allow GUI testing in virtual frame buffer (xvfb)

FEST had some problem with xvfb but workaround was found

supports tab-completion based on requests history

CHANGELOG:
Further improve handling of exceptions in GUI.

Add StatusBar? implementing ExceptionResultHandler?.

Make completion processing asynchronous.

Minor changes.

Improve completion in console.

Improve history in InteractiveConsole?.

First working version of DirectConsole?.

Minor changes.

Make Connection.address non final.

It is more suitable to use in configuration.

Improvement of consoles.

Improve PopupMenu? and closing of FrameJoinable?.

Fix BrowserTest?.

Found bug with FEST running under xvfb.

JButtonFixture.click() is not working under xvfb.
GuiTest? has wrapper which uses JButton.doClick() directly.

Store CompositeParam? param in TreeNode?.

Simplify ClientSideManagedConnection? connecting.

There is now connectedFunctor needed, ApplicationRequests? can be
send right after creation. They are buffered until the version
and features are negotiated.

Narow down interface of ClientSideManagedConnection?.

Allow that connection specialization send only
ApplicationRequests?.

Improve policy of text control choosing.

Change name of Genotype in BrowserTest?.

Make BrowserTest? change name of Genotype.

Minor change.

First working draft of TrackConsole?.

Simplify Consoles.

More improvements with gui joinables.

Unify initialization on gui joinables.

More rework of Frame based entities.

Refactorize structure of JFrames based entities.

Extract GuiTest? from BrowserBaseTest?.

Reorganize Console classes structure.

Add Collection view to JoinableCollection?.

Configure timeout in testing.

Minor changes.

Rework connections hierarchy.

Add Mode to the get operation.

Make get and set in Tree take PrimitiveParam?.

Unify naming of operations.

Make RunAt? use the given ExceptionHandler?.

It wraps the virtual runAt() method call with
try-catch passing exception to handler.

Force RunAt? to include ExceptionHandler?.

Improve ClientAtServer?.

Minor change.

Another sweep with FindBugs?.

Rename Instance to Tree.

Minor changes.

Minor changes.

Further clarify semantics of Futures.

Add FutureHandler?.

FutureHandler? is refinement of Future, that proxifies
exception handling to ExceptionResultHandler? given
at construction time.

Remove StateFunctor? (use Future<Void> instead).

Make Connection use Future<Void>.

Unparametrize *ResponseFuture?.

Remove StateCallback? not needed anymore.

Distinguish between sides of ResponseFuture?.

Base ResponseCallback? on Future (now ResponseFuture?).

Make asynchronous store taking Future for flags.

Implement storeValue in ObjectInstance?.

File size: 4.7 KB
Line 
1package com.framsticks.hosting;
2
3// import org.apache.log4j.Logger;
4import org.testng.annotations.Test;
5
6import com.framsticks.core.Mode;
7import com.framsticks.core.ObjectTree;
8import com.framsticks.core.Path;
9import com.framsticks.core.XmlBasedTest;
10import com.framsticks.remote.RemoteTree;
11
12import com.framsticks.test.TestClass;
13import com.framsticks.core.Tree;
14import com.framsticks.params.FramsClass;
15import com.framsticks.util.dispatching.Dispatching;
16import com.framsticks.params.AccessInterface;
17import com.framsticks.params.PrimitiveParam;
18import com.framsticks.params.PropertiesAccess;
19import com.framsticks.params.types.ProcedureParam;
20import com.framsticks.util.dispatching.Dispatching.Waiter;
21import com.framsticks.util.dispatching.FutureHandler;
22import com.framsticks.util.dispatching.RunAt;
23
24import static com.framsticks.core.TreeOperations.*;
25
26import static org.fest.assertions.Assertions.*;
27
28@Test
29public class ServerTest extends XmlBasedTest {
30
31        protected RemoteTree remote;
32        protected FramsClass remoteTestFramsClass;
33        protected Path remotePath;
34
35        protected Server server;
36        protected ObjectTree hosted;
37        protected TestClass hostedObject;
38
39        @Override
40        protected String getConfigurationName() {
41                return "ServerTest.xml";
42        }
43
44        @Test
45        public void runServer() {
46                assertThat(framsticks.size()).isEqualTo(2);
47                assertThat(framsticks.get("test")).isInstanceOf(Server.class);
48                assertThat(framsticks.get("remote")).isInstanceOf(RemoteTree.class);
49
50                server = (Server) framsticks.get("test");
51                remote = (RemoteTree) framsticks.get("remote");
52                assertThat(server.getHosted()).isInstanceOf(ObjectTree.class);
53                hosted = (ObjectTree) server.getHosted();
54                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
55                hostedObject = hosted.getRootObject(TestClass.class);
56        }
57
58        @Test(dependsOnMethods = "runServer")
59        public void fetchInfo() {
60                remote.dispatch(new RunAt<Tree>(failOnException) {
61                        @Override
62                        protected void runAt() {
63                                remote.info(Path.to(remote, "/"), new FutureHandler<FramsClass>(failOnException) {
64                                        @Override
65                                        protected void result(FramsClass result) {
66                                                remoteTestFramsClass = result;
67                                                assertThat(result.getId()).isEqualTo("TestClass");
68                                        }
69                                });
70                        }
71                });
72
73                Dispatching.synchronize(remote, 1.0);
74        }
75
76        @Test(dependsOnMethods = "fetchInfo")
77        public void resolveAndfetchRootObject() {
78                final Waiter waiter = produceWaiter(1.0);
79
80                remote.dispatch(new RunAt<Tree>(failOnException) {
81                        @Override
82                        protected void runAt() {
83                                final Path path = Path.to(remote, "/");
84                                assertThat(path.isResolved()).isFalse();
85
86                                remote.resolve(path, new FutureHandler<Path>(failOnException) {
87                                        @Override
88                                        protected void result(final Path result) {
89                                                assertThat(result.isResolved()).isTrue();
90                                                remotePath = result;
91                                                remote.get(result, Mode.FETCH, new FutureHandler<Object>(failOnException) {
92                                                        @Override
93                                                        protected void result(Object object) {
94                                                                AccessInterface access = bindAccess(result);
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                        }
103                });
104        }
105
106        @Test(dependsOnMethods = "resolveAndfetchRootObject")
107        public void setValueName() {
108                final Waiter waiter = produceWaiter(2.0);
109
110                set(remotePath, remoteTestFramsClass.getParamEntry("name", PrimitiveParam.class), "new name", new FutureHandler<Integer>(failOnException) {
111                        @Override
112                        protected void result(Integer flags) {
113                                // assertThat(flags).isEqualTo(0);
114                                /** And now check directly whether it was really set. */
115                                hosted.dispatch(new RunAt<Tree>(failOnException) {
116                                        @Override
117                                        protected void runAt() {
118                                                assertThat(hostedObject.getName()).isEqualTo("new name");
119                                                waiter.pass();
120                                        }
121                                });
122                        }
123                });
124        }
125
126        @Test(dependsOnMethods = "setValueName")
127        public void callMethod() {
128                final Waiter firstWaiter = produceWaiter(2.0);
129                final Waiter waiter = produceWaiter(2.0);
130
131                call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new FutureHandler<Object>(failOnException) {
132                        @Override
133                        protected void result(Object result) {
134                                firstWaiter.pass();
135                        }
136                });
137
138                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) {
139                        @Override
140                        protected void result(Object result) {
141                                hosted.dispatch(new RunAt<Tree>(failOnException) {
142                                        @Override
143                                        protected void runAt() {
144                                                assertThat(hostedObject.getHistory()).isEqualTo("next word|");
145                                                waiter.pass();
146                                        }
147                                });
148                        }
149                });
150
151        }
152
153        @Test(dependsOnMethods = "callMethod")
154        public void endWait() {
155                monitor.useFor(1.0);
156        }
157}
Note: See TracBrowser for help on using the repository browser.