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

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

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

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

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

    public void tearDown() throws Exception {
        //
    }
    

    public void testJsonToFlatTransform() throws Exception {
  		System.out.println("Json TO Flat  ==============================================================");
        //logger.debug("Transform08900001Test | testTransform()");

        //----------------------------------------------------------------------
        // source message 생성
        //----------------------------------------------------------------------
    	String data ="";
    	data = "{\"XYZ_IDAS00000557_REQ\":{\"SYS_ID_S3\": \"\",        \"TLGR_BYKD_CD_S4\": \"0200\",        \"DLNG_DVSN_CD_S6\": \"100000\",        \"SDRV_DVSN_S1\": \"S\",        \"STAT_CD_S3\": \"\",        \"RSPNS_CD_S3\": \"000\",        \"TLGR_TRSM_YMD_S8\": \"\",        \"TLGR_TRSM_HR_S6\": \"\",        \"TLGR_CHAS_NO_S8\": \"\",      \"DLNG_OCRN_YMD_S8\": \"\",        \"CUST_NM\": \"테스트\",        \"CSNO\": \"12345\"}}";
    	data = "{\"XYZ_IDAS00000557_REQ\":{        \"TLGR_BYKD_CD_S4\": \"0200\",        \"DLNG_DVSN_CD_S6\": \"100000\",        \"SDRV_DVSN_S1\": \"S\",        \"STAT_CD_S3\": \"\",        \"RSPNS_CD_S3\": \"000\",        \"TLGR_TRSM_YMD_S8\": \"\",        \"TLGR_TRSM_HR_S6\": \"\",        \"TLGR_CHAS_NO_S8\": \"\",      \"DLNG_OCRN_YMD_S8\": \"\",        \"CUST_NM\": \"테스트\",        \"CSNO\": \"12345\"}}";

    	
        Message source = MessageFactory.getFactory().getMessage("XYZ_IDAS00000557_REQ");
        Message target1 = MessageFactory.getFactory().getMessage("XYZ_OTST00000005_REQ");
        System.out.println(target1);
//		String rootItemName = ((UJSONMessage)source).getLayout().getRootItem().getName();
//        JSONObject value = (JSONObject)JSONValue.parse(data);
//        JSONObject root = new JSONObject();
//        root.put(rootItemName, value);
//        data = root.toJSONString();  

        System.out.println("before="+source);
        source.setData(data);
        System.out.println("source="+source);

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

        System.out.println(target.toString());
        
    }
      
    
}
