/*
 * Created on Mar 2, 2006
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.va.med.esr.common.batchprocess;

import java.util.ArrayList;

import gov.va.med.esr.common.util.RuleAbstractTestCase;
import gov.va.med.esr.common.batchprocess.AacImportProcess;
import gov.va.med.esr.common.persistent.comms.ImportFileDAO;
import gov.va.med.esr.common.model.comms.CommsImportStatistics;
import gov.va.med.esr.common.model.comms.CmsMailedFileEntry;
import gov.va.med.esr.common.model.comms.CmsReturnedByUSPSFileEntry;
import gov.va.med.esr.common.model.comms.CmsErrorFileEntry;
import gov.va.med.esr.common.model.comms.CmsRejectFileEntry;

/**
 * @author DNS   TSAIG
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TestAacImportProcess extends RuleAbstractTestCase {

    public TestAacImportProcess(String testName) {
        super(testName);
    }

    
    

    public void testImportProcessStraight() {
        //login anonymous
        this.getLoginManager().loginAnonymous();

        try {
            AacImportProcess proc = (AacImportProcess)applicationContext.getBean("aacImportProcess");
            CommsImportStatistics stats = proc.execute(null);
            System.out.println("stats="+stats.getReturnedMailFileProcessedCount());
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }


    }

    public void testImportDAO_reads() throws Exception {
    	ImportFileDAO dao =   (ImportFileDAO)applicationContext.getBean("importFileDAO");
    	CommsImportStatistics stats = new CommsImportStatistics();    	

    	CmsMailedFileEntry mailed = null;
    	CmsRejectFileEntry reject = null;
    	CmsErrorFileEntry error = null;
    	CmsReturnedByUSPSFileEntry usps = null;
       	
    	ArrayList list = dao.readCmsMailedFile(stats);
    	if (list != null) {
        	mailed = (CmsMailedFileEntry)list.get(0);
        	if (mailed != null) 
        		System.out.println(mailed);
        		System.out.println("entry="+mailed+"\n"+mailed.getBarCode()+"\n"+mailed.getCommunicationId()+"\n"+mailed.getFormNumber());
    	}
    	 	
     	list = dao.readCmsErrorFile(stats);
     	if (list != null) {
        	error = (CmsErrorFileEntry)list.get(0);
        	if (error != null)
        		System.out.println("error="+error+"\n"+error.getBarCode()+"\n"+
        				error.getCommunicationId()+"\n"+error.getFormNumber()+"\n"+
        				error.getErrorCode());     		
     	}
       	
     	list = dao.readCmsRejectFile(stats);
     	if (list != null) {
        	reject = (CmsRejectFileEntry)list.get(0);
        	if (reject != null)
        		System.out.println("reject="+reject+"\n"+reject.getBarCode()+"\n"+
        				reject.getCommunicationId()+"\n"+reject.getFormNumber()+"\n"+
        				reject.getCode1Reject());     		
     	}
    	
     	list = dao.readCmsReturnedMailFile(stats);
     	if (list != null) {
        	usps = (CmsReturnedByUSPSFileEntry)list.get(0);
        	if (usps != null)
        		System.out.println("returned="+usps+"\n"+usps.getBarCode()+"\n"+
        				usps.getCommunicationId()+"\n"+usps.getFormNumber()+"\n");     		
     	}
    }


}
