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

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

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

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

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

    public void tearDown() throws Exception {
        //
    }
    
    public void testEuckrToUtf8() throws Exception {
    	System.out.println("EUC-KR TO UTF-8 ==============================================================");
    	
    	//----------------------------------------------------------------------
    	// source message 생성
    	//----------------------------------------------------------------------
    	String data ="";
    	data = "한글      ABCD1234  HANGLE    ";
    	Message source = MessageFactory.getFactory().getMessage("EAI_ASC_REQ1");
    	source.setData(data.getBytes());
    	
    	System.out.println("source="+source);
    	
    	//----------------------------------------------------------------------
    	// 변환 방식 1
    	//----------------------------------------------------------------------
    	Transformer transformer = engine.getTransformer();
    	Message target = transformer.transform("TRANSFORM_EAI_EUCKR2UTF8_REQ", new Message[] { source });
    	
    	System.out.println("target ="+target);
    	System.out.println("target new String(data) ="+new String((byte[])target.getData()));
    	
    	
        
    }
    public void testUtf8ToEuckr() throws Exception {
    	System.out.println("UTF-8 TO EUC-KR ==============================================================");
    	
    	//----------------------------------------------------------------------
    	// source message 생성
    	//----------------------------------------------------------------------
    	byte[] data = "한글    ABCD1234  HANGLE    ".getBytes("utf-8");
    	Message source = MessageFactory.getFactory().getMessage("EAI_ASC_REQ1");
    	source.setData(data);
    	
    	System.out.println("source="+source);
    	
    	//----------------------------------------------------------------------
    	// 변환 방식 1
    	//----------------------------------------------------------------------
    	Transformer transformer = engine.getTransformer();
    	Message target = transformer.transform("TRANSFORM_EAI_UTF82EUCKR_REQ", new Message[] { source });
    	
    	System.out.println("target ="+target);
    	System.out.println("target new String(data) ="+new String((byte[])target.getData()));
        
    }

    
    
}
