source: java/main/src/test/java/com/framsticks/core/LocalTreeTest.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: 3.2 KB
Line 
1package com.framsticks.core;
2
3import java.util.ArrayList;
4
5import org.testng.annotations.BeforeClass;
6// import org.testng.annotations.BeforeMethod;
7import org.testng.annotations.Test;
8
9import com.framsticks.model.Joint;
10import com.framsticks.model.Model;
11import com.framsticks.model.ModelBuilder;
12import com.framsticks.model.f0.Schema;
13import com.framsticks.model.f0.SchemaBuilder;
14import com.framsticks.structure.LocalTree;
15import com.framsticks.structure.Path;
16import com.framsticks.structure.Tree;
17import com.framsticks.structure.TreeOperations;
18import com.framsticks.test.TestConfiguration;
19import com.framsticks.util.dispatching.Dispatching;
20import com.framsticks.util.dispatching.Monitor;
21import com.framsticks.util.dispatching.RunAt;
22import com.framsticks.params.Access;
23import com.framsticks.params.ReflectionAccess;
24import com.framsticks.params.types.FloatParam;
25
26
27
28import static org.fest.assertions.Assertions.*;
29import static com.framsticks.params.ParamsUtil.getParam;
30import static com.framsticks.structure.TreeOperations.*;
31
32@Test
33public class LocalTreeTest extends TestConfiguration {
34
35        private Model model;
36        private Schema schema;
37        private LocalTree tree;
38        private Monitor monitor;
39
40        @BeforeClass
41        public void setUp() {
42                schema = new SchemaBuilder().stream(Schema.getDefaultDefinitionAsStream()).finish();
43                assertThat(schema.getFramsClasses().size()).isEqualTo(5);
44                assertThat(schema.getNeuroClasses().size()).isEqualTo(21);
45        }
46
47        @Test
48        public void loadModel() {
49                model = new ModelBuilder().schema(schema).stream(LocalTreeTest.class.getResourceAsStream("/parsers/f0_example.txt")).finish();
50
51                assertThat(model.getJoints().size()).isEqualTo(2);
52        }
53
54
55        @Test(dependsOnMethods = "loadModel", timeOut = 2000)
56        public void startTree() {
57                tree = new LocalTree();
58                tree.takeAllFrom(schema.getRegistry());
59
60                tree.setRootObject(model);
61
62                monitor = new Monitor(tree);
63                monitor.use();
64
65                assertThat(Dispatching.get(tree, new Dispatching.QueryHandler<String>(failOnException) {
66                                @Override
67                                public String get() {
68                                        return tree.getRootObject(Model.class).getParts().get(2).info;
69                                }
70                        })).isEqualTo("bla");
71
72                tree.dispatch(new RunAt<Tree>(failOnException) {
73                        @Override
74                        protected void runAt() {
75                                assertThat(tree.getRootObject(Model.class).getNeuroDefinitions().get(2).details).isEqualTo("G");
76
77                                Path path = Path.to(tree, "/");
78                                assertThat(path.isResolved());
79                                Access access = TreeOperations.bindAccess(path);
80                                assertThat(access.get("se", Double.class)).isEqualTo(1.0);
81
82                                assertThat(getParam(bindAccess(tree, "/parts/2"), "m", FloatParam.class).getDef(Double.class)).isEqualTo(1.0);
83                                assertThat(getParam(bindAccess(tree, "/parts/2"), "m", FloatParam.class).getMax(Double.class)).isEqualTo(999.0);
84                                assertThat(bindAccess(tree, "/parts/2")).isInstanceOf(ReflectionAccess.class);
85                                assertThat(Path.to(tree, "/neurodefs").getTopObject()).isInstanceOf(ArrayList.class);
86                                assertThat(Path.to(tree, "/joints/1").getTopObject()).isInstanceOf(Joint.class);
87                                assertThat(bindAccess(tree, "/parts/2").get("i", String.class)).isEqualTo("bla");
88                        }
89                });
90
91        }
92
93        @Test(dependsOnMethods = "startTree", timeOut = 2000)
94        public void stopTree() {
95                monitor.useFor(1.0).drop().join();
96        }
97}
Note: See TracBrowser for help on using the repository browser.