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

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

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

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

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

    public void tearDown() throws Exception {
        //
    }


    public void testFlatToUJsonTransform() throws Exception {

        //----------------------------------------------------------------------
        // source message 생성
        //----------------------------------------------------------------------
    	//String data ="0200      12000               D                                                                                                                       ";
    	String data ="1234567890ABCDEFGHIJ한글";
        Message source = MessageFactory.getFactory().getMessage("EAI_TSTFULL_REQ1");
        source.setData(data.getBytes());
        System.out.println(source);

        //----------------------------------------------------------------------
        // 변환 방식 1
        //----------------------------------------------------------------------
        Transformer transformer = engine.getTransformer();
        Message target = transformer.transform("TRANSFORM_EAI_TSTFULL2UJSON_REQ", new Message[] { source });

        
//        System.out.println(target);
        System.out.println(target.toString());
        System.out.println("testFlatToJsonTransform >> [["+target.getData()+"]]");
        
    }    
    public void atestFlatToFlatTransform() 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_TSTASC2FULL_REQ", new Message[] { source });
    	
    	
//        System.out.println(target);
    	System.out.println(target.toString());
    	System.out.println("testFlatToFlatTransform >> [["+new String((byte[])target.getData())+"]]");
    	
    }    
    public void atestUJonToFlatTransform() throws Exception {
    	
    	//----------------------------------------------------------------------
    	// source message 생성
    	//----------------------------------------------------------------------
		String data ="{\"EAI_TSTUJSON_REQ1\":{\"GROUP\":{\"HANGLE\":\"\",\"TEXT\":\"1234567890ABCDEFGHIJ한글\",\"BASE\":\"\"}}}";
    	
    	Message source = MessageFactory.getFactory().getMessage("EAI_TSTUJSON_REQ1");
    	source.setData(data.getBytes("UTF-8"));
    	System.out.println(source);
    	
    	//----------------------------------------------------------------------
    	// 변환 방식 1
    	//----------------------------------------------------------------------
    	Transformer transformer = engine.getTransformer();
    	Message target = transformer.transform("TRANSFORM_EAI_TSTUJSON2FULL_REQ", new Message[] { source });
    	
    	
//        System.out.println(target);
    	System.out.println(target.toString());
    	System.out.println("testFlatToJsonTransform >> [["+new String((byte[])target.getData())+"]]");
    	
    }    
    
    

}
