comparison src/treecms/test/AbstractNodeTest.java @ 16:bb9760760744

commit
author shoshi
date Sat, 21 May 2011 04:46:00 +0900
parents 17ed97ca9960
children 168deb591f21
comparison
equal deleted inserted replaced
15:22cd920986c5 16:bb9760760744
1 package treecms.test; 1 package treecms.test;
2 2
3 import java.nio.ByteBuffer; 3 import java.nio.ByteBuffer;
4 import java.util.LinkedList;
5 import java.util.List; 4 import java.util.List;
6
7 import junit.framework.Assert; 5 import junit.framework.Assert;
8
9 import org.junit.Test; 6 import org.junit.Test;
10 7 import treecms.api.NodeChildren;
11 import treecms.api.Node;
12 import treecms.api.NodeID; 8 import treecms.api.NodeID;
9 import treecms.api.SingleNode;
10 import treecms.tree.util.NodeChildrenImpl;
13 11
14 /** 12 /**
15 * Node実装の基本的なテスト 13 * Node実装の基本的なテスト
16 * @author shoshi 14 * @author shoshi
17 */ 15 */
19 { 17 {
20 /** 18 /**
21 * テストに用いるNodeを実装者は返す 19 * テストに用いるNodeを実装者は返す
22 * @return Node 20 * @return Node
23 */ 21 */
24 public abstract Node getInstance(); 22 public abstract SingleNode getInstance();
25 23
26 /** 24 /**
27 * NodeID取得のテスト 25 * NodeID取得のテスト
28 */ 26 */
29 @Test 27 @Test
36 * Nodeのデータ(子供Nodeや属性のマップ) 34 * Nodeのデータ(子供Nodeや属性のマップ)
37 */ 35 */
38 @Test 36 @Test
39 public void testGetData() 37 public void testGetData()
40 { 38 {
41 Assert.assertNotNull(getInstance().getData()); 39 Assert.assertNotNull(getInstance().getList());
40 Assert.assertNotNull(getInstance().getAll());
42 } 41 }
43 42
44 /** 43 /**
45 * NodeからForestを取得するテスト 44 * NodeからForestを取得するテスト
46 */ 45 */
54 * Nodeに子供Nodeを追加するテスト 53 * Nodeに子供Nodeを追加するテスト
55 */ 54 */
56 @Test 55 @Test
57 public void testAddChildren() 56 public void testAddChildren()
58 { 57 {
59 Node node = getInstance(); 58 SingleNode node = getInstance();
60 59
61 Node ch1 = node.getForest().create(); 60 SingleNode ch1 = node.getForest().create();
62 Node ch2 = node.getForest().create(); 61 SingleNode ch2 = node.getForest().create();
63 Node ch3 = node.getForest().create(); 62 SingleNode ch3 = node.getForest().create();
64 63
65 LinkedList<Node> list = new LinkedList<Node>(); 64 NodeChildren<SingleNode> list = new NodeChildrenImpl<SingleNode>();
66 list.add(ch1); 65 list.add(ch1);
67 list.add(ch2); 66 list.add(ch2);
68 list.add(ch3); 67 list.add(ch3);
69 68
70 node.addAll(list); 69 node.addAll(list);
71 70
72 List<Node> children = node.children(); 71 List<SingleNode> children = node.getList();
73 for(int i = 0;i < list.size();i ++){ 72 int size = list.getList().size();
73 for(int i = 0;i < size;i ++){
74 NodeID id1 = children.get(i).getID(); 74 NodeID id1 = children.get(i).getID();
75 NodeID id2 = list.get(i).getID(); 75 NodeID id2 = list.get(i).getID();
76 76
77 Assert.assertEquals(true,id1.equals(id2)); 77 Assert.assertEquals(true,id1.equals(id2));
78 } 78 }
82 * Nodeにセットした属性を取り出すテスト 82 * Nodeにセットした属性を取り出すテスト
83 */ 83 */
84 @Test 84 @Test
85 public void testSetAndGetAttribute() 85 public void testSetAndGetAttribute()
86 { 86 {
87 Node node = getInstance(); 87 SingleNode node = getInstance();
88 byte[] name = "test".getBytes(); 88 byte[] name = "test".getBytes();
89 byte[] value = "test".getBytes(); 89 byte[] value = "test".getBytes();
90 90
91 node.put(ByteBuffer.wrap(name),ByteBuffer.wrap(value)); 91 node.put(ByteBuffer.wrap(name),ByteBuffer.wrap(value));
92 Assert.assertEquals(true,node.get(ByteBuffer.wrap(name)).equals(ByteBuffer.wrap(value))); 92 Assert.assertEquals(true,node.get(ByteBuffer.wrap(name)).equals(ByteBuffer.wrap(value)));