view src/treecms/proto/test/EditableTreeBuilderTest1.java @ 27:45881237e777

commit
author ShoshiTAMAKI
date Sun, 07 Nov 2010 14:07:03 +0900
parents 9b91329e8a04
children
line wrap: on
line source

package treecms.proto.test;



import org.junit.Test;
import org.junit.runner.JUnitCore;

import treecms.proto.api.*;
import treecms.proto.edit.EditableTreeBuilder;
import treecms.proto.simple.*;

public class EditableTreeBuilderTest1 
{
	public static void main(String _args[])
	{
		JUnitCore.main(EditableTreeBuilderTest1.class.getName());
	}
	
	private Node m_root;
	private Node m_target1;
	private Node m_target2;
	
	public EditableTreeBuilderTest1()
	{
		
		TreeBuilder builder = new SimpleTreeBuilder();
		Node root = builder.getContents();
		root.setTitle("root");
		
		Node child1 = builder.createNode();
		child1.setTitle("child1");
		Node child2 = builder.createNode();
		child2.setTitle("child2");
		
		root.addChild(child1);
		root.addChild(child2);
		
		Node child11 = builder.createNode(); 
		child11.setTitle("child11");
		Node child12 = builder.createNode();
		child12.setTitle("child12");
		Node child13 = builder.createNode();
		child13.setTitle("child13");
		
		child1.addChild(child11);
		child1.addChild(child12);
		child1.addChild(child13);
		
		Node child21 = builder.createNode();
		child21.setTitle("child21");
		
		child2.addChild(child21);
		
		Node child211 = builder.createNode();
		child211.setTitle("child211");
		Node child212 = builder.createNode();
		child212.setTitle("child212");
		
		child21.addChild(child211);
		child21.addChild(child212);
		
		m_root = root;
		m_target1 = child212;
		m_target2 = child211;
	}
	
	@Test
	public void testClone()
	{
		Node target;
		EditableTreeBuilder builder;
		builder = new EditableTreeBuilder(m_root,m_target1);
		target = builder.getTargetNode();
		target.setTitle("*"+m_target1.getTitle());
		System.out.println("-----------------------------------------------");
		print(builder.getContents(),0);
		
		builder = new EditableTreeBuilder(builder.getContents(),m_target2);
		target = builder.getTargetNode();
		target.setTitle("*"+m_target2.getTitle());
		System.out.println("-----------------------------------------------");
		print(builder.getContents(),0);
	}
	
	private void print(Node _root,int _indent)
	{
		for(int i = 0;i < _indent;i ++){
			System.out.print("\t");
		}
		System.out.println(_root.getTitle()+"["+_root.getID()+"]");
		for(Node child : _root.getChildren()){
			print(child,_indent+1);
		}
	}
}