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 ArrayErrorLayoutTest extends TestCase {
	protected static Logger logger = Logger.getLogger("transformer");

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

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

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

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

    public void tearDown() throws Exception {
        //
    }

	public void testVfield() throws Exception {
		System.out.println("testVfield ==============================================================");
		Message target = null;
		byte[] data = null;
		byte[] result = null;
		target = MessageFactory.getFactory().getMessage("EAI_TST003_REQ1");
		//System.out.println("before="+target);
		//data = "KBO0002AAAA1AAAA2BBBB1BBBB20010ABCDEFGHIJ0005543210003AAAA1AAAA2BBBB1BBBB2CCCC1CCCC2".getBytes();//정상데이터
		//data = "KBO0003AAAA1AAAA2BBBB1BBBB2010ABCDEF00150005500050003A0003AAAA2BBBB1BBBB2CCCC1CCCC2".getBytes();//오류데이터
		
		
		//data = "KBO0000000000000003AAAA1AAAA2BBBB1BBBB2CCCC1CCCC2".getBytes();//정상데이터
		data = "KBO0000000000000005AAAA1AAAA2BBBB1BBBB2CCCC1CCCC2".getBytes();//정상데이터
		System.out.println(new String(data));
		target.setData(data);
		System.out.println(target);
		//result =(byte[])target.getData();
		//System.out.println("result=["+result.length+"][" + new String(result)+"]");
		//System.out.println("reqMsgP1="+target.getString("EAI_TST003_REQ1.InData.reqMsgP1"));
		//System.out.println("reqMsgP2="+target.getString("EAI_TST003_REQ1.InData.reqMsgP2"));

	} 
	public void atestTransformXmlToFlat() throws Exception {
		System.out.println("testTransformXmlToFlat ==============================================================");
	    Message source = MessageFactory.getFactory().getMessage("EAI_TST004_REQ2");
	    Message target = MessageFactory.getFactory().getMessage("EAI_TST004_REQ1");
	        
	    String reqXML = "<EAI_TST004_REQ2>"
	    		+ "<InData>"  // 
	    		+ "<reqGroupCoCd>KBO</reqGroupCoCd>"
	    		+ "<grid1>"
	    		+ "<field1>AAAA1</field1>"
	    		+ "<field2>BBBB1</field2>"
	    		+ "</grid1>"
	    		+ "<grid1>"
	    		+ "<field1>AAAA2</field1>"
	    		+ "<field2>BBBB2</field2>"
	    		+ "</grid1>"
	    		+ "<reqCount1>0010</reqCount1>"
	    		+ "<reqMsgP1>ABCDEFGHIJ</reqMsgP1>"
	    		+ "<reqCount2>0005</reqCount2>"
	    		+ "<reqMsgP2>54321</reqMsgP2>"
	    		+ "<grid2>"
	    		+ "<field1>AAAA1</field1>"
	    		+ "<field2>BBBB1</field2>"
	    		+ "</grid2>"
	    		+ "<grid2>"
	    		+ "<field1>AAAA2</field1>"
	    		+ "<field2>BBBB2</field2>"
	    		+ "</grid2>"        		
	    		+ "<grid2>"
	    		+ "<field1>AAAA3</field1>"
	    		+ "<field2>BBBB3</field2>"
	    		+ "</grid2>"        		
	    		+ "</InData>"
	    		+ "</EAI_TST004_REQ2>";
	        
	    source.setData(reqXML);
        Transformer transformer = engine.getTransformer();
        System.out.println("before="+target);
        transformer.transform("TRANSFORM_EAI_TST004_REQ", target, new Message[] { source });
        System.out.println("result=[" + new String((byte[])target.getData())+"]");
        System.out.println("after="+target);
		
	} 
    
}
