package test.org.itscool.commons.document;

import junit.framework.TestCase;

import org.itscool.commons.document.BeanToXmlDocument;

public class BeanToXmlDocument2Test extends TestCase{
    
    /**
     * クラスからタグ名に変換
     */
    public void test1(){
        try{
            SampleBean1 bean = new SampleBean1();
            bean.setId(1);
            bean.setName("aaa");
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "sample_bean");
            
            //オブジェクト登録
            beanToXml.addElement(bean);
            
            System.out.println(beanToXml.parseText("UTF-8")+"\n");
            //DocumentBeanParser.parseBean();
        }catch(Exception e){
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
    
    /**
     * クラスからタグ名変換
     */
    public void test2(){
        try{
            SampleBean1 bean = new SampleBean1();
            bean.setId(1);
            bean.setName("こども１");
            
            SampleParent1 parent = new SampleParent1();
            parent.setName("おとな１");
            parent.setBean(bean);
            
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "sample_bean");
            beanToXml.replaceClassToTagName(SampleParent1.class.getName(), "sample_parent");
            
            beanToXml.addElement(parent);
            System.out.println(beanToXml.parseText("UTF-8")+"\n");
            //DocumentBeanParser.parseBean();
        }catch(Exception e){
            fail(e.getMessage());
        }
    }
    
    /**
     * クラスからタグ名に変換
     */
    public void test3(){
        try{
            SampleBean1 bean = new SampleBean1();
            bean.setId(1);
            bean.setName("aaa");
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleBean1.class.getName(), "社員");
            beanToXml.replaceMemberToTagName(SampleBean1.class.getName(), "id", "社員番号");
            beanToXml.replaceMemberToTagName(SampleBean1.class.getName(), "name", "社員名");
            
            //オブジェクト登録
            beanToXml.addElement(bean);
            
            System.out.println(beanToXml.parseText("UTF-8")+"\n");
            //DocumentBeanParser.parseBean();
        }catch(Exception e){
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
    
    /**
     * クラスからタグ名変換
     */
    public void test4(){
        try{
            SampleBean1 bean = new SampleBean1();
            bean.setId(1);
            bean.setName("こども１");
            
            SampleParent1 parent = new SampleParent1();
            parent.setName("おとな１");
            parent.setBean(bean);
            
            BeanToXmlDocument beanToXml = new BeanToXmlDocument("root");
            
            //マッピング定義
            beanToXml.replaceClassToTagName(SampleParent1.class.getName(), "部署");
            beanToXml.replaceMemberToTagName(SampleParent1.class.getName(), "name", "部署名");
            beanToXml.replaceMemberToTagName(SampleParent1.class.getName(), "bean", "社員情報");
            
            beanToXml.replaceMemberToTagName(SampleBean1.class.getName(), "id", "社員番号");
            beanToXml.replaceMemberToTagName(SampleBean1.class.getName(), "name", "社員名");
            
            beanToXml.addElement(parent);
            System.out.println(beanToXml.parseText("UTF-8")+"\n");
            //DocumentBeanParser.parseBean();
        }catch(Exception e){
            fail(e.getMessage());
        }
    }
    
}
