source: java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java @ 101

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

HIGHLIGHTS:

  • improve tree side notes
  • improve GUI layout
  • add foldable list of occured events to EventControl?
  • improve automatic type conversion in proxy listeners
  • implement several Access functionalities as algorithms independent of Access type
  • introduce draft base classes for distributed experiments
  • automatically register dependant Java classes to FramsClass? registry
  • add testing prime experiment and configuration
  • simplify and improve task dispatching

CHANGELOG:
Improve task dispatching in RemoteTree?.

GUI no longer hangs on connection problems.

Make all dispatchers joinables.

Refactorize Thread dispatcher.

Remove Task and PeriodicTask?.

Use Java utilities in those situations.

Reworking tasks dispatching.

Fix bug in EventControl? listener dispatching.

Minor improvements.

Add testing configuration for ExternalProcess? in GUI.

More improvement to prime.

Support for USERREADONLY in GUI.

Add that flag to various params in Java classes.

Remove redundant register clauses from several FramsClassAnnotations?.

Automatically gather and register dependant classes.

Add configuration for prime.

Improve Simulator class.

Add prime.xml configuration.

Introduce draft Experiment and Simulator classes.

Add prime experiment tests.

Enclose typical map with listeners into SimpleUniqueList?.

Needfile works in GUI.

Improve needfile handling in Browser.

More improvement with NeedFile?.

Implementing needfile.

Update test.

Rename ChangeEvent? to TestChangeEvent?.

Automatic argument type search in RemoteTree? listeners.

MultiParamLoader? uses AccessProvider?. By default old implementation
enclosed in AccessStash? or Registry.

Minor changes.

Rename SourceInterface? to Source.

Also improve toString of File and ListSource?.

Remove unused SimpleSource? class.

Add clearing in HistoryControl?.

Show entries in table at EventControl?.

Improve EventControl?.

Add listeners registration to EventControl?.

Add foldable table to HistoryControl?.

Add control row to Procedure and Event controls.

Improve layout of controls.

Another minor change to gui layout.

Minor improvement in the SliderControl?.

Minor changes.

Move ReflectionAccess?.Backend to separate file.

It was to cluttered.

Cleanup in ReflectionAccess?.

Move setMin, setMax, setDef to AccessOperations?.

Extract loading operation into AccessOperations?.

Append Framsticks to name of UnsupportedOperationException?.

The java.lang.UnsupportedOperationException? was shadowing this class.

Rename params.Util to params.ParamsUtil?.

Several improvements.

Minor changes.

Implement revert functionality.

Improve local changes management.

Minor improvement.

Remove methods rendered superfluous after SideNoteKey? improvement.

Improve SideNoteKey?.

It is now generic type, so explicit type specification at
call site is no more needed.

Introduce SideNoteKey? interface.

Only Objects implementing that key may be used as side note keys.

Minor improvements.

Use strings instead of ValueControls? in several gui mappings.

File size: 4.1 KB
Line 
1package com.framsticks.params;
2
3import java.util.Arrays;
4
5import org.testng.annotations.BeforeClass;
6import org.testng.annotations.Test;
7
8import com.framsticks.params.types.EventParam;
9import com.framsticks.params.types.ProcedureParam;
10import com.framsticks.params.types.StringParam;
11import com.framsticks.parsers.Savers;
12import com.framsticks.test.TestChangeEvent;
13import com.framsticks.test.TestClass;
14import com.framsticks.test.TestConfiguration;
15import com.framsticks.util.lang.Holder;
16
17import static org.fest.assertions.Assertions.*;
18
19@Test
20public class FramsClassBuilderTest extends TestConfiguration {
21
22        FramsClass framsClass;
23        ReflectionAccess access;
24        TestClass test;
25
26        @BeforeClass
27        public void setUp() {
28                test = new TestClass();
29                test.setName("test");
30                test.appendHistory("first");
31                framsClass = FramsClass.build().forClass(TestClass.class);
32        }
33
34        @Test
35        public void checkProcedureParams() {
36                assertThat(framsClass.getParamCount()).isEqualTo(8);
37
38                assertThat(framsClass.getParam("name")).isInstanceOf(StringParam.class);
39                assertThat(framsClass.getParam("history")).isInstanceOf(StringParam.class);
40                assertThat(framsClass.getParam("history_changed")).isInstanceOf(EventParam.class);
41
42                assertThat(framsClass.getParam("appendHistory")).isInstanceOf(ProcedureParam.class);
43                assertThat(framsClass.getParam("resetHistory")).isInstanceOf(ProcedureParam.class);
44
45                ProcedureParam appendHistory = framsClass.getParamEntry("appendHistory", ProcedureParam.class);
46                assertThat(appendHistory.getArgumentsType().size()).isEqualTo(1);
47                assertThat(appendHistory.getArgumentsType().get(0).getId()).isEqualTo("arg0");
48        }
49
50        @Test(dependsOnMethods = "checkProcedureParams")
51        public void print() {
52                assertThat(Savers.saveFramsClass(new ListSink(), framsClass).getOut()).isEqualTo(
53                                Arrays.asList(
54                                        "class:",
55                                        "name:TestClass",
56                                        "id:TestClass",
57                                        "",
58                                        "prop:",
59                                        "id:name",
60                                        "name:Name",
61                                        "type:s",
62                                        "",
63                                        "prop:",
64                                        "id:history",
65                                        "name:History",
66                                        "type:s",
67                                        "",
68                                        "prop:",
69                                        "id:history_changed",
70                                        "name:HistoryListener",
71                                        "type:e TestChangeEvent",
72                                        "",
73                                        "prop:",
74                                        "id:appendHistory",
75                                        "name:AppendHistory",
76                                        "type:p d(s arg0)",
77                                        "",
78                                        "prop:",
79                                        "id:resetHistory",
80                                        "name:ResetHistory",
81                                        "type:p()",
82                                        "",
83                                        "prop:",
84                                        "id:children",
85                                        "name:Children",
86                                        "type:l TestChild uid",
87                                        "flags:1",
88                                        "",
89                                        "prop:",
90                                        "id:createChild",
91                                        "name:CreateChild",
92                                        "type:p(s arg0)",
93                                        "",
94                                        "prop:",
95                                        "id:children_changed",
96                                        "name:ChildrenListener",
97                                        "type:e ListChange",
98                                        ""
99                                )
100                        );
101        }
102
103        @Test(dependsOnMethods = "print")
104        public void createAccess() {
105                access = new ReflectionAccess(TestClass.class, framsClass);
106                access.select(test);
107        }
108
109        @Test(dependsOnMethods = "createAccess")
110        public void callProcedures() {
111
112                assertThat(access.get("history", String.class)).isEqualTo("initial|first|");
113                Object result = access.call("appendHistory", new Object[] {"second"});
114
115                assertThat(result).isInstanceOf(Integer.class);
116                assertThat(result).isEqualTo(21);
117                assertThat(access.get("history", String.class)).isEqualTo("initial|first|second|");
118
119                result = access.call("resetHistory", null);
120                assertThat(result).isNull();
121
122                assertThat(access.get("history", String.class)).isEqualTo("");
123        }
124
125        @Test(dependsOnMethods = "callProcedures")
126        public void listeners() {
127
128                final Holder<String> called = new Holder<>();
129
130                final EventListener<TestChangeEvent> listener = new EventListener<TestChangeEvent>() {
131
132                        @Override
133                        public void action(TestChangeEvent argument) {
134                                called.set(argument.history);
135                        }
136                };
137
138                final EventParam eventParam = access.getFramsClass().getParamEntry("history_changed", EventParam.class);
139                access.reg(eventParam, listener);
140
141                final String currentHistory = access.get("history", String.class);
142                final String addition = "test";
143
144                access.call("appendHistory", new Object[] { addition });
145
146                String expected = currentHistory + addition + "|";
147                assertThat(access.get("history", String.class)).isEqualTo(expected);
148                assertThat(called.get()).isEqualTo(expected);
149                access.regRemove(eventParam, listener);
150        }
151
152}
Note: See TracBrowser for help on using the repository browser.