Changeset 99 for java/main/src/test
- Timestamp:
- 07/10/13 22:41:02 (11 years ago)
- Location:
- java/main/src/test
- Files:
-
- 3 added
- 3 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/test/java/com/framsticks/communication/RequestTest.java
r96 r99 7 7 import com.framsticks.communication.queries.GetRequest; 8 8 import com.framsticks.communication.queries.InfoRequest; 9 import com.framsticks.communication.queries.RegisterRequest; 9 10 import com.framsticks.communication.queries.SetRequest; 10 11 import com.framsticks.communication.queries.UseRequest; … … 46 47 { SetRequest.class, "set /test field value"}, 47 48 { SetRequest.class, "set /test field \"value with spaces\""}, 49 { RegisterRequest.class, "reg /test/field_changed"}, 48 50 { VersionRequest.class, "version 4"}, 49 51 { InfoRequest.class, "info /some/path"}, -
java/main/src/test/java/com/framsticks/core/PathTest.java
r87 r99 8 8 9 9 import org.testng.annotations.BeforeClass; 10 import org.testng.annotations.DataProvider; 10 11 import org.testng.annotations.Test; 11 12 12 13 import com.framsticks.test.TestConfiguration; 14 import com.framsticks.util.lang.Pair; 15 16 import static org.fest.assertions.Assertions.*; 13 17 14 18 @Test … … 25 29 } 26 30 27 @Test 28 public void testPath() { 31 @Test(dataProvider = "pathValidationProvider") 32 public void pathValidation(String path, boolean ok) { 33 assertThat(Path.isValidString(path)).describedAs(path).isEqualTo(ok); 34 } 35 36 @Test(dataProvider = "pathSplitingProvider") 37 public void pathSpliting(String path, String prefix, String suffix) { 38 Pair<String, String> p = Path.removeLastElement(path); 39 assertThat(p.first).isEqualTo(prefix); 40 assertThat(p.second).isEqualTo(suffix); 41 } 42 43 @DataProvider 44 public Object[][] pathValidationProvider() { 45 return new Object[][] { 46 { "/", true }, 47 { "/path", true }, 48 { "path", false }, 49 { "/path/to/", false }, 50 { "/path/to", true }, 51 { "/testClass/history_changed", true }, 52 { "/cli/events/e0", true } 53 54 }; 55 } 56 57 @DataProvider 58 public Object[][] pathSplitingProvider() { 59 return new Object[][] { 60 { "/event", "/", "event" }, 61 { "/path/event", "/path", "event" } 62 }; 29 63 } 30 64 -
java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java
r98 r99 50 50 protected void clickAndExpandPath(String path) { 51 51 tree.clickPath(path); 52 Dispatching.sleep( 1.0);52 Dispatching.sleep(2.0); 53 53 tree.expandPath(path); 54 54 robot.waitForIdle(); -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r98 r99 12 12 13 13 import com.framsticks.model.ModelPackage; 14 import com.framsticks.remote. SimulatorTree;14 import com.framsticks.remote.RemoteTree; 15 15 import com.framsticks.util.dispatching.Dispatching; 16 16 … … 19 19 private static final Logger log = Logger.getLogger(BrowserTest.class); 20 20 21 SimulatorTree localhost;21 RemoteTree localhost; 22 22 23 23 @Override … … 25 25 browser = new Browser(); 26 26 27 localhost = new SimulatorTree();27 localhost = new RemoteTree(); 28 28 localhost.setName("localhost"); 29 29 localhost.setAddress("localhost:9009"); … … 37 37 public void testShow() { 38 38 Dispatching.synchronize(localhost, 1.0); 39 // Dispatching.sleep(0.5);39 Dispatching.sleep(2.0); 40 40 log.info("testing"); 41 tree.clickRow(0).expandRow(0); 42 robot.waitForIdle(); 41 clickAndExpandPath("localhost"); 42 // tree.clickRow(0).expandRow(0); 43 // robot.waitForIdle(); 43 44 44 tree.clickRow(1).expandRow(1); 45 robot.waitForIdle(); 45 clickAndExpandPath("localhost/simulator"); 46 // tree.clickRow(1).expandRow(1); 47 // robot.waitForIdle(); 46 48 assertThat(tree.valueAt(1)).isEqualTo("simulator"); 47 49 robot.waitForIdle(); -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r97 r99 7 7 import org.testng.annotations.Test; 8 8 9 import com.framsticks.core.Path; 9 10 import com.framsticks.core.Tree; 10 import com.framsticks.core. ObjectTree;11 import com.framsticks.core.LocalTree; 11 12 import com.framsticks.params.AccessInterface; 13 import com.framsticks.params.EventListener; 12 14 import com.framsticks.params.FramsClass; 13 15 import com.framsticks.params.ReflectionAccess; 16 import com.framsticks.params.types.EventParam; 14 17 import com.framsticks.params.types.StringParam; 15 18 import com.framsticks.parsers.XmlLoader; 19 import com.framsticks.test.ChangeEvent; 16 20 import com.framsticks.test.TestClass; 21 import com.framsticks.util.dispatching.FutureHandler; 17 22 // import com.framsticks.util.dispatching.Dispatching; 18 23 import com.framsticks.util.dispatching.RunAt; … … 22 27 public class ProcedureBrowserTest extends BrowserBaseTest { 23 28 24 ObjectTree tree;29 LocalTree tree; 25 30 26 31 @Override … … 29 34 30 35 assertThat(browser.getTrees().size()).isEqualTo(1); 31 assertThat(browser.getTrees().get("test")).isInstanceOf( ObjectTree.class);36 assertThat(browser.getTrees().get("test")).isInstanceOf(LocalTree.class); 32 37 33 tree = ( ObjectTree) browser.getTrees().get("test");38 tree = (LocalTree) browser.getTrees().get("test"); 34 39 } 35 40 … … 60 65 assertThat(access).isInstanceOf(ReflectionAccess.class); 61 66 FramsClass framsClass = access.getFramsClass(); 62 assertThat(framsClass.getParamCount()).isEqualTo( 4);67 assertThat(framsClass.getParamCount()).isEqualTo(5); 63 68 assertThat(framsClass.getParam(0).getId()).isEqualTo("name"); 64 69 assertThat(framsClass.getParam(1).getId()).isEqualTo("history"); 65 assertThat(framsClass.getParam(2).getId()).isEqualTo("appendHistory"); 66 assertThat(framsClass.getParam(3).getId()).isEqualTo("resetHistory"); 70 assertThat(framsClass.getParam(2).getId()).isEqualTo("history_changed"); 71 assertThat(framsClass.getParam(3).getId()).isEqualTo("appendHistory"); 72 assertThat(framsClass.getParam(4).getId()).isEqualTo("resetHistory"); 67 73 68 74 assertThat(access.get("history", String.class)).isEqualTo("initial|"); … … 77 83 waitForIdle(); 78 84 85 final EventListener<ChangeEvent> listener = new EventListener<ChangeEvent>() { 86 87 @Override 88 public void action(ChangeEvent argument) { 89 assertThat(argument.history).isEqualTo(""); 90 } 91 }; 79 92 80 93 tree.dispatch(new RunAt<Tree>(failOnException) { 81 94 @Override 82 95 protected void runAt() { 83 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo("initial|Żółw|"); 96 AccessInterface access = bindAccess(tree, "/"); 97 assertThat(access.get("history", String.class)).isEqualTo("initial|Żółw|"); 98 99 tree.addListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, FutureHandler.doNothing(Void.class, failOnException)); 84 100 } 85 101 }); … … 91 107 @Override 92 108 protected void runAt() { 93 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo(""); 109 AccessInterface access = bindAccess(tree, "/"); 110 assertThat(access.get("history", String.class)).isEqualTo(""); 111 112 tree.removeListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, FutureHandler.doNothing(Void.class, failOnException)); 94 113 } 95 114 }); -
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 -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r97 r99 6 6 import org.testng.annotations.Test; 7 7 8 import com.framsticks.params.types.EventParam; 8 9 import com.framsticks.params.types.ProcedureParam; 9 10 import com.framsticks.params.types.StringParam; 10 11 import com.framsticks.parsers.Savers; 12 import com.framsticks.test.ChangeEvent; 11 13 import com.framsticks.test.TestClass; 12 14 import com.framsticks.test.TestConfiguration; 15 import com.framsticks.util.lang.Holder; 16 13 17 import static org.fest.assertions.Assertions.*; 14 18 … … 30 34 @Test 31 35 public void checkProcedureParams() { 32 assertThat(framsClass.getParamCount()).isEqualTo( 4);36 assertThat(framsClass.getParamCount()).isEqualTo(5); 33 37 34 38 assertThat(framsClass.getParam("name")).isInstanceOf(StringParam.class); 35 39 assertThat(framsClass.getParam("history")).isInstanceOf(StringParam.class); 40 assertThat(framsClass.getParam("history_changed")).isInstanceOf(EventParam.class); 36 41 37 42 assertThat(framsClass.getParam("appendHistory")).isInstanceOf(ProcedureParam.class); … … 62 67 "", 63 68 "prop:", 69 "id:history_changed", 70 "name:HistoryListener", 71 "type:e ChangeEvent", 72 "", 73 "prop:", 64 74 "id:appendHistory", 65 75 "name:AppendHistory", … … 75 85 } 76 86 87 @Test(dependsOnMethods = "print") 88 public void createAccess() { 89 access = new ReflectionAccess(TestClass.class, framsClass); 90 access.select(test); 91 } 77 92 78 @Test(dependsOnMethods = " print")93 @Test(dependsOnMethods = "createAccess") 79 94 public void callProcedures() { 80 access = new ReflectionAccess(TestClass.class, framsClass);81 82 access.select(test);83 95 84 96 assertThat(access.get("history", String.class)).isEqualTo("initial|first|"); … … 93 105 94 106 assertThat(access.get("history", String.class)).isEqualTo(""); 107 } 95 108 109 @Test(dependsOnMethods = "callProcedures") 110 public void listeners() { 111 112 final Holder<String> called = new Holder<>(); 113 114 final EventListener<ChangeEvent> listener = new EventListener<ChangeEvent>() { 115 116 @Override 117 public void action(ChangeEvent argument) { 118 called.set(argument.history); 119 } 120 }; 121 122 final EventParam eventParam = access.getFramsClass().getParamEntry("history_changed", EventParam.class); 123 access.reg(eventParam, listener); 124 125 final String currentHistory = access.get("history", String.class); 126 final String addition = "test"; 127 128 access.call("appendHistory", new Object[] { addition }); 129 130 String expected = currentHistory + addition + "|"; 131 assertThat(access.get("history", String.class)).isEqualTo(expected); 132 assertThat(called.get()).isEqualTo(expected); 133 access.regRemove(eventParam, listener); 96 134 } 97 135 -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r98 r99 17 17 import com.framsticks.util.dispatching.ExceptionResultHandler; 18 18 19 import static org.fest.assertions.Assertions.*;19 // import static org.fest.assertions.Assertions.*; 20 20 21 21 public class TestConfiguration { … … 31 31 private final List<AssertionError> asyncAssertions = new LinkedList<>(); 32 32 33 public static AssertionError wrapInAssertion(Throwable throwable) { 34 if (throwable instanceof AssertionError) { 35 return (AssertionError) throwable; 36 } 37 38 AssertionError ae = new AssertionError(); 39 ae.initCause(throwable); 40 return ae; 41 } 42 43 public void addAsyncAssertion(Throwable throwable) { 44 synchronized (asyncAssertions) { 45 asyncAssertions.add(wrapInAssertion(throwable)); 46 } 47 } 48 33 49 public ExceptionHandler createExceptionHandler() { 34 50 return new ExceptionHandler() { 35 51 @Override 36 52 public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) { 37 AssertionError ae; 38 if (AssertionError.class.isInstance(throwable)) { 39 ae = AssertionError.class.cast(throwable); 40 } else { 41 ae = new AssertionError(); 42 ae.initCause(throwable); 43 } 44 synchronized (asyncAssertions) { 45 asyncAssertions.add(ae); 46 } 53 addAsyncAssertion(throwable); 47 54 return true; 48 55 } … … 83 90 84 91 protected Dispatching.Waiter produceWaiter(double timeOut) { 85 Waiter waiter = new Waiter(timeOut );92 Waiter waiter = new Waiter(timeOut, failOnException); 86 93 waiters.add(waiter); 87 94 return waiter; 88 95 } 89 96 90 public staticfinal ExceptionResultHandler failOnException = new ExceptionResultHandler() {97 public final ExceptionResultHandler failOnException = new ExceptionResultHandler() { 91 98 @Override 92 99 public void handle(FramsticksException e) { 93 e.printStackTrace();94 a ssertThat(e).isNull();100 log.error("passing exception as assertion in " + TestConfiguration.this.getClass(), e); 101 addAsyncAssertion(e); 95 102 } 96 103 }; -
java/main/src/test/resources/configs/ProcedureBrowserTest.xml
r97 r99 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Browser> 3 <import class="com.framsticks.core. ObjectTree" />3 <import class="com.framsticks.core.LocalTree" /> 4 4 <import class="com.framsticks.test.TestClass" /> 5 < ObjectTree name="test">5 <LocalTree name="test"> 6 6 <TestClass /> 7 </ ObjectTree>7 </LocalTree> 8 8 </Browser> -
java/main/src/test/resources/configs/ServerTest.xml
r97 r99 3 3 <import class="com.framsticks.hosting.Server" /> 4 4 <import class="com.framsticks.remote.RemoteTree" /> 5 <import class="com.framsticks.core. ObjectTree" />5 <import class="com.framsticks.core.LocalTree" /> 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 8 <Server name="server" port="9007"> 9 < ObjectTree name="test">9 <LocalTree name="test"> 10 10 <TestClass name="a test name" /> 11 </ ObjectTree>11 </LocalTree> 12 12 </Server> 13 13 <RemoteTree name="remote" address="localhost:9007" /> -
java/main/src/test/resources/configs/test.xml
r97 r99 2 2 <Framsticks> 3 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote. SimulatorTree" />4 <import class="com.framsticks.remote.RemoteTree" /> 5 5 <Browser name="browser"> 6 < SimulatorTree name="localhost:9009" address="localhost:9009" />6 <RemoteTree name="localhost:9009" address="localhost:9009" /> 7 7 </Browser> 8 8 </Framsticks> -
java/main/src/test/resources/log4j.properties
r98 r99 28 28 log4j.logger.com.framsticks=WARN 29 29 log4j.logger.com.framsticks.test.TestConfiguration=INFO 30 # log4j.logger.com.framsticks. core.TreeOperations=DEBUG30 # log4j.logger.com.framsticks.hosting.Cli=DEBUG 31 31 # log4j.logger.com.framsticks.core.AbstractTree=DEBUG 32 32 # log4j.logger.com.framsticks.remote.RemoteTree=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.