Mercurial > hg > Members > shoshi > TreeCMSv2
comparison src/treecms/test/TreeEditorTest.java @ 6:12604eb6b615
added javadoc
author | shoshi |
---|---|
date | Mon, 14 Mar 2011 23:24:38 +0900 |
parents | 87bba22e4fa2 |
children |
comparison
equal
deleted
inserted
replaced
5:87bba22e4fa2 | 6:12604eb6b615 |
---|---|
1 package treecms.test; | 1 package treecms.test; |
2 | 2 |
3 import java.util.List; | |
4 import java.util.LinkedList; | |
5 | |
6 import junit.framework.Assert; | |
7 | |
8 import org.junit.Before; | |
3 import org.junit.Test; | 9 import org.junit.Test; |
4 | 10 import treecms.api.Forest; |
11 import treecms.api.Node; | |
12 import treecms.api.NodeID; | |
5 import treecms.api.Tree; | 13 import treecms.api.Tree; |
6 import treecms.api.TreeEditor; | 14 import treecms.api.TreeEditor; |
15 import treecms.tree.util.NodePathFinder; | |
7 | 16 |
8 public class TreeEditorTest | 17 public class TreeEditorTest |
9 { | 18 { |
10 Tree m_tree; | 19 Tree m_tree; |
11 TreeEditor m_editor; | 20 TreeEditor m_editor; |
12 | 21 |
22 Node root,ch1,ch2,ch11,ch21,ch22,ch223,cloned; | |
23 | |
13 public TreeEditorTest(TreeEditor _editor,Tree _tree) | 24 public TreeEditorTest(TreeEditor _editor,Tree _tree) |
14 { | 25 { |
15 m_editor = _editor; | 26 m_editor = _editor; |
16 m_tree = _tree; | 27 m_tree = _tree; |
28 | |
29 Forest forest = m_editor.getForest(); | |
30 root = m_editor.getRoot(); | |
31 | |
32 ch1 = forest.create(); | |
33 ch2 = forest.create(); | |
34 ch11 = forest.create(); | |
35 ch21 = forest.create(); | |
36 ch22 = forest.create(); | |
37 ch223 = forest.create(); //target | |
38 | |
39 LinkedList<Node> rootChildren = new LinkedList<Node>(); | |
40 rootChildren.add(ch1); | |
41 rootChildren.add(ch2); | |
42 root.getData().add(rootChildren); | |
43 | |
44 ch1.getData().add(ch11); | |
45 | |
46 LinkedList<Node> ch2Children = new LinkedList<Node>(); | |
47 ch2Children.add(ch21); | |
48 ch2Children.add(ch22); | |
49 ch2.getData().add(ch2Children); | |
50 | |
51 ch22.getData().add(ch223); | |
52 | |
53 //Edit | |
54 cloned = m_editor.updateTree(ch223,ch223.getData()); | |
17 } | 55 } |
18 | 56 |
19 @Test | 57 @Test |
20 public void testEdit() | 58 public void testEdit() |
21 { | 59 { |
60 NodePathFinder oldPath = new NodePathFinder(root,ch223); | |
61 NodePathFinder newPath = new NodePathFinder(m_editor.getRoot(),cloned); | |
62 List<Node> oldPathList = oldPath.list(); | |
63 List<Node> newPathList = newPath.list(); | |
22 | 64 |
65 //compare | |
66 for(int i = 0;i < oldPathList.size();i ++){ | |
67 Node node1 = oldPathList.get(i); | |
68 Node node2 = newPathList.get(i); | |
69 | |
70 Assert.assertEquals(true,node1.getID().isFamily(node2.getID())); | |
71 } | |
23 } | 72 } |
24 | 73 |
25 @Test | 74 @Test |
26 public void testCommit() | 75 public void testForceCommit() |
76 { | |
77 m_editor.commit(true); | |
78 NodeID rootID1 = m_editor.getRoot().getID(); | |
79 NodeID rootID2 = m_tree.getRoot().getID(); | |
80 | |
81 Assert.assertEquals(true,rootID1.equals(rootID2)); | |
82 } | |
83 | |
84 @Test | |
85 public void testCommitFailsWhenTreeWasUpdated() | |
27 { | 86 { |
28 | 87 |
29 } | 88 } |
30 | 89 |
31 @Test | 90 @Test |