package com.eactive.eai.transformer;

import com.eactive.eai.common.util.Logger;
import com.eactive.eai.transformer.engine.TransformEngine;
import com.eactive.eai.transformer.function.util.CodeConversion;
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 LayoutRefTest extends TestCase {
	protected static Logger logger = Logger.getLogger("transformer");

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

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

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

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

    public void tearDown() throws Exception {
        //
    }
    
	public void atestCase1Test() throws Exception {
		//참조정보 무시함

		//String data ="LLZZHDR001112222333455520190918130066601123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234FFFFFFFFFFFFSPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARE########";
		String data ="LLZZHDR001112222333455520190918130066602123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234FFFFFFFFFFFFSPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARESPARE########";
		System.out.println("KFM_EBE98009022_RES1 - 패턴 없음, min 1, max 1, 참조정보 존재 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KFM_EBE98009022_RES1");
    	source.setData(IConv.asciiToEBCDIC(data));
    	System.out.println(source.toString());
	} 
    
	public void atestCase2Test() throws Exception {
		//참조정보는 최대 건수를 넘을수 없음
//		String data ="LLZZHDR1122233334445666777777777777888001AAAAAAA000000000000";
		String data ="LLZZHDR1122233334445666777777777777888";
			   data += "040";
			   data += "1AAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBB";
			   data += "2AAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBB";
			   data += "3AAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBB";
			   data += "4AAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBBAAAAAAABBBBBBB";
			   data += "000000000000";
		
		System.out.println("KFM_EBE98109042_REQ1 - 패턴 30, min 0, max 30, 참조정보 존재 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KFM_EBE98109042_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source.toString());
    	
//    	data ="LLZZHDR1122233334445666777777777777888002AAAAAAABBBBBBB000000000000";
//    	System.out.println(data);
//    	source = MessageFactory.getFactory().getMessage("KFM_EBE98009022_RES1");
//    	source.setData(data.getBytes());
//    	System.out.println(source.toString());
	}
	
	public void atestCase3Test() throws Exception {
		//String data ="00000000001111111111223420190918566620191231ABCDEABCDEABCDEABCDEABCDEABCDE000000000000000111111111111111";
		String data ="";
		
		System.out.println("KGE_KGE0400440_REQ2 - 패턴 0, min 0, max 0, 참조정보 없음 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KGE_KGE0400440_REQ2");
    	source.setData(IConv.asciiToEBCDIC(data));
    	System.out.println(source.toString());    	
	}
	
	public void atestCase4Test() throws Exception {
		String data ="00000000001111111111ABCDEABCDEABCDEABCDEABCDEABCDE2019091820191231000000000000000111111111111111";
    	System.out.println("KGE_KGE0400440_RES1 - 패턴 0, min 1, max 1, 참조정보 없음 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KGE_KGE0400440_RES1");
    	source.setData(IConv.asciiToEBCDIC(data));
    	System.out.println(source.toString());
	}
	
	public void atestCase5Test() throws Exception {
		String data ="00001112222222222222222222222222222222222222019091812000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF1234567890123456789012345678901234567890123456781112345678901234567890123456789012345678901234567800001234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901111000000000000000000022BBBBBBBBBBBBBBBBBBBBBBB";
		System.out.println("KFI_ECE0100000_REQ1 - BYTES 레이아웃 인데 2201(String) 으로 표시 됨 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KFI_ECE0100000_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source.toString());
	}
	
	public void atestCase6Test() throws Exception {
		String data ="0011122222222333333444444445555500001000016661000000000200000000030000000004000000000";
		System.out.println("KJI_KJI040ZB41_RES1 -grid인데 2113 byte로 되어 있음 ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KJI_KJI040ZB41_RES1");
    	source.setData(IConv.asciiToEBCDIC(data));
    	System.out.println(source.toString());
    	
    	data ="00111222222223333334444444455555000020000266610000000002000000000300000000040000000007771000000000200000000030000000004000000000";
		System.out.println(data);
    	source = MessageFactory.getFactory().getMessage("KJI_KJI040ZB41_RES1");
    	source.setData(IConv.asciiToEBCDIC(data));
    	System.out.println(source.toString());
	}
	
	public void atestCase7Test() throws Exception {
		String data ="<KYB_KYB2010_REQ1>"
				+ "<InData>"
				+ "<mgtBrncd>0000</mgtBrncd>"
				+ "<pfrmRegiNo>11111</pfrmRegiNo>"
				+ "<cretnMbdyDstcd>2</cretnMbdyDstcd>"
				+ "<ecalTranCncdCd>3</ecalTranCncdCd>"
				+ "<paymtAplcnYm>20190918</paymtAplcnYm>"
				+ "<tranBrncd>1234</tranBrncd>"
				+ "<tranBaseYmd>20190918</tranBaseYmd>"
				+ "<gUIDNo>123456789012345678901234567890123456</gUIDNo>"
				+ "<userEmpid>7777777</userEmpid>"
				+ "<mlgPfrmDstcd>0</mlgPfrmDstcd>"
				+ "<rcdrwDstcd>0</rcdrwDstcd>"
				+ "<rcdrwAmt>1000000</rcdrwAmt>"
				+ "<cshTrferDstcd>1</cshTrferDstcd>"
				+ "<intgraTiaccCd>1234567890123</intgraTiaccCd>"
				+ "<intgraTiaccName>과목명</intgraTiaccName>"
				+ "<amtPtrnCd>00001</amtPtrnCd>"
				+ "<intgraTiaccCd2>1234567890123</intgraTiaccCd2>"
				+ "<tiaccName2>통합계정과목명2</tiaccName2>"
				+ "<amtPtrn2>00001</amtPtrn2>"
				+ "<ondmdYn>1</ondmdYn>"
				+ "<acno>12345678901234567890</acno>"
				+ "<mrvamt>1000000</mrvamt>"
				+"</InData>"
				+"</KYB_KYB2010_REQ1>";
		
    	System.out.println("KYB_KYB2010_REQ1 - fieldType 이 flot이면  2106(FLOT) 인데 2118 인 BIGDECIMAL 로 되어 있음");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("KYB_KYB2010_REQ1");
    	source.setData(data);
    	System.out.println(source.toString());
	}
	
	public void atestCase8Test() throws Exception {
		String data ="<PAH_KAA0499641_RES2>"
				+ "<OutData "
				+ " custMgtNo=\"1234567890\""
				+ " cnsntPrcssDstic=\"11111\""
				+ " smphUapplDstic=\"1\""
				+ " smphMchtlUniqNo=\"1\""
				+ " termlPshtCtnt=\"\""
				+ " exusTermlPshtCtnt=\"\""
				+ " smphMchtlDstic=\"\""
				+ " pgmVsnno=\"\""
				+ " wWWBnkgID=\"\""
				+ " regiYms=\"\""
				+ " lastModfiYMS=\"\""
				+ " finacInfoOferCtnt=\"\""
				+ " osVsncd=\"\""
				+ " appUniqno=\"\""
				+ " appDelYn=\"\""
				+ " msgPerRecvYnCtnt=\"\""
				+ " starNotiStupSupplCtnt=\"\""
				+ " sMSDpstCnsntYn=\"\""
				+ " cphnAreaNo=\"\""
				+ " cphnExnm=\"\""
				+ " cphnIdiviNo=\"\""
				+ " RcmdnPrdctName1=\"\""
				+ " RcmdnPrdctName2=\"\""
				+ " RcmdnPrdctName3=\"\""
				+ " RcmdnPrdctCd1=\"\""
				+ " RcmdnPrdctCd2=\"\""
				+ " RcmdnPrdctCd3=\"\""
				+ " MaktngPcDstcd=\"\""
				+ " outSpare=\"출력예비\" >"
				+"</OutData>"
				+"</PAH_KAA0499641_RES2>";
		System.out.println("PAH_KAA0499641_RES2 - XML 레이아웃 타입이면 fieldType이 BYTEARRAY 로 설정되면 2113(BYTEARRAY)인데 2101(String) ");
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("PAH_KAA0499641_RES2");
    	source.setData(data);
    	System.out.println(source.toString());
	}
	
	public void atestTemp() throws Exception {
		System.out.println("-----------------------------------------------");
		//String data ="{\"BFE_KFK120BF43_REQ1\":{\"InData\":{\"업무팀조회구분\":\"\",\"수신계좌수\":0,\"업무팀첫번째조회여부\":\"\",\"국내펀드포함총예금잔액\":0,\"첫번째조회여부\":\"1\",\"다음조회키영역\":{\"다음조회키4\":0,\"다음조회키3\":\"\",\"다음조회키2\":\"\",\"다음조회키1\":\"\"},\"국내펀드계좌수\":0,\"부ID고객식별자\":\"\",\"총예금잔액\":0,\"부ID고객관리번호\":\"\",\"총자동대출잔액\":0}}}";
		//String data ="{\"BFE_KFK120BF43_REQ1\":{\"InData\":{\"업무팀조회구분\":\"\",\"수신계좌수\":\"0\",\"업무팀첫번째조회여부\":\"\",\"국내펀드포함총예금잔액\":\"0\",\"첫번째조회여부\":\"1\",\"다음조회키영역\":{\"다음조회키4\":\"\",	\"다음조회키3\":\"\",	\"다음조회키2\":\"\",	\"다음조회키1\":\"\"},\"국내펀드계좌수\":\"0\",\"부ID고객식별자\":\"\",\"총예금잔액\":\"0\",\"부ID고객관리번호\":\"\",\"총자동대출잔액\":\"0\"}}}";
		String data ="{\"BFE_KFK120BF43_REQ1\":{\"InData\":{\"다음조회키영역\":{\"다음조회키4\":\"\",	\"다음조회키3\":\"\",	\"다음조회키2\":\"\",	\"다음조회키1\":\"\"}}}}";

		System.out.println(data);
		Message source = MessageFactory.getFactory().getMessage("BFE_KFK120BF43_REQ1");
		source.setData(data);
		System.out.println(source.toString());
	}
	
	
	public void testEbcdicDefaultValue() throws Exception {
		String data ="B";


		Message source = MessageFactory.getFactory().getMessage("EAA_EAA0501251_RES1");
		System.out.println("Init default value");
		System.out.println(source.toString());
		System.out.println("Set value");
		source.setData(CodeConversion.ascToSE(data.getBytes()));
		System.out.println("After set value");
		System.out.println(source.toString());
	}	
}
