/*
 * BeanToXmlDocument3Test.java
 *
 * Created on 2007/11/30, 16:40
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package test.org.itscool.commons.document;

import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.itscool.commons.document.BeanToXmlDocument;
import org.w3c.dom.Document;

/**
 *
 * @author ios
 */
public class BeanToXmlDocument3Test extends TestCase{
    
    public void testParseList(){
        SampleBean1 child = new SampleBean1();
        child.setId(1);
        child.setName("child1");
        
        SampleBean1 child2 = new SampleBean1();
        child2.setId(2);
        child2.setName("child2");
        
        List childs = new ArrayList();
        childs.add(child);
        childs.add(child2);
        try{
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "sample_bean");
            
            //オブジェクト追加
            beanToXml.addElement(childs);
            
            Document document = beanToXml.getDocument();
            
            String text = beanToXml.parseTextIndent("Shift_JIS");
            System.out.println("---- test2 start ----");
            System.out.println(text);
            System.out.println("---- test2 end ----");
            
        }catch(Exception e){
            fail(e.getMessage());
        }
    }
    
    public void testParseList2(){
        SampleBean1 child = new SampleBean1();
        child.setId(1);
        child.setName("child1");
        
        SampleBean1 child2 = new SampleBean1();
        child2.setId(2);
        child2.setName("child2");
        
        List childs = new ArrayList();
        childs.add(child);
        childs.add(null);
        try{
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "sample_bean");
            
            //オブジェクト登録
            beanToXml.addElement(childs, "sample_bean_list");
            
            Document document = beanToXml.getDocument();
            
            String text = beanToXml.parseTextIndent("Shift_JIS");
            System.out.println("---- test3 start ----");
            System.out.println(text);
            System.out.println("---- test3 end ----");
            
        }catch(Exception e){
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
}
