package com.eactive.eai.transformer;

import com.eactive.eai.common.util.Logger;
import com.eactive.eai.transformer.engine.TransformEngine;
import com.eactive.eai.transformer.engine.Transformer;
import com.eactive.eai.transformer.message.Message;
import com.eactive.eai.transformer.message.MessageFactory;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;


public class TransformErrorTest extends TestCase {
	protected static Logger logger = Logger.getLogger("transformer");

	TransformEngine engine = null;
    
    
    public TransformErrorTest(String name) {
        super(name);
    }

    public static Test suite() {
        /*
        * the dynamic way
        */
        return new TestSuite(TransformErrorTest.class);
    }

    public void setUp() throws Exception {
    	String module = System.getProperty("moudle");
    	if (module == null){
    		System.setProperty("moudle","TEST_DB");
    	}
    	String tableowner = System.getProperty("eai.tableowner");
    	if (tableowner == null){
    		System.setProperty("eai.tableowner","INST2");
    	}
    	String profix = System.getProperty("prefix");
    	if (profix == null){
    		System.setProperty("prefix","local.eai.db2");
    	}
    	
        // 변환 초기화
        engine = TransformEngine.getInstance();

        if (!engine.isStarted()) {
            engine.start();
        }
    }

    public void tearDown() throws Exception {
        //
    }
    
//    public void atestXmlToUJson() throws Exception {
//  		System.out.println("Xml TO UJson ==============================================================");
//        //logger.debug("Transform08900001Test | testTransform()");
//
//        //----------------------------------------------------------------------
//        // source message 생성
//        //----------------------------------------------------------------------
//    	String data ="";
//    	data = "<InData telgmLen=\"0650\" sysDstic=\"KIOSK\" telgmNo=\"0200\" bzwkCd=\"8000\" bzoprDte=\"20190703\" hndlnBrncd=\"8518\" hndlnTrmno=\"P81\" obaobDstic=\"1\" drwotBnkCd=\"004\" tranSerno=\"000002\" shetSerno=\"00\" operDstic=\"N0\" uno=\"\" feeDstcd=\"S\" mchtlOperDstic=\"\" mchtlDstic=\"M\" sndrcvFlag=\"1\" rspnsCd=\"\" spare1=\"\" acno=\"49230101099108\" pwd=\"6GP30CGG2081040G2081040G2081040G   T\" custnm=\"\" cno=\"\" paymtCustnm=\"\" amtSin=\"\" tranAfAmt=\"00000000000\" fee1=\"0000000\" creCrdNo=\"\" cardCoCd=\"\" inquryWayDstic=\"01\" smptyPaymtNo=\"\" elctrPaymtNo=\"\" inquryPbltxTelgmNo=\"004000003162\" totalWrntNoitm=\"000001\" totalWrntAmt=\"000000000133280\" paymtTotalNoitm=\"000001\" paymtTotalAmt=\"000000000133280\" crecdintmTrm=\"00\" crecdIinptintmTrm=\"00\" pointYn=\"\" pointMaxIntmTrm=\"00\" pointUseYn=\"\" pointSelcIntmTrm=\"00\" spare2=\"\"><cdpaymtHistAray cdhistSerno=\"01\" cdlsgbName=\"서울\" cdtxitmName =\"자동차세\" cdpaymtAmt=\"133280\" cdpaymtDdln=\"20190731\" cdpaymtYn=\"Y\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdhist2 cdelctrPaymtNo=\"1123011019760005287\" /><cdhist2 cdelctrPaymtNo=\"\" /><cdhist2 cdelctrPaymtNo=\"\" /><cdhist2 cdelctrPaymtNo=\"\" /></InData>";
//        
//    	
//    	Message source = MessageFactory.getFactory().getMessage("KGN_KGA0100513_REQ1");
//        source.setData("<KGN_KGA0100513_REQ1>"+data+"</KGN_KGA0100513_REQ1>");
//
//        System.out.println("source="+source);
//
//        //----------------------------------------------------------------------
//        // 변환 방식 1
//        //----------------------------------------------------------------------
//        Transformer transformer = engine.getTransformer();
//        Message target = transformer.transform("TRANSFORM_KGN_KGA0100513KGN_REQ", new Message[] { source });
//
//        System.out.println(target);
//        System.out.println("getData="+target.getData());
//        
//    }
//    
//    public void testXmlToUJson() throws Exception {
//  		System.out.println("Xml TO UJson ==============================================================");
//        //logger.debug("Transform08900001Test | testTransform()");
//
//        //----------------------------------------------------------------------
//        // source message 생성
//        //----------------------------------------------------------------------
//    	String data ="";
//    	data = "<InData telgmLen=\"0650\" sysDstic=\"KIOSK\" telgmNo=\"0200\" bzwkCd=\"8000\" bzoprDte=\"20190703\" hndlnBrncd=\"8518\" hndlnTrmno=\"P81\" obaobDstic=\"1\" drwotBnkCd=\"004\" tranSerno=\"000002\" shetSerno=\"00\" operDstic=\"N0\" uno=\"\" feeDstcd=\"S\" mchtlOperDstic=\"\" mchtlDstic=\"M\" sndrcvFlag=\"1\" rspnsCd=\"\" spare1=\"\" acno=\"49230101099108\" pwd=\"6GP30CGG2081040G2081040G2081040G   T\" custnm=\"\" cno=\"\" paymtCustnm=\"\" amtSin=\"\" tranAfAmt=\"00000000000\" fee1=\"0000000\" creCrdNo=\"\" cardCoCd=\"\" inquryWayDstic=\"01\" smptyPaymtNo=\"\" elctrPaymtNo=\"\" inquryPbltxTelgmNo=\"004000003162\" totalWrntNoitm=\"000001\" totalWrntAmt=\"000000000133280\" paymtTotalNoitm=\"000001\" paymtTotalAmt=\"000000000133280\" crecdintmTrm=\"00\" crecdIinptintmTrm=\"00\" pointYn=\"\" pointMaxIntmTrm=\"00\" pointUseYn=\"\" pointSelcIntmTrm=\"00\" spare2=\"\"><cdpaymtHistAray cdhistSerno=\"01\" cdlsgbName=\"서울\" cdtxitmName =\"자동차세\" cdpaymtAmt=\"133280\" cdpaymtDdln=\"20190731\" cdpaymtYn=\"Y\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdpaymtHistAray cdhistSerno=\"00\" cdlsgbName=\"\" cdtxitmName=\"\" cdpaymtAmt=\"00\" cdpaymtDdln=\"\" cdpaymtYn=\"\" /><cdhist2 cdelctrPaymtNo=\"1123011019760005287\" /><cdhist2 cdelctrPaymtNo=\"\" /><cdhist2 cdelctrPaymtNo=\"\" /><cdhist2 cdelctrPaymtNo=\"\" /></InData>";
//        
//    	
//    	Message source = MessageFactory.getFactory().getMessage("KGN_KGA0100513_REQ1");
//        source.setData("<KGN_KGA0100513_REQ1>"+data+"</KGN_KGA0100513_REQ1>");
//
//        System.out.println("source="+source);
//
//        //----------------------------------------------------------------------
//        // 변환 방식 1
//        //----------------------------------------------------------------------
//        Transformer transformer = engine.getTransformer();
//        Message target = transformer.transform("TRANSFORM_KGN_KGA0100513KGN_REQ", new Message[] { source });
//
//        System.out.println(target);
//        System.out.println("getData="+target.getData());
//        
//    }
    
    public void testFlatToUJson() throws Exception {
  		System.out.println("Flat TO UJson ==============================================================");
        //----------------------------------------------------------------------
        // source message 생성
        //----------------------------------------------------------------------
    	String data ="";
    	data = "KB0S0012313153506840000001011112222     김은수                                            018009999        [KB태블릿브랜치] 김은수님, 정상적으로 로그인되었습니다.                         0                                                                 00281648458";
    	
    	Message source = MessageFactory.getFactory().getMessage("CCA_BNC71901R1CCAS01_REQ3");
//        source.setData(data.getBytes());

        System.out.println("source="+source);

        //----------------------------------------------------------------------
        // 변환 방식 1
        //----------------------------------------------------------------------
        Transformer transformer = engine.getTransformer();
        Message target = transformer.transform("TRANSFORM_CCA_BNC71901R1CCA_REQ", new Message[] { source });

        System.out.println(target);
        System.out.println("getData="+target.getData());
        
    }
    
}
