/*
 * Created on Aug 1, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.va.med.esr.service;


import gov.va.med.esr.common.model.person.Person;
import gov.va.med.esr.common.model.person.id.PersonIdEntityKeyImpl;
import gov.va.med.esr.common.persistent.person.PersonDAO;
import gov.va.med.esr.common.util.RuleAbstractTestCase;
import gov.va.med.esr.service.trigger.BulletinTrigger;
import gov.va.med.fw.persistent.DAOException;
import gov.va.med.fw.service.ServiceException;

import java.math.BigDecimal;
import java.util.Hashtable;

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

    private CommsEmailBulletinService service = null;

    public TestCommsEmailBulletinService(String testName) {
        super(testName);

    }

    private void setService()
    {
        if (service == null) {
            try {
                service = (CommsEmailBulletinService) applicationContext.getBean( "commsEmailBulletinService" );
            }
           catch (Exception e) {
                //if (logger.isDebugEnabled()) {
                    logger.trace("Failed to obtain a service this.applicationContext", e);
            }
        }
    }
/*	
    public void testSendSimpleEmail() throws Exception{
        
        setService();
	   
        String from = "PII                ";
    	String[] toList = {"PII                   "};
    	String[] ccList = null;
    	String subject = "Testing Comms Email Bulletin";
    	String bodyText = "This is a simple email test!";
    	
    	try{
    	    service.sendSimpleMailMessage(from, toList, ccList, subject, bodyText);
    	} catch (Exception ex)
    	{
    	    throw ex;
    	}
    }   
*/
/*	
	public void testGetEmptyBulletinDataTable()
	{

        
	    setService();
	    
	    try{
	        Hashtable tab = service.getEmptyBulletinDataTable("Geroge Test1");
	        tab = service.getEmptyBulletinDataTable("Geroge Test1");
	        tab = service.getEmptyBulletinDataTable("Geroge Test2");
	        tab = service.getEmptyBulletinDataTable("HEC Notification of Changes to Service Connected Percentage");	        
	    } catch (ServiceException sex)
	    {
	        sex.printStackTrace();
	    }
	    
	}
*/
/*	
    public void testInsertEmailBulletins()
    {
        CommsEmailBulletinDAO dao = null;
        
        try {
            dao = (CommsEmailBulletinDAO)applicationContext.getBean("commsEmailBulletinDAO");
        } catch (ServiceException sex)
        {
            sex.printStackTrace();
            fail("Fail to get a CommsEmailBulletinDAO", sex);
        }
        String[] name = new String [] {
                "HEC Notification of Changes to Service Connected Percentage",
                "HEC Notification of Changes in VA Pension Status",
                "HEC Notification of Change to Rated Disability- Rated Disability Added",
                "HEC Notification of Change to Rated Disability- Rated Disability Removed",
                "HEC Notification of Purple Heart is No",
                "HEC Notification of Need for Site to Verify Veteran",
                "Enrollment Letter Processing",
                "HEC Notification of Need for Site to Send Ineligible Information",
                "HEC Notification of Need for Site to Verify Veteran",
                "HEC Notification of Need for Site to Verify DOD Deletion"};

        String[] text = new String [] {
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                ""};
        
        String[] desc = new String [] {
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                ""};
        String[] subject = new String [] {
                "HEC Notification of changes to SC Percentage",
                "HEC Notification of changes to VA Pension Status",
                "HEC Notification of Rated Disabilities added",
                "HEC Notification of Rated Disabilities removed",
                "HEC Notification of Purple Heart is No",
                "HEC Notification of Need for Site to Verify Veteran",
                "Letter processing completed",
                "HEC Notification of need for site to send ineligible information",
                "HEC notification of need for site to verify veteran",
                "HEC notification of need for site to verify Date of Death deletion"};
        


        for (int i=0; i< name.length; i++)
        {

            CommsBulletin bul = new CommsBulletin();
            bul.setCommsBulletinName(name[i]);
            bul.setCommsBulletinText(text[i]);
            bul.setDescription(desc[i]);
            bul.setRecipient("PII                   ");
            bul.setSubject(subject[i]);        
        
	        try
	        {
	            dao.insert(bul);
	        } catch (DAOException dex)
	        {
	            dex.printStackTrace();
	            fail("Fail to get a CommsEmailBulletinDAO", dex);
	        }
        }
        
        setComplete() ; //to set transaction not to roll back
    }
*/
/*
    public void testSendingEmailBulletin1()
    {   
        String bullName = "Geroge Test1";
        
        setService();
        try
        {
            service.sendEmailBulletin("Geroge Test1", null);
        } catch (ServiceException sex)
        {
            sex.printStackTrace();
            fail("Fail to send a email bulletin: " + bullName, sex);
        }       
        
        setComplete();
    }
*/
/*    
    public void testSendingEmailBulletin2()
    {
        
        String bullName = "Geroge Test2";
        
        Hashtable dataTable = new Hashtable();
        dataTable.put("LastName","Anderson");
        dataTable.put("FirstName","Christopher");
        dataTable.put("AddressLine1","1200 Parkwood Blvd");
        dataTable.put("AddressLine2","#301 Suite 4");
        dataTable.put("City","Plano");
        dataTable.put("State","TX");
        dataTable.put("Zip","75024");

        setService();
        
        try
        {
            service.sendEmailBulletin("Geroge Test2", dataTable);
        } catch (ServiceException sex)
        {
            sex.printStackTrace();
            fail("Fail to send a email bulletin: " + bullName, sex);
        }        
    }
*/
    
    public void testSendingEmailBulletin()
    {

        String bullName = "HEC Notification of Changes to Service Connected Percentage";

        setService(); //set EmailBulletinService

        try
        {
            //get a person
            PersonDAO personDao = (PersonDAO)applicationContext.getBean("personDAO");
            Person person = (Person) personDao.getByKey(
                    new PersonIdEntityKeyImpl(new BigDecimal(21575292)));

            //populate SC related data
            Hashtable dataTable = service.getEmptyBulletinDataTable(bullName);
            dataTable.put("DateOfChange", "8/15/2005");
            dataTable.put("SCChangedFrom", "5");
            dataTable.put("SCChangedTo", "8");
            


            //send an email bulletin
            
            service.sendEmailBulletin(
                    BulletinTrigger.DataType.HEC_NOTIFY_POW_DISCREPANCY_NOT_MATCH,
                    java.util.Collections.unmodifiableMap(dataTable),
                    person);
                    
        } catch (DAOException dex)
        {
            dex.printStackTrace();
            fail("Fail to send a email bulletin: " + bullName, dex);
        } catch (ServiceException ex)
        {
            ex.printStackTrace();
            fail("Fail to send a email bulletin: " + bullName, ex);
        }

        setComplete();
    }

    /**
     * Test sending email bulletin to specified recipient. 
     */
/*
	public void testSendingDeliveryPreferenceChangeNotification()
			throws Exception {
		// set EmailBulletinService
		setService(); 

		String emailAddress = "PII                ";
		
		service.sendEmailBulletin(
				BulletinTrigger.DataType.DELIVERY_PREFERENCE_CHANGE_MAIL_TO_ONLINE,
				emailAddress);
		
		service.sendEmailBulletin(
				BulletinTrigger.DataType.DELIVERY_PREFERENCE_CHANGE_ONLINE_TO_MAIL,
				emailAddress);
		
		service.sendEmailBulletin(
				BulletinTrigger.DataType.TRIGGER_HANDBOOK_COMMUNICATION,
				emailAddress);

		setComplete();
	}
*/
}
