/*
 * 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.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.itscool.commons.document.BeanToXmlDocument;
import org.w3c.dom.Document;

/**
 *
 * @author ios
 */
public class BeanToXmlDocument5Test 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");
        
        Map childs = new HashMap();
        childs.put("child1-key", child);
        childs.put("child2-key", child2);
        
        SampleParent3 parent = new SampleParent3();
        parent.setName("parent");
        parent.setBeanMap(childs);
        
        try{
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleParent3.class.getName(), "sample_parent");
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "sample_bean");
            
            //オブジェクト追加
            beanToXml.addElement(parent);
            
            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){
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

}
