package com.eactive.eai.transformer;

import org.apache.commons.lang3.time.StopWatch;

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

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

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

    public void setUp() throws Exception {
        // 
        engine = TransformEngine.getInstance();

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

    public void tearDown() throws Exception {
        //
    }

    
    
	public void testJsonToFlatTransform2() throws Exception {
		System.out.println("==============================================================");

		// ----------------------------------------------------------------------
		// source message 
		// ----------------------------------------------------------------------
		String data = "";

		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		Message source = MessageFactory.getFactory().getMessage("KAE_KAE0403140_RES1");
		source.setBytes("KAE_KAE0403140_RES1.OutData.outBook.grid[0].groupCoCd", "111".getBytes());
		System.out.println(source);

		Transformer transformer = engine.getTransformer();
		Message target = transformer.transform("TRANSFORM_KCR_KAE0403140KCR_RES", new Message[] { source });

		System.out.println("[" + new String((byte[]) target.getData()) + "]");
		stopWatch.stop();
		System.out.println("    elapsed       : " + stopWatch.toString());
	}
    
}
