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

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

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

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

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

    public void tearDown() throws Exception {
        //
    }

   
    public void atestASCFlat() throws Exception {
        Message source = MessageFactory.getFactory().getMessage("EAI_TSTASC_REQ1");
        System.out.println(source);
    }
    public void atestEBCDICFlat() throws Exception {
    	Message source = MessageFactory.getFactory().getMessage("EAI_TSTEBCDIC_REQ1");
    	System.out.println(source);
    }
    
    public void testAsc2Ebcdic() throws Exception {
    	
    	//----------------------------------------------------------------------
    	// source message 생성
    	//----------------------------------------------------------------------
		String data ="0000000002abcdefghij1234567890abcdefghijAbcdefghij2234567890Abcdefghij";
    	
    	Message source = MessageFactory.getFactory().getMessage("EAI_TSTASC_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source);
    	
    	//----------------------------------------------------------------------
    	// 변환 방식 1
    	//----------------------------------------------------------------------
    	Transformer transformer = engine.getTransformer();
    	Message target = transformer.transform("TRANSFORM_EAI_TSTASC2EBCDIC_REQ", new Message[] { source });
    	
    	
//        System.out.println(target);
    	System.out.println(target.toString());
    	System.out.println("testFlatToJsonTransform >> [["+new String((byte[])target.getData())+"]]");

    }
    public void testEbcdic2Asc() throws Exception {
    	
    	//----------------------------------------------------------------------
    	// source message 생성
    	//----------------------------------------------------------------------
    	String data ="0000000002abcdefghij1234567890abcdefghijAbcdefghij2234567890Abcdefghij";
    	byte[] temp = CodeConversion.ascToSE(data.getBytes());
    	Message source = MessageFactory.getFactory().getMessage("EAI_TSTEBCDIC_REQ1");
    	source.setData(temp);
    	System.out.println(source);
    	
    	//----------------------------------------------------------------------
    	// 변환 방식 1
    	//----------------------------------------------------------------------
    	Transformer transformer = engine.getTransformer();
    	Message target = transformer.transform("TRANSFORM_EAI_TSTEBCDIC2ASC_REQ", new Message[] { source });
    	
    	
//        System.out.println(target);
    	System.out.println(target.toString());
    	System.out.println("testFlatToJsonTransform >> [["+new String((byte[])target.getData())+"]]");
    	
    }

}
