Mercurial > hg > Members > shoshi > TreeCMSv2
changeset 5:87bba22e4fa2
added test case
author | shoshi |
---|---|
date | Tue, 01 Mar 2011 01:29:59 +0900 |
parents | f5ed85be5640 |
children | 12604eb6b615 |
files | .classpath CHANGELOG src/treecms/test/NodeIDTest.java src/treecms/test/NodeTest.java src/treecms/test/TreeEditorTest.java src/treecms/test/TreeTest.java src/treecms/tree/cassandra/v1/CassandraTree.java |
diffstat | 7 files changed, 240 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Thu Feb 24 21:30:18 2011 +0900 +++ b/.classpath Tue Mar 01 01:29:59 2011 +0900 @@ -21,5 +21,6 @@ <classpathentry kind="lib" path="lib/log4j-1.2.14.jar"/> <classpathentry kind="lib" path="lib/slf4j-api-1.5.8.jar"/> <classpathentry kind="lib" path="lib/slf4j-log4j12-1.5.8.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="bin"/> </classpath>
--- a/CHANGELOG Thu Feb 24 21:30:18 2011 +0900 +++ b/CHANGELOG Tue Mar 01 01:29:59 2011 +0900 @@ -1,5 +1,7 @@ ChangeLog. +2011-02-28 + added test case 2011-02-25 finished treecms.cassandra.v1 implementation ( not tested yet. ) 2011-02-18
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/test/NodeIDTest.java Tue Mar 01 01:29:59 2011 +0900 @@ -0,0 +1,40 @@ +package treecms.test; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import treecms.api.NodeID; + +public class NodeIDTest +{ + NodeID m_newID; + + public NodeIDTest(NodeID _id) + { + m_newID = _id; + } + + @Before + public void testCreateID() + { + NodeID newID = m_newID.create(); + Assert.assertNull(newID); + } + + @Test + public void testCompareID() + { + NodeID newID = m_newID.create(); + Assert.assertEquals(true,m_newID.equals(m_newID)); + Assert.assertEquals(false,m_newID.equals(newID)); + } + + @Test + public void testUpdateID() + { + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/test/NodeTest.java Tue Mar 01 01:29:59 2011 +0900 @@ -0,0 +1,72 @@ +package treecms.test; + +import java.util.LinkedList; +import java.util.List; + +import junit.framework.Assert; + +import org.junit.Test; + +import treecms.api.Node; +import treecms.api.NodeID; + +public class NodeTest +{ + Node m_node; + + public NodeTest(Node _node) + { + m_node = _node; + } + + @Test + public void testGetID() + { + Assert.assertNotNull(m_node.getID()); + } + + @Test + public void testGetData() + { + Assert.assertNotNull(m_node.getData()); + } + + @Test + public void testGetForest() + { + Assert.assertNotNull(m_node.getForest()); + } + + @Test + public void testAddChildren() + { + Node ch1 = m_node.getForest().create(); + Node ch2 = m_node.getForest().create(); + Node ch3 = m_node.getForest().create(); + + LinkedList<Node> list = new LinkedList<Node>(); + list.add(ch1); + list.add(ch2); + list.add(ch3); + + m_node.getData().add(list); + + List<Node> children = m_node.getData().list(); + for(int i = 0;i < list.size();i ++){ + NodeID id1 = children.get(i).getID(); + NodeID id2 = list.get(i).getID(); + + Assert.assertEquals(true,id1.equals(id2)); + } + } + + @Test + public void testSetAndGetAttribute() + { + byte[] name = "test".getBytes(); + byte[] value = "test".getBytes(); + + m_node.getData().set(name,value); + Assert.assertEquals(true,m_node.getData().get(name).equals(value)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/test/TreeEditorTest.java Tue Mar 01 01:29:59 2011 +0900 @@ -0,0 +1,42 @@ +package treecms.test; + +import org.junit.Test; + +import treecms.api.Tree; +import treecms.api.TreeEditor; + +public class TreeEditorTest +{ + Tree m_tree; + TreeEditor m_editor; + + public TreeEditorTest(TreeEditor _editor,Tree _tree) + { + m_editor = _editor; + m_tree = _tree; + } + + @Test + public void testEdit() + { + + } + + @Test + public void testCommit() + { + + } + + @Test + public void testCheck() + { + + } + + @Test + public void testUpdate() + { + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/test/TreeTest.java Tue Mar 01 01:29:59 2011 +0900 @@ -0,0 +1,82 @@ +package treecms.test; + +import java.util.LinkedList; + +import junit.framework.Assert; + +import org.junit.Test; + +import treecms.api.Node; +import treecms.api.NodeData; +import treecms.api.Tree; + +public class TreeTest +{ + Tree m_tree; + + public TreeTest(Tree _tree) + { + m_tree = _tree; + } + + @Test + public void testUpdateTree() + { + /** + * Root + * + 1 + * + + 1-1 <- update this. + * + + * + 2 + * + 2-1 + */ + + Node ch1 = m_tree.getForest().create(); + Node ch2 = m_tree.getForest().create(); + + Node ch11 = m_tree.getForest().create(); + Node ch12 = m_tree.getForest().create(); + + LinkedList<Node> list = new LinkedList<Node>(); + list.add(ch1); + list.add(ch2); + + m_tree.getRoot().getData().add(list); + + LinkedList<Node> ch1list = new LinkedList<Node>(); + ch1list.add(ch11); + ch1.getData().add(ch1list); + + LinkedList<Node> ch2list = new LinkedList<Node>(); + ch2list.add(ch12); + ch2.getData().add(ch2list); + + LinkedList<Node> before = findPath(m_tree.getRoot(),ch11); + NodeData newData = ch11.getData().deepCopy(); + m_tree.updateTree(ch11,newData); + LinkedList<Node> after = findPath(m_tree.getRoot(),ch11); + + for(int i = 0;i < before.size();i ++){ + boolean result = before.get(i).getID().isFamily(after.get(i).getID()); + Assert.assertEquals(true,result); + } + } + + public LinkedList<Node> findPath(Node _from,Node _target) + { + if(_from.getID().isFamily(_target.getID())){ + LinkedList<Node> path = new LinkedList<Node>(); + path.add(_from); + return path; + } + + for(Node child : _from.getData().list()){ + LinkedList<Node> path = findPath(child,_target); + if(path != null){ + path.add(_from); + } + } + + return null; + } +}