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 com.eactive.eai.transformer.util.IConv;

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


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

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

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

    public void setUp() throws Exception {
        // 변환 초기화
        engine = TransformEngine.getInstance();

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

    public void tearDown() throws Exception {
        //
    }

	public void testStandardError() throws Exception {
	System.out.println("Test If ==============================================================");
	// ----------------------------------------------------------------------
	// source message 생성
	// ----------------------------------------------------------------------
	Message source = MessageFactory.getFactory().getMessage("EAI_XML_ERR");
	
    String data = "<EAI_XML_ERR><OutForms></OutForms><OutData ErrmsgErrNoitm=\"1\"><RpsntErrInfo ErrmsgErrcd=\"S9FBF003\" ErrmsgTreatCd=\"\" ErrPgmName=\"\" ErrmsgErrSituNo=\"90\" /><ErrmsgErrInfo ErrmsgErrcd=\"S9FBF003\" ErrmsgTreatCd=\"\" ErrmsgErrPgmzName=\"\" ErrmsgErrSituNo=\"90\" /></OutData></EAI_XML_ERR>";
    source.setData(data);
    
    System.out.println(source);
    System.out.println("["+ source.getData() +"]");
    
    // 
	Transformer transformer = engine.getTransformer();
	Message target = transformer.transform("TRANSFORM_EAI_XMLTOUJN_ERR", new Message[] { source });

	System.out.println(target);

	System.out.println("["+ target.getData() +"]");
	
	Message target2 = transformer.transform("TRANSFORM_EAI_UJNTOEBC_ERR", new Message[] { target });

	System.out.println("[" + IConv.ebcdicToASCII((byte[])target2.getData()) +"]");
	
	
//	Message source1 = MessageFactory.getFactory().getMessage("EAI_ASCII_ERR");
//	System.out.println(source1);
//    System.out.println("["+ new String((byte[])source1.getData()) +"]");
//    
//   Message source2 = MessageFactory.getFactory().getMessage("EAI_UJSON_ERR");
//	System.out.println(source2);
//    System.out.println("["+ source2.getData() +"]");
	
} 
    
//	public void testIf() throws Exception {
//		System.out.println("Test If ==============================================================");
//		// ----------------------------------------------------------------------
//		// source message 생성
//		// ----------------------------------------------------------------------
//		String data = "";
//    	data = "0000001230";
//    	
//		Message source = MessageFactory.getFactory().getMessage("EAI_TSTFUNCTION_REQ");
//		
//		source.setData(IConv.asciiToEBCDIC(data));
//		System.out.println(source);
//        Transformer transformer = engine.getTransformer();
//        Message target = transformer.transform("TRANSFORM_EAI_TSTFUNCTION_ERR", new Message[] { source });
//      
//        System.out.println(target);
//      
//        System.out.println("["+ target.getData() +"]");
//	} 
    
    
//	public void testUjsonToEbcdic() throws Exception {
//		System.out.println("testUjsonToEbcdic ==============================================================");
//		// ----------------------------------------------------------------------
//		// source message 생성
//		// ----------------------------------------------------------------------
//		String data = "";
//    	data = "{\"EAI_TSTFUNCTION_ERR\":{\"group\":{\"data1\":1.1}}}";
//
//    	System.out.println(data);
//    	Message source = MessageFactory.getFactory().getMessage("EAI_TSTFUNCTION_ERR");
//		
//		source.setData(data);
//		System.out.println(source);
//        Transformer transformer = engine.getTransformer();
//        Message target = transformer.transform("TRANSFORM_EAI_TSTFUNCTION_RES", new Message[] { source });
//      
//        System.out.println(target);
//      
//        System.out.println("["+ target.getData() +"]");
//	}
	
//	public void testPcb() throws Exception {
//		System.out.println("testPcb ==============================================================");
//		// ----------------------------------------------------------------------
//		// source message 생성
//		// ----------------------------------------------------------------------
//		String data = "";
////    	data = "{\"PCB_EEF200502_REQ1\":{\"InData\":{\"ARRAY\":[{\"금융회사코드\":\"\",\"일자\":\"\",\"OTP상태코드\":\"\",\"처리시간\":\"\"}],\"주민번호\":\"\",\"개별전문길이\":\"000\",\"요구기관코드\":\"01004\",\"전문종별코드\":\"0200\",\"전문전송일자\":\"20200102\",\"요청시작위치\":\"001\",\"TRCODE\":\"TTASKOTP\",\"전문전송시간\":\"092800\",\"응답코드\":\"0000\",\"OTP서버응답코드\":\"0000\",\"OTP상태코드\":\"\",\"ENDFLAG\":\"EF\",\"요구시스템\":\"EBK\",\"예비\":\"\",\"OTP일련번호\":\"1001818052\",\"예비정보필드\":\"\",\"FIELD_LENGTH\":\"0000000790\",\"서비스코드\":\"OTP503\",\"서버별거래일련번호\":\"00\",\"사용자식별코드\":\"\",\"송수신코드\":\"1\",\"센터예비필드\":\"\",\"사용자암호\":\"\",\"거래구분코드\":\"200502\",\"벤더코드\":\"004\",\"사용자ID2\":\"\",\"거래일련번호\":\"00000015\",\"조회시작일\":\"00110000\",\"요구년월일시\":\"20200102000000\",\"외부시스템구분코드\":\"OTP\",\"응답년월시\":\"20200102000000\",\"사용자ID1\":\"WAPUSER\",\"조회종료일\":\"20200102\",\"응답코드1\":\"000\",\"기관예비필드\":\"\",\"전체건수\":\"000\",\"전문일련번호\":\"00000015\",\"미통지존재여부\":\"0\",\"세션정보\":\"000\",\"기준일자\":\"20200102\",\"응답기관코드\":\"00999\",\"매체사용건수\":\"1\",\"전송년월일\":\"20200102000000\",\"업무코드\":\"WBS\",\"업무별거래일련번호\":\"000000\",\"ARRAY?\":1:1,\"매체코드2\":\"\",\"매체코드1\":\"WBS\",\"거래유형코드\":\"000\",\"인터넷뱅킹로그인ID\":\"WAPUSER\",\"테스트구분\":\"T\",\"트랜젝션코드\":\"OTPSGN\"}}}";
//    	data = "{\"PCB_EEF200502_REQ1\":{\"InData\":{\"ARRAY수\":1}}}";
//
//    	System.out.println(data);
//    	Message source = MessageFactory.getFactory().getMessage("PCB_EEF200502_REQ1");
//		
//		source.setData(data);
//		System.out.println(source);
//        Transformer transformer = engine.getTransformer();
//        Message target = transformer.transform("TRANSFORM_PCB_EEF200502PCB_REQ", new Message[] { source });
//      
//        System.out.println(target);
//      
//        System.out.println("["+ target.getData() +"]");
//	}
}
