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

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

HIGHLIGHTS:

  • add auto loading and saving algorithms between

frams files format and Java classes

  • respect ValueChange? events in GUI (do not reload object)
  • support results of procedures in Java server
  • make Experiment automatically convert between frams file and NetFile? object
  • add MessageLogger? (compatible with original frams server messages)
  • WorkPackageLogic? now validates results, is able to discard them, reschedule

whole package, or only uncomputed remainder

CHANGELOG:
Show just a short description in PrimeExperiment?.

Add primes_changed event to the PrimeExperiment?.

Make WorkPackageLogic? robust to frams server returning invalid results.

Add MessageLogger? to logics.

Add NetFile? interface. Support Messages from server.

Minor changes to connections.

Merge results in the PrimeExperiment?.

More netload class->file conversion to Simulator.

Move netsave parsing to Simulator.

Fix bug with inverted ordering of events firing in Experiment.

Minor changes.

Minor logging changes.

Use AccessOperations?.convert in NetLoadSaveLogic?

NetLoadSaveLogic? now encloses the conversion.

Use more generic AccessOperations? saveAll and loadAll in PrimePackage?.

Add Result class for enclosing of call invocations' results.

Improve feature request handling in Connections.

Use AccessOperations?.convert in RemoteTree? events parsing.

Minor change.

Add some information params to Java server root and CLI objects.

A draft implementation of loadAll algorithm.

That algorithm tries to load objects into a tree structure.

Add AccessOperationsTest? test.

Develop WorkPackageLogic?.

  • add state tracking fields
  • add work package generation

Add utility class SimplePrimitive?.

Meant for Java backend classes, enclose a single primitive value
and set of listeners.

Improve primitive value refresh in GUI.

When ValueChange? found in called event, do not reload whole
object, but only update GUI (no communication is performed).

Use ValueChange? in the TestClass? test.

Minor changes.

Sending all packages in PrimeExperiment? to the frams servers.

Develop AccessOperations?.loadComposites().

Remove addAccess from MultiParamLoader? interface.

There is now no default AccessProvider? in MultiParamLoader?.
User must explicitely set AccessStash? or Registry.

Improve saving algorithms in AccessOperations?.

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.core.ValueChange;
9import com.framsticks.params.types.EventParam;
10import com.framsticks.params.types.ProcedureParam;
11import com.framsticks.params.types.StringParam;
12import com.framsticks.parsers.Savers;
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 ValueChange",
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<ValueChange> listener = new EventListener<ValueChange>() {
131
132                        @Override
133                        public void action(ValueChange argument) {
134                                called.set(argument.value.toString());
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.