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

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

HIGHLIGHTS:

  • import refactorization: move Tree, Path, etc.

from core to structure package

  • initial serialization implementation
  • improve PrimeExperiment? test
  • many organizational changes and convenience improvements

CHANGELOG:
Make registry in AbstractTree? final.

Move most classes from core to structure package.

Minor changes.

Switch names of Future and FutureHandler?.

Rename ExceptionResultHandler? to ExceptionHandler?.

Rename ExceptionHandler? to ExceptionDispatcherHandler?.

Fix bug in ParamCandidate? cache.

Add missing synchronization to the BufferedDispatcher?.

Develop @Serialized support.

Rework serialization further.

Add serialization/deserialization interface to ValueParam?.

Move getStorageType and isNumeric from Param down to params hierarchy.

Minor changes.

Improve param type induction.

Add TestSerializedClass? for testing new serialization.

Add info files gor GenePool? and Population.

Add standard.expt exemplary netfile.

Add type name field to PropertiesObject?.

Use PropertiesObject? for PropertiesAccess? instead of ordinary map.

Hide getFramsClass is several more places.

More unification accross FramsClass?, Access and Path.

Add ParamCollection?.

Simplify interface for getting params from FramsClass?, Access
or Path.

Make Access.call() interface variadic.

Add arguments(args) convenience wrapper around new Object[] {args}.

Upgrade to apache.commons.lang version 3.1

Minor improvement with Response constructors.

Develop proper result printing in ClientAtServer?.

Add experimentNetsave to PrimeExperiment?.

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