Changeset 99 for java/main/src/test/java


Ignore:
Timestamp:
07/10/13 22:41:02 (11 years ago)
Author:
psniegowski
Message:

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.

Location:
java/main/src/test/java/com/framsticks
Files:
2 added
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/test/java/com/framsticks/communication/RequestTest.java

    r96 r99  
    77import com.framsticks.communication.queries.GetRequest;
    88import com.framsticks.communication.queries.InfoRequest;
     9import com.framsticks.communication.queries.RegisterRequest;
    910import com.framsticks.communication.queries.SetRequest;
    1011import com.framsticks.communication.queries.UseRequest;
     
    4647                        { SetRequest.class, "set /test field value"},
    4748                        { SetRequest.class, "set /test field \"value with spaces\""},
     49                        { RegisterRequest.class, "reg /test/field_changed"},
    4850                        { VersionRequest.class, "version 4"},
    4951                        { InfoRequest.class, "info /some/path"},
  • java/main/src/test/java/com/framsticks/core/PathTest.java

    r87 r99  
    88
    99import org.testng.annotations.BeforeClass;
     10import org.testng.annotations.DataProvider;
    1011import org.testng.annotations.Test;
    1112
    1213import com.framsticks.test.TestConfiguration;
     14import com.framsticks.util.lang.Pair;
     15
     16import static org.fest.assertions.Assertions.*;
    1317
    1418@Test
     
    2529        }
    2630
    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                };
    2963        }
    3064
  • java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java

    r98 r99  
    5050        protected void clickAndExpandPath(String path) {
    5151                tree.clickPath(path);
    52                 Dispatching.sleep(1.0);
     52                Dispatching.sleep(2.0);
    5353                tree.expandPath(path);
    5454                robot.waitForIdle();
  • java/main/src/test/java/com/framsticks/gui/BrowserTest.java

    r98 r99  
    1212
    1313import com.framsticks.model.ModelPackage;
    14 import com.framsticks.remote.SimulatorTree;
     14import com.framsticks.remote.RemoteTree;
    1515import com.framsticks.util.dispatching.Dispatching;
    1616
     
    1919        private static final Logger log = Logger.getLogger(BrowserTest.class);
    2020
    21         SimulatorTree localhost;
     21        RemoteTree localhost;
    2222
    2323        @Override
     
    2525                browser = new Browser();
    2626
    27                 localhost = new SimulatorTree();
     27                localhost = new RemoteTree();
    2828                localhost.setName("localhost");
    2929                localhost.setAddress("localhost:9009");
     
    3737        public void testShow() {
    3838                Dispatching.synchronize(localhost, 1.0);
    39                 // Dispatching.sleep(0.5);
     39                Dispatching.sleep(2.0);
    4040                log.info("testing");
    41                 tree.clickRow(0).expandRow(0);
    42                 robot.waitForIdle();
     41                clickAndExpandPath("localhost");
     42                // tree.clickRow(0).expandRow(0);
     43                // robot.waitForIdle();
    4344
    44                 tree.clickRow(1).expandRow(1);
    45                 robot.waitForIdle();
     45                clickAndExpandPath("localhost/simulator");
     46                // tree.clickRow(1).expandRow(1);
     47                // robot.waitForIdle();
    4648                assertThat(tree.valueAt(1)).isEqualTo("simulator");
    4749                robot.waitForIdle();
  • java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java

    r97 r99  
    77import org.testng.annotations.Test;
    88
     9import com.framsticks.core.Path;
    910import com.framsticks.core.Tree;
    10 import com.framsticks.core.ObjectTree;
     11import com.framsticks.core.LocalTree;
    1112import com.framsticks.params.AccessInterface;
     13import com.framsticks.params.EventListener;
    1214import com.framsticks.params.FramsClass;
    1315import com.framsticks.params.ReflectionAccess;
     16import com.framsticks.params.types.EventParam;
    1417import com.framsticks.params.types.StringParam;
    1518import com.framsticks.parsers.XmlLoader;
     19import com.framsticks.test.ChangeEvent;
    1620import com.framsticks.test.TestClass;
     21import com.framsticks.util.dispatching.FutureHandler;
    1722// import com.framsticks.util.dispatching.Dispatching;
    1823import com.framsticks.util.dispatching.RunAt;
     
    2227public class ProcedureBrowserTest extends BrowserBaseTest {
    2328
    24         ObjectTree tree;
     29        LocalTree tree;
    2530
    2631        @Override
     
    2934
    3035                assertThat(browser.getTrees().size()).isEqualTo(1);
    31                 assertThat(browser.getTrees().get("test")).isInstanceOf(ObjectTree.class);
     36                assertThat(browser.getTrees().get("test")).isInstanceOf(LocalTree.class);
    3237
    33                 tree = (ObjectTree) browser.getTrees().get("test");
     38                tree = (LocalTree) browser.getTrees().get("test");
    3439        }
    3540
     
    6065                                assertThat(access).isInstanceOf(ReflectionAccess.class);
    6166                                FramsClass framsClass = access.getFramsClass();
    62                                 assertThat(framsClass.getParamCount()).isEqualTo(4);
     67                                assertThat(framsClass.getParamCount()).isEqualTo(5);
    6368                                assertThat(framsClass.getParam(0).getId()).isEqualTo("name");
    6469                                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");
    6773
    6874                                assertThat(access.get("history", String.class)).isEqualTo("initial|");
     
    7783                waitForIdle();
    7884
     85                final EventListener<ChangeEvent> listener = new EventListener<ChangeEvent>() {
     86
     87                        @Override
     88                        public void action(ChangeEvent argument) {
     89                                assertThat(argument.history).isEqualTo("");
     90                        }
     91                };
    7992
    8093                tree.dispatch(new RunAt<Tree>(failOnException) {
    8194                        @Override
    8295                        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));
    84100                        }
    85101                });
     
    91107                        @Override
    92108                        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));
    94113                        }
    95114                });
  • java/main/src/test/java/com/framsticks/hosting/ServerTest.java

    r98 r99  
    22
    33// import org.apache.log4j.Logger;
     4import java.util.Arrays;
     5import java.util.LinkedList;
     6import java.util.List;
     7
    48import org.testng.annotations.Test;
    59
    6 import com.framsticks.core.Mode;
    7 import com.framsticks.core.ObjectTree;
     10import com.framsticks.core.LocalTree;
    811import com.framsticks.core.Path;
     12import com.framsticks.core.TreeOperations;
    913import com.framsticks.core.XmlBasedTest;
    1014import com.framsticks.remote.RemoteTree;
    1115
     16import com.framsticks.test.ChangeEvent;
    1217import com.framsticks.test.TestClass;
    1318import com.framsticks.core.Tree;
    1419import com.framsticks.params.FramsClass;
    15 import com.framsticks.util.dispatching.Dispatching;
    1620import com.framsticks.params.AccessInterface;
     21import com.framsticks.params.EventListener;
    1722import com.framsticks.params.PrimitiveParam;
    1823import com.framsticks.params.PropertiesAccess;
     24import com.framsticks.params.types.EventParam;
     25// import com.framsticks.params.types.EventParam;
    1926import com.framsticks.params.types.ProcedureParam;
    2027import com.framsticks.util.dispatching.Dispatching.Waiter;
     
    3441
    3542        protected Server server;
    36         protected ObjectTree hosted;
     43        protected LocalTree hosted;
    3744        protected TestClass hostedObject;
     45        protected EventListener<ChangeEvent> listener;
     46        protected List<String> listenerArguments = new LinkedList<>();
    3847
    3948        @Override
     
    5059                server = (Server) framsticks.get("test");
    5160                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();
    5463                assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class);
    5564                hostedObject = hosted.getRootObject(TestClass.class);
     
    5867        @Test(dependsOnMethods = "runServer")
    5968        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) {
    6172                        @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();
    7078                        }
    7179                });
    7280
    73                 Dispatching.synchronize(remote, 1.0);
    7481        }
    7582
     
    7885                final Waiter waiter = produceWaiter(1.0);
    7986
    80                 remote.dispatch(new RunAt<Tree>(failOnException) {
     87                TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) {
    8188                        @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();
    9796                        }
    9897                });
     
    120119
    121120        @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")
    122142        public void callMethod() {
    123                 final Waiter firstWaiter = produceWaiter(2.0);
    124143                final Waiter waiter = produceWaiter(2.0);
    125144
    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));
    132146
    133147                call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) {
     
    143157                        }
    144158                });
     159        }
    145160
     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|"));
    146167        }
    147168
  • java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java

    r97 r99  
    66import org.testng.annotations.Test;
    77
     8import com.framsticks.params.types.EventParam;
    89import com.framsticks.params.types.ProcedureParam;
    910import com.framsticks.params.types.StringParam;
    1011import com.framsticks.parsers.Savers;
     12import com.framsticks.test.ChangeEvent;
    1113import com.framsticks.test.TestClass;
    1214import com.framsticks.test.TestConfiguration;
     15import com.framsticks.util.lang.Holder;
     16
    1317import static org.fest.assertions.Assertions.*;
    1418
     
    3034        @Test
    3135        public void checkProcedureParams() {
    32                 assertThat(framsClass.getParamCount()).isEqualTo(4);
     36                assertThat(framsClass.getParamCount()).isEqualTo(5);
    3337
    3438                assertThat(framsClass.getParam("name")).isInstanceOf(StringParam.class);
    3539                assertThat(framsClass.getParam("history")).isInstanceOf(StringParam.class);
     40                assertThat(framsClass.getParam("history_changed")).isInstanceOf(EventParam.class);
    3641
    3742                assertThat(framsClass.getParam("appendHistory")).isInstanceOf(ProcedureParam.class);
     
    6267                                        "",
    6368                                        "prop:",
     69                                        "id:history_changed",
     70                                        "name:HistoryListener",
     71                                        "type:e ChangeEvent",
     72                                        "",
     73                                        "prop:",
    6474                                        "id:appendHistory",
    6575                                        "name:AppendHistory",
     
    7585        }
    7686
     87        @Test(dependsOnMethods = "print")
     88        public void createAccess() {
     89                access = new ReflectionAccess(TestClass.class, framsClass);
     90                access.select(test);
     91        }
    7792
    78         @Test(dependsOnMethods = "print")
     93        @Test(dependsOnMethods = "createAccess")
    7994        public void callProcedures() {
    80                 access = new ReflectionAccess(TestClass.class, framsClass);
    81 
    82                 access.select(test);
    8395
    8496                assertThat(access.get("history", String.class)).isEqualTo("initial|first|");
     
    93105
    94106                assertThat(access.get("history", String.class)).isEqualTo("");
     107        }
    95108
     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);
    96134        }
    97135
  • java/main/src/test/java/com/framsticks/test/TestConfiguration.java

    r98 r99  
    1717import com.framsticks.util.dispatching.ExceptionResultHandler;
    1818
    19 import static org.fest.assertions.Assertions.*;
     19// import static org.fest.assertions.Assertions.*;
    2020
    2121public class TestConfiguration {
     
    3131        private final List<AssertionError> asyncAssertions = new LinkedList<>();
    3232
     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
    3349        public ExceptionHandler createExceptionHandler() {
    3450                return new ExceptionHandler() {
    3551                        @Override
    3652                        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);
    4754                                return true;
    4855                        }
     
    8390
    8491        protected Dispatching.Waiter produceWaiter(double timeOut) {
    85                 Waiter waiter = new Waiter(timeOut);
     92                Waiter waiter = new Waiter(timeOut, failOnException);
    8693                waiters.add(waiter);
    8794                return waiter;
    8895        }
    8996
    90         public static final ExceptionResultHandler failOnException = new ExceptionResultHandler() {
     97        public final ExceptionResultHandler failOnException = new ExceptionResultHandler() {
    9198                @Override
    9299                public void handle(FramsticksException e) {
    93                         e.printStackTrace();
    94                         assertThat(e).isNull();
     100                        log.error("passing exception as assertion in " + TestConfiguration.this.getClass(), e);
     101                        addAsyncAssertion(e);
    95102                }
    96103        };
Note: See TracChangeset for help on using the changeset viewer.