1 | package com.framsticks.core; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | |
---|
5 | import org.testng.annotations.BeforeClass; |
---|
6 | // import org.testng.annotations.BeforeMethod; |
---|
7 | import org.testng.annotations.Test; |
---|
8 | |
---|
9 | import com.framsticks.model.Joint; |
---|
10 | import com.framsticks.model.Model; |
---|
11 | import com.framsticks.model.ModelBuilder; |
---|
12 | import com.framsticks.model.f0.Schema; |
---|
13 | import com.framsticks.model.f0.SchemaBuilder; |
---|
14 | import com.framsticks.structure.LocalTree; |
---|
15 | import com.framsticks.structure.Path; |
---|
16 | import com.framsticks.structure.Tree; |
---|
17 | import com.framsticks.structure.TreeOperations; |
---|
18 | import com.framsticks.test.TestConfiguration; |
---|
19 | import com.framsticks.util.dispatching.Dispatching; |
---|
20 | import com.framsticks.util.dispatching.Monitor; |
---|
21 | import com.framsticks.util.dispatching.RunAt; |
---|
22 | import com.framsticks.params.Access; |
---|
23 | import com.framsticks.params.ReflectionAccess; |
---|
24 | import com.framsticks.params.types.FloatParam; |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | import static org.fest.assertions.Assertions.*; |
---|
29 | import static com.framsticks.params.ParamsUtil.getParam; |
---|
30 | import static com.framsticks.structure.TreeOperations.*; |
---|
31 | |
---|
32 | @Test |
---|
33 | public 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 | } |
---|