- Timestamp:
- 07/10/13 22:41:02 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r98 r99 2 2 3 3 // import org.apache.log4j.Logger; 4 import java.util.Arrays; 5 import java.util.LinkedList; 6 import java.util.List; 7 4 8 import org.testng.annotations.Test; 5 9 6 import com.framsticks.core.Mode; 7 import com.framsticks.core.ObjectTree; 10 import com.framsticks.core.LocalTree; 8 11 import com.framsticks.core.Path; 12 import com.framsticks.core.TreeOperations; 9 13 import com.framsticks.core.XmlBasedTest; 10 14 import com.framsticks.remote.RemoteTree; 11 15 16 import com.framsticks.test.ChangeEvent; 12 17 import com.framsticks.test.TestClass; 13 18 import com.framsticks.core.Tree; 14 19 import com.framsticks.params.FramsClass; 15 import com.framsticks.util.dispatching.Dispatching;16 20 import com.framsticks.params.AccessInterface; 21 import com.framsticks.params.EventListener; 17 22 import com.framsticks.params.PrimitiveParam; 18 23 import com.framsticks.params.PropertiesAccess; 24 import com.framsticks.params.types.EventParam; 25 // import com.framsticks.params.types.EventParam; 19 26 import com.framsticks.params.types.ProcedureParam; 20 27 import com.framsticks.util.dispatching.Dispatching.Waiter; … … 34 41 35 42 protected Server server; 36 protected ObjectTree hosted;43 protected LocalTree hosted; 37 44 protected TestClass hostedObject; 45 protected EventListener<ChangeEvent> listener; 46 protected List<String> listenerArguments = new LinkedList<>(); 38 47 39 48 @Override … … 50 59 server = (Server) framsticks.get("test"); 51 60 remote = (RemoteTree) framsticks.get("remote"); 52 assertThat(server.getHosted()).isInstanceOf( ObjectTree.class);53 hosted = ( ObjectTree) server.getHosted();61 assertThat(server.getHosted()).isInstanceOf(LocalTree.class); 62 hosted = (LocalTree) server.getHosted(); 54 63 assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class); 55 64 hostedObject = hosted.getRootObject(TestClass.class); … … 58 67 @Test(dependsOnMethods = "runServer") 59 68 public void fetchInfo() { 60 remote.dispatch(new RunAt<Tree>(failOnException) { 69 final Waiter waiter = produceWaiter(1.0); 70 71 TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) { 61 72 @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 }); 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(); 70 78 } 71 79 }); 72 80 73 Dispatching.synchronize(remote, 1.0);74 81 } 75 82 … … 78 85 final Waiter waiter = produceWaiter(1.0); 79 86 80 remote.dispatch(new RunAt<Tree>(failOnException) {87 TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) { 81 88 @Override 82 protected void runAt() { 83 final Path path = Path.to(remote, "/"); 84 assertThat(path.isResolved()).isFalse(); 85 86 remote.get(path, Mode.FETCH, new FutureHandler<Path>(failOnException) { 87 @Override 88 protected void result(Path path) { 89 assertThat(path.isResolved()).isTrue(); 90 remotePath = path; 91 AccessInterface access = bindAccess(path); 92 assertThat(access).isInstanceOf(PropertiesAccess.class); 93 assertThat(access.get("name", String.class)).isEqualTo("a test name"); 94 waiter.pass(); 95 } 96 }); 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(); 97 96 } 98 97 }); … … 120 119 121 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") 122 142 public void callMethod() { 123 final Waiter firstWaiter = produceWaiter(2.0);124 143 final Waiter waiter = produceWaiter(2.0); 125 144 126 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new FutureHandler<Object>(failOnException) { 127 @Override 128 protected void result(Object result) { 129 firstWaiter.pass(); 130 } 131 }); 145 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, produceWaiter(2.0).passInFuture(Object.class)); 132 146 133 147 call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) { … … 143 157 } 144 158 }); 159 } 145 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|")); 146 167 } 147 168
Note: See TracChangeset
for help on using the changeset viewer.