source: java/main/src/test/java/com/framsticks/params/ParamsUtilTest.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: 2.6 KB
Line 
1package com.framsticks.params;
2
3import static org.fest.assertions.Assertions.*;
4
5import java.util.Arrays;
6import java.util.Map;
7import java.util.TreeMap;
8
9import org.testng.annotations.Test;
10
11import com.framsticks.params.AccessOperations;
12import com.framsticks.params.FramsClass;
13import com.framsticks.params.ListSink;
14import com.framsticks.params.ReflectionAccess;
15import com.framsticks.params.types.UniversalParam;
16import com.framsticks.parsers.Savers;
17import com.framsticks.test.TestConfiguration;
18import com.framsticks.test.TestSerializedClass;
19
20
21public class ParamsUtilTest extends TestConfiguration {
22
23        @Test
24        public void testSerialization() {
25                FramsClass framsClass;
26                ReflectionAccess access;
27
28                framsClass = FramsClass.build().forClass(TestSerializedClass.class);
29                assertThat(framsClass.getParamCount()).isEqualTo(1);
30                assertThat(framsClass.getParam("theArray")).isInstanceOf(UniversalParam.class);
31
32                access = new ReflectionAccess(TestSerializedClass.class, framsClass);
33
34                assertThat(Savers.saveFramsClass(new ListSink(), framsClass).getOut()).isEqualTo(
35                                Arrays.asList(
36                                        "class:",
37                                        "name:TestSerializedClass",
38                                        "id:TestSerializedClass",
39                                        "",
40                                        "prop:",
41                                        "id:theArray",
42                                        "name:TheArray",
43                                        "type:x",
44                                        ""
45                                )
46                        );
47
48                TestSerializedClass test = new TestSerializedClass();
49                test.getTheArray().add(1);
50                test.getTheArray().add(3.0);
51                test.getTheArray().add("word");
52
53                ListSink sink = new ListSink();
54                AccessOperations.savePrimitives(access.select(test), sink);
55                assertThat(sink.getOut()).isEqualTo(Arrays.asList(
56                                "TestSerializedClass:",
57                                "theArray:@Serialized:[1,3.0,\"word\"]",
58                                ""
59                        ));
60
61
62                assertThat(ParamsUtil.serialize("@Serialized:")).isEqualTo("@Serialized:\"@Serialized:\"");
63                assertThat(ParamsUtil.serialize(Arrays.asList(12, null, "abc"))).isEqualTo("@Serialized:[12,null,\"abc\"]");
64                assertThat(ParamsUtil.serialize(Arrays.asList(Arrays.asList(Arrays.asList())))).isEqualTo("@Serialized:[[[]]]");
65
66                Map<String, Object> f12 = new TreeMap<String, Object>();
67                f12.put("a", 123);
68                f12.put("b", Arrays.asList(7, 8, 9));
69                assertThat(ParamsUtil.serialize(f12)).isEqualTo("@Serialized:{\"a\":123,\"b\":[7,8,9]}");
70
71                // List<Object> f18 = new ArrayList<>();
72                // List<Object> f18_0 = new ArrayList<>();
73                // List<Object> f18_1 = Arrays.asList("x", f18);
74                // List<Object> f18_2 = new ArrayList<>();
75                // f18_2.add(f18_0);
76                // f18_0.add(f18_2);
77                // f18.add(f18_0);
78                // f18.add(f18_1);
79                // f18.add(f18_2);
80
81                // root[0] is f18_0
82                // root[0]==root[2][0], root[1][1]==root, root[1][1][1][1][0]=="x".
83
84                // assertThat(ParamsUtil.serialize(f18)).isEqualTo("@Serialized:[[^3],[\"x\",^0],[^1]]");
85
86        }
87
88}
Note: See TracBrowser for help on using the repository browser.