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 com.eactive.eai.transformer.transform.TransformManager;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;


public class TransformGvAttrTest extends TestCase {
	protected static Logger logger = Logger.getLogger("transformer");

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

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

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

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

    public void tearDown() throws Exception {
        //
    }

    public void testTransformXMLtoFLAT() throws Exception {
    	long t = System.currentTimeMillis();
    	printLog("\n\n<<================================== testTransformXMLtoFLAT ==================================>> \n");
        Message source = MessageFactory.getFactory().getMessage("GVATTR_REQ1");
        Message target = MessageFactory.getFactory().getMessage("GVATTR_REQ2");
        
        String transformName = "TRANSFORM_GVATTR_REQ";
        //  xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.001.001.05\"
        
        String reqXML = "" 
        		+"<GVATTR_REQ1>"
        		+"<GetGiftCardInfo2 xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.001.001.05\">"
        		+"<list><req PtnrCd=\"CD00000001\" PtnrPw=\"PW00000002\" GfctNo=\"NO00000003\">REQDATA0</req></list>"
        		+"<list><req PtnrCd=\"CD00000011\" PtnrPw=\"PW00000012\" GfctNo=\"NO00000013\">REQDATA1</req></list>"
        		+"</GetGiftCardInfo2>"
        		+"</GVATTR_REQ1>"
        		;
        
        printLog("\nSOURCE XML STR : " + reqXML);
        int iter = 1;
        for(int i=0; i<iter; i++) {
	        source.setData(reqXML);
	        printLog("\nSOURCE  : \n" + source);
	        printLog("source.toLogString:\n" + source.toLogString());
	        printLog("TARGET    : \n" + target);
	        
	        printLog("\nTransform Start : \n");
	        
	        Transformer transformer = engine.getTransformer();
	        transformer.transform(transformName, target, new Message[] { source });
	 
	        printLog("\nSOURCE  : \n" + source);
	        printLog("TRANSFORM : \n" + TransformManager.getManager().getTransform(transformName));
	        printLog("TARGET    : \n" + target);
	        printLog("toLogString:\n" + target.toLogString());
        }
        System.out.println("$$ Transform iter="+ iter + ", Time (ms):" +(System.currentTimeMillis() - t) );
        
    }
    
    
    public void testTransformFLATtoXML() throws Exception {
    	long t = System.currentTimeMillis();
    	printLog("\n\n<<================================== testTransformFLATtoXML ==================================>> \n");
        Message source = MessageFactory.getFactory().getMessage("GVATTR_REQ2");
        Message target = MessageFactory.getFactory().getMessage("GVATTR_REQ1");
        
        String transformName = "TRANSFORM_GVATTR_RES";
        //  xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.001.001.05\"
        
        String reqFLAT = "02REQDATA2  CD00000011PW00000012NO00000013REQDATA3  CD00000021PW00000022NO00000023" 

        		;
        
        printLog("\nSOURCE FLAT STR : " + reqFLAT);
        int iter = 1;
        for(int i=0; i<iter; i++) {
	        source.setData(reqFLAT.getBytes());
	        printLog("\nSOURCE  : \n" + source);
	        printLog("source.toLogString:\n" + source.toLogString());
	        printLog("TARGET    : \n" + target);
	        
	        printLog("\nTransform Start : \n");
	        
	        Transformer transformer = engine.getTransformer();
	        transformer.transform(transformName, target, new Message[] { source });
	 
	        printLog("\nSOURCE  : \n" + source);
	        printLog("TRANSFORM : \n" + TransformManager.getManager().getTransform(transformName));
	        printLog("TARGET    : \n" + target);
	        printLog("toLogString:\n" + target.toLogString());
        }
        System.out.println("$$ Transform iter="+ iter + ", Time (ms):" +(System.currentTimeMillis() - t) );
        
    }
    public static void printLog(String message) {
    	 System.out.println(message);
    }
}
