Mercurial > hg > Members > shoshi > TreeCMSv1
view src/treecms/proto/test/SimpleNodeTest1.java @ 33:c0a0fa870e6e
commit again
author | shoshi |
---|---|
date | Fri, 19 Nov 2010 15:31:42 +0900 |
parents | ff4d4704e5d7 |
children |
line wrap: on
line source
package treecms.proto.test; import static org.hamcrest.core.IsNull.notNullValue; import static org.hamcrest.core.IsNot.not; import org.junit.Test; import org.junit.Assert; import org.junit.runner.JUnitCore; import treecms.proto.api.*; import treecms.proto.simple.*; import java.util.List; public class SimpleNodeTest1 { public static void main(String _arg[]) { JUnitCore.main(SimpleNodeTest1.class.getName()); } private Node m_target; private Node m_child1,m_child2,m_child3; public SimpleNodeTest1() { m_target = new SimpleNode(); m_child1 = m_target.addChild(new SimpleNode()); m_child2 = m_target.addChild(new SimpleNode()); m_child3 = m_target.addChild(new SimpleNode()); } @Test public void testCreateNode() { Node node = new SimpleNode(); Assert.assertThat(node,notNullValue()); String clsName = "test1"; node.setClassName(clsName); Assert.assertEquals(node.getClassName(),clsName); String title = "test2"; node.setTitle(title); Assert.assertEquals(node.getTitle(),title); } @Test public void testClone() { Node node = new SimpleNode(); String clsName = "test1"; node.setClassName(clsName); String title = "test2"; node.setTitle(title); Node clone = node.cloneNode(); Assert.assertThat(clone.getID(),not(node.getID())); Assert.assertEquals(node.getClassName(),clone.getClassName()); Assert.assertEquals(node.getTitle(),clone.getTitle()); } @Test public void testChildOperation() { //check that correctly added. List<Node> children = m_target.getChildren(); Assert.assertEquals(children.size(),3); Assert.assertEquals(children.get(0),m_child1); Assert.assertEquals(children.get(1),m_child2); Assert.assertEquals(children.get(2),m_child3); } @Test public void testRemoveChild() { //remove m_target.removeChild(m_child3); List<Node> children = m_target.getChildren(); Assert.assertEquals(children.get(0),m_child1); Assert.assertEquals(children.get(1),m_child2); } @Test public void testUpOperation() { //up m_target.up(m_child2); List<Node> children = m_target.getChildren(); Assert.assertEquals(children.get(0),m_child2); Assert.assertEquals(children.get(1),m_child1); Assert.assertEquals(children.get(2),m_child3); } @Test public void testDownOperation() { //up m_target.down(m_child2); List<Node> children = m_target.getChildren(); Assert.assertEquals(children.get(0),m_child1); Assert.assertEquals(children.get(1),m_child3); Assert.assertEquals(children.get(2),m_child2); } @Test public void testReplaceOperation() { //replace Node node = new SimpleNode(); m_target.replace(m_child2,node); List<Node> children = m_target.getChildren(); Assert.assertEquals(children.get(0),m_child1); Assert.assertEquals(children.get(1),node); Assert.assertEquals(children.get(2),m_child3); } }