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

	TransformEngine engine = null;
	
	String comdata = "";
    
    
    public LayoutNewJsonTest(String name) {
        super(name);
    }

    public static Test suite() {
        /*
        * the dynamic way
        */
        return new TestSuite(LayoutNewJsonTest.class);
    }
    /**
     * EAI_UJSON2DEPTHEXT_REQ1
     * 	abc
     * 	grid1
     *   	long1         10,0
     *   	data2
     *   	grid2
     *      	data3
     *       	big4      15,5
     * abcd
     * grid3
     * 		long1         10,0
     *   	data2
     *   	grid4
     *      	data5
     *      	big6      15,0
     */
    public void setUp() throws Exception {
    	AllTests.setParams();
        // ��ȯ �ʱ�ȭ
        engine = TransformEngine.getInstance();

		comdata += "{                                                                      "+"\n";
		comdata += "    \"EAI_UJSON2DEPTHEXT_REQ1\":{                                      "+"\n";
		comdata += "        \"abc\":\"cba  \",                                             "+"\n";
		comdata += "        \"grid1\":[                                                    "+"\n";
		comdata += "            {                                                          "+"\n";
		comdata += "                \"long1\":1,                                           "+"\n";
		comdata += "                \"data2\":\"     \",                                   "+"\n";
		comdata += "                \"grid2\":[                                            "+"\n";
		comdata += "                    {                                                  "+"\n";
		//comdata += "                        \"data3\":\"12345\",                           "+"\n";
		comdata += "                        \"big4\":14.00000                              "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"13   \",                           "+"\n";
		comdata += "                        \"big4\":14.00001                              "+"\n";
		comdata += "                    }                                                  "+"\n";
		comdata += "                ]                                                      "+"\n";
		comdata += "            },                                                         "+"\n";
		comdata += "            {                                                          "+"\n";
		comdata += "                \"long1\":10000,                                       "+"\n";
		comdata += "                \"data2\":\"     \",                                   "+"\n";
		comdata += "                \"grid2\":[                                            "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"23   \",                           "+"\n";
		comdata += "                        \"big4\":24.00000                              "+"\n";
		comdata += "                    }                                                  "+"\n";
		comdata += "                ]                                                      "+"\n";
		comdata += "            },                                                         "+"\n";
		comdata += "            {                                                          "+"\n";
		comdata += "                \"long1\":1000000000,                                  "+"\n";
		comdata += "                \"data2\":\"     \",                                   "+"\n";
		comdata += "                \"grid2\":[                                            "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"31\",                              "+"\n";
		comdata += "                        \"big4\":1.1                                   "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"32\",                              "+"\n";
		comdata += "                        \"big4\":1234567890.1                          "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"33\",                              "+"\n";
		comdata += "                        \"big4\":1.12345                               "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data3\":\"34\",                              "+"\n";
		comdata += "                        \"big4\":1234567890.00034                      "+"\n";
		comdata += "                    }                                                  "+"\n";
		comdata += "                ]                                                      "+"\n";
		comdata += "            }                                                          "+"\n";
		comdata += "        ],                                                             "+"\n";
		comdata += "        \"abcd\":\"123\",                                              "+"\n";
		comdata += "        \"grid3\":[                                                    "+"\n";
		comdata += "            {                                                          "+"\n";
		comdata += "                \"long1\":1,                                           "+"\n";
		comdata += "                \"data2\":\"    1\",                                   "+"\n";
		comdata += "                \"grid4\":[                                            "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"00023\",                           "+"\n";
		comdata += "                        \"big6\":1                                     "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"     \",                           "+"\n";
		comdata += "                        \"big6\":100000                                "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"00035\",                           "+"\n";
		comdata += "                        \"big6\":900000003600011                       "+"\n";
		comdata += "                    }                                                  "+"\n";
		comdata += "                ]                                                      "+"\n";
		comdata += "            },                                                         "+"\n";
		comdata += "            {                                                          "+"\n";
		comdata += "                \"long1\":1000000000,                                  "+"\n";
		comdata += "                \"data2\":\"     \",                                   "+"\n";
		comdata += "                \"grid4\":[                                            "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"00061\",                           "+"\n";
		comdata += "                        \"big6\":0                                     "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"00062\",                           "+"\n";
		comdata += "                        \"big6\":123456                                "+"\n";
		comdata += "                    },                                                 "+"\n";
		comdata += "                    {                                                  "+"\n";
		comdata += "                        \"data5\":\"00063\",                           "+"\n";
		comdata += "                        \"big6\":900000003600011                       "+"\n";
		comdata += "                    }                                                  "+"\n";
		comdata += "                ]                                                      "+"\n";
		comdata += "            }                                                          "+"\n";
		comdata += "        ]                                                              "+"\n";
		comdata += "    }                                                                  "+"\n";
		comdata += "}                                                                      "+"\n";
        
        
        if (!engine.isStarted()) {
            engine.start();
        }
    }

    public void tearDown() throws Exception {
        //
    }
    /**
     * 
     * EAI_UJSON2DEPTH_REQ1
     * 	abc
     *	grid1
     *   	long1
     *   	data2
     *   	grid2
     *       	data3
     *       	big4
     * @throws Exception
     */
    public void atestUJSON2DEPTH() throws Exception {
  		System.out.println("testUJSON2DEPTH ==============================================================");
        //logger.debug("Transform08900001Test | testTransform()");

        //----------------------------------------------------------------------
        // source message ����
        //----------------------------------------------------------------------
    	String data ="";
//    	data = "{ \"EAI_UJSON2DEPTH_REQ1\": {"
//        + " \"abc\": \"cba\", "
//        + " \"grid1\": [ "
//        + "	{ \"data1\": \"1row\" , \"grid2\" : [ {\"data3\" : \"13\"},{\"data4\" : \"14\"} ]   } "
//        + "	,{ \"data1\": \"2row\" , \"grid2\" : [{ \"data3\" : \"23\"} ]   } "
//        + "	] "
//        + " } "
//        + "}";
    	data +="{                                                             "+"\n";
    	data +="    \"EAI_UJSON2DEPTH_REQ1\":{                                "+"\n";
    	data +="        \"abc\":\"cba\",                                      "+"\n";
    	data +="        \"grid1\":[                                           "+"\n";
    	data +="            {                                                 "+"\n";
    	data +="                \"long1\":1,                                  "+"\n";
    	data +="                \"grid2\":[                                   "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"data3\":\"13\",                     "+"\n";
    	data +="                        \"big4\":1.10000                      "+"\n";
    	data +="                    },                                        "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"data3\":\"13\",                     "+"\n";
    	data +="                        \"big4\":2.10000                      "+"\n";
    	data +="                    }                                         "+"\n";
    	data +="                ]                                             "+"\n";
    	data +="            },                                                "+"\n";
    	data +="            {                                                 "+"\n";
    	data +="                \"long1\":100000,                             "+"\n";
    	data +="                \"grid2\":[                                   "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"data3\":\"23\",                     "+"\n";
    	data +="                        \"big4\":22222.22222                  "+"\n";
    	data +="                    }                                         "+"\n";
    	data +="                ]                                             "+"\n";
    	data +="            },                                                "+"\n";
    	data +="            {                                                 "+"\n";
    	data +="                \"long1\":1000000000,                         "+"\n";
    	data +="                \"grid2\":[                                   "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"data3\":\"33\"                      "+"\n";
    	data +="                    },                                        "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"big4\":3333333333.33333             "+"\n";
    	data +="                    },                                        "+"\n";
    	data +="                    {                                         "+"\n";
    	data +="                        \"data3\":\"35\",                     "+"\n";
    	data +="                        \"big4\":3333333333.55555             "+"\n";
    	data +="                    }                                         "+"\n";
    	data +="                ]                                             "+"\n";
    	data +="            }                                                 "+"\n";
    	data +="        ]                                                     "+"\n";
    	data +="    }                                                         "+"\n";
    	data +="}                                                             "+"\n";
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_UJSON2DEPTH_REQ1");
        source.setData(data.getBytes());

        System.out.println("source="+source);
        System.out.println("beauti=\n" + ((String) source.getData()));
    }
    /**
     * EAI_UJSON2DEPTHEXT_REQ1
     * 	abc
     * 	grid1
     *   	long1
     *   	data2
     *   	grid2
     *      	data3
     *       	big4
     * abcd
     * grid3
     * 		long1
     *   	data2
     *   	grid4
     *      	data5
     *      	big6
     * @throws Exception
     */
    public void atestUJSON2DEPTHEXT() throws Exception {
  		System.out.println("testUJSON2DEPTHEXT ==============================================================");
        //logger.debug("Transform08900001Test | testTransform()");
        //----------------------------------------------------------------------
        // source message ����
        //----------------------------------------------------------------------
    	String data ="";
    	data = comdata;
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_UJSON2DEPTHEXT_REQ1");
        source.setData(data.getBytes());

        System.out.println("source="+source);
        System.out.println("beauti=\n" + ((String) source.getData()));
        

    }
    public void testJSON2JSON() throws Exception {
  		System.out.println("testJSON2JSON ==============================================================");
        //logger.debug("Transform08900001Test | testTransform()");

    	String data ="";
    	data = comdata;
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_UJSON2DEPTHEXT_REQ1");
        source.setData(data.getBytes());
        System.out.println(source.toString());
        System.out.println("beauti=\n" + ((String) source.getData()));
        

        Transformer transformer = engine.getTransformer(); 
        
        Message target = transformer.transform("TRANSFORM_EAI_NEWJSON2NEWJSON_REQ", new Message[] { source });
        System.out.println(target.toString());
        System.out.println("beauti=\n" + ((String) target.getData()));
        
    }
    public void atestJSON2FLAT() throws Exception {
    	System.out.println("testJSON2FLAT ==============================================================");
    	//logger.debug("Transform08900001Test | testTransform()");
    	
    	String data = comdata;
		System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_UJSON2DEPTHEXT_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source.toString());
    	 System.out.println("beauti=\n" + ((String) source.getData()));
    	
    	Transformer transformer = engine.getTransformer(); 
    	
    	Message target = transformer.transform("TRANSFORM_EAI_NEWJSON2FLAT_REQ", new Message[] { source });
    	System.out.println(target.toString());
    	System.out.println("["+new String((byte[])target.getData())+"]");
    	
    }

    public void atestFLAT2JSON() throws Exception {
    	System.out.println("testFLAT2JSON ==============================================================");
    	//logger.debug("Transform08900001Test | testTransform()");
    	
    	String data ="";
    	data = "cba  000030000000001     000021234500000000140000013   0000000014000010000010000     0000123   0000000024000001000000000     0000333   000000000000000     00000000000003435   000000000000036123000020000000001     00001000230000000000000241000000000     0000300033000000000000000     00000000000003400035900000003600011";
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_FLAT2DEPTHEXT_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source.toString());
    	System.out.println("["+new String((byte[])source.getData())+"]");
    	
    	
    	Transformer transformer = engine.getTransformer(); 
    	System.out.println("engine--------------------------------------------------");
    	
    	Message target = transformer.transform("TRANSFORM_EAI_FLAT2NEWJSON_REQ", new Message[] { source });
    	System.out.println(target.toString());
    	System.out.println("beauti=\n" + ((String) target.getData()));
    	
    }
 
    public void atestFLAT2JSONTYPE() throws Exception {
    	System.out.println("testFLAT2JSONTYPE ==============================================================");
    	//logger.debug("Transform08900001Test | testTransform()");
    	
    	String data ="";
    	data = "cba  000030000000001     000021234500000000140000013   0000000014000010000010000     0000123   0000000024000001000000000     0000333   000000000000000     00000000000003435   000000000000036123000020000000001     00001000230000000000000241000000000     0000300033000000000000000     00000000000003400035900000003600011";
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_FLATTYPE_REQ1");
    	source.setData(data.getBytes());
    	System.out.println(source.toString());
    	System.out.println("["+new String((byte[])source.getData())+"]");
    	
    	
//    	Transformer transformer = engine.getTransformer(); 
//    	System.out.println("engine--------------------------------------------------");
//    	
//    	Message target = transformer.transform("TRANSFORM_EAI_FLAT2UJSONTYPE_REQ", new Message[] { source });
//    	System.out.println(target.toString());
//    	System.out.println(target.getData());
    	
    }
    public void atestJSON2FLATTYPE() throws Exception {
    	System.out.println("testJSON2FLATTYPE ==============================================================");
    	//logger.debug("Transform08900001Test | testTransform()");
    	
    	String data ="";
    	data = "{ \"EAI_UJSONTYPE_REQ1\" : {                                ";
    	data+= "     \"STRING_VALUE\" : \"AAAA\"                            ";
    	data+= "    , \"STRING_NULL_VALUE\" : null                          ";
    	data+= "    , \"INT_VALUE\" : 12345                                 ";
    	data+= "    , \"INT_NULL_VALUE\" : null                             ";
//    	data+= "    , \"INT_SPACE_VALUE\" : \"     \"                       ";
    	data+= "    , \"LONG_VALUE\" : 1234567890                           ";
    	data+= "    , \"LONG_NULL_VALUE\" : null                            ";
//    	data+= "    , \"LONG_SPACE_VALUE\" : \"          \"                 ";
    	data+= "    , \"BIG_VALUE\" : 1234567890.12345                      ";
    	data+= "    , \"BIG_NULL_VALUE\" : null                             ";
//    	data+= "    , \"BIG_SPACE_VALUE\" : \"               \"             ";
    	data+= "    , \"BIG15_VALUE\" : 123456789012345                     ";
    	data+= "    , \"BIG15_NULL_VALUE\" : null                           ";
//    	data+= "    , \"BIG15_SPACE_VALUE\" : \"               \"           ";
    	data+= "    , \"HANGLE\" : \"�ѱ�\"                                   ";
    	data+= "    , \"ENG\" : \"ABCDEF\"                                  ";
    	data+= "}}";
    	System.out.println(data);
    	Message source = MessageFactory.getFactory().getMessage("EAI_UJSONTYPE_REQ1");
    	source.setData(data.getBytes("UTF-8"));
    	System.out.println(source.toString());
    	//System.out.println("["+new String((byte[])source.getData())+"]");
    	 
    	
//    	Transformer transformer = engine.getTransformer(); 
//    	System.out.println("engine--------------------------------------------------");
//    	
//    	Message target = transformer.transform("TRANSFORM_EAI_UJSON2FLATTYPE_REQ", new Message[] { source });
//    	System.out.println(target.toString());
//    	System.out.println(target.getData());
    	
    }
    
    
}
