view src/treecms/test/AbstractNodeTest.java @ 17:168deb591f21

commit
author shoshi
date Tue, 24 May 2011 00:33:12 +0900
parents bb9760760744
children 77a894c0b919
line wrap: on
line source

package treecms.test;

import java.nio.ByteBuffer;
import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import treecms.api.NodeChildren;
import treecms.api.NodeID;
import treecms.api.SingleNode;
import treecms.tree.util.NodeChildrenImpl;

/**
 * Node実装の基本的なテスト
 * @author shoshi
 */
public abstract class AbstractNodeTest
{
	/**
	 * テストに用いるNodeを実装者は返す
	 * @return Node
	 */
	public abstract SingleNode getInstance();
	
	/**
	 * NodeID取得のテスト
	 */
	@Test
	public void testGetID()
	{
		Assert.assertNotNull(getInstance().getID());
	}
	
	/**
	 * Nodeのデータ(子供Nodeや属性のマップ)
	 */
	@Test
	public void testGetData()
	{
		Assert.assertNotNull(getInstance().getList());
		Assert.assertNotNull(getInstance().getAll());
	}
	
	/**
	 * NodeからForestを取得するテスト
	 */
	@Test
	public void testGetForest()
	{
		Assert.assertNotNull(getInstance().getForest());
	}
	
	/**
	 * Nodeに子供Nodeを追加するテスト
	 */
	@Test
	public void testAddChildren()
	{
		SingleNode node = getInstance();
		
		SingleNode ch1 = node.getForest().create();
		SingleNode ch2 = node.getForest().create();
		SingleNode ch3 = node.getForest().create();
		
		NodeChildren<SingleNode> list = new NodeChildrenImpl<SingleNode>(ch1,ch2,ch3);
		node.addAll(list);
		
		List<SingleNode> children = node.getList();
		int size = list.getList().size();
		for(int i = 0;i < size;i ++){
			NodeID id1 = children.get(i).getID();
			NodeID id2 = list.get(i).getID();
			
			Assert.assertEquals(true,id1.equals(id2));
		}
	}
	
	/**
	 * Nodeにセットした属性を取り出すテスト
	 */
	@Test
	public void testSetAndGetAttribute()
	{
		SingleNode node = getInstance();
		byte[] name = "test".getBytes();
		byte[] value = "test".getBytes();
		
		node.put(ByteBuffer.wrap(name),ByteBuffer.wrap(value));
		Assert.assertEquals(true,node.get(ByteBuffer.wrap(name)).equals(ByteBuffer.wrap(value)));
	}
}