1 | package com.framsticks.core; |
---|
2 | |
---|
3 | import java.util.Arrays; |
---|
4 | |
---|
5 | import org.testng.annotations.BeforeMethod; |
---|
6 | import org.testng.annotations.Test; |
---|
7 | |
---|
8 | import static com.framsticks.params.AccessOperations.*; |
---|
9 | import com.framsticks.params.FramsClass; |
---|
10 | import com.framsticks.params.ListSink; |
---|
11 | import com.framsticks.params.ListSource; |
---|
12 | import com.framsticks.params.ReflectionAccess; |
---|
13 | import com.framsticks.structure.messages.ListChange; |
---|
14 | import com.framsticks.structure.messages.ListChange.Action; |
---|
15 | import com.framsticks.test.TestConfiguration; |
---|
16 | |
---|
17 | import static org.fest.assertions.Assertions.*; |
---|
18 | |
---|
19 | @Test |
---|
20 | public class ListChangeTest extends TestConfiguration { |
---|
21 | |
---|
22 | FramsClass framsClass; |
---|
23 | ReflectionAccess access; |
---|
24 | ListChange listChange; |
---|
25 | |
---|
26 | @BeforeMethod |
---|
27 | public void clearListChange() { |
---|
28 | listChange = new ListChange(); |
---|
29 | } |
---|
30 | |
---|
31 | // @Test |
---|
32 | // public void testEnumBehaviour() { |
---|
33 | // for (Action a : Action.class.getEnumConstants()) { |
---|
34 | // // assertThat(Integer.class.cast(a)).isEqualTo(a.ordinal()); |
---|
35 | // assertThat(Action.class.cast(a.ordinal())).isEqualTo(a); |
---|
36 | // } |
---|
37 | |
---|
38 | // } |
---|
39 | |
---|
40 | @Test |
---|
41 | public void testFramsClass() { |
---|
42 | framsClass = FramsClass.build().forClass(ListChange.class); |
---|
43 | assertThat(framsClass.getParamCount()).isEqualTo(4); |
---|
44 | } |
---|
45 | |
---|
46 | @Test(dependsOnMethods = "testFramsClass") |
---|
47 | public void createReflectionAccess() { |
---|
48 | access = new ReflectionAccess(ListChange.class, framsClass); |
---|
49 | } |
---|
50 | |
---|
51 | @Test(dependsOnMethods = "createReflectionAccess") |
---|
52 | public void manualAccess() { |
---|
53 | access.select(listChange); |
---|
54 | |
---|
55 | access.set("type", 2); |
---|
56 | assertThat(listChange.action).isEqualTo(Action.Modify); |
---|
57 | |
---|
58 | listChange.action = Action.Remove; |
---|
59 | assertThat(access.get("type", Integer.class)).isEqualTo(1); |
---|
60 | } |
---|
61 | |
---|
62 | @Test(dependsOnMethods = "createReflectionAccess") |
---|
63 | public void loading() throws Exception { |
---|
64 | load(access.select(listChange), ListSource.createFrom("type:2", "pos:0", "id:test")); |
---|
65 | |
---|
66 | assertThat(listChange.action).isEqualTo(Action.Modify); |
---|
67 | assertThat(listChange.position).isEqualTo(0); |
---|
68 | assertThat(listChange.identifier).isEqualTo("test"); |
---|
69 | |
---|
70 | ListSink sink = new ListSink(); |
---|
71 | save(access.select(listChange), sink); |
---|
72 | assertThat(sink.getOut()).isEqualTo(Arrays.asList("ListChange:", "type:2", "pos:0", "id:test", "")); |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|