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

//Java classes
//EDB Classes
import gov.va.med.esr.common.util.DataSetupTestCase;
import gov.va.med.esr.common.model.ee.MedicaidFactor;
import gov.va.med.esr.common.model.person.Person;

/**
 * @author DNS   MERCHA
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class MedicaidFactorTest extends DataSetupTestCase {
	private MedicaidFactor factor = null;
	
	public MedicaidFactorTest(String name) {
		super(name);
		super.setDefaultRollback(false);
		
	}
	
	public void setUpData() throws Exception {
        factor  = new MedicaidFactor();
 
        //factor.setLastUpdateDate(new Date());
        factor.setEligibleForMedicaid(Boolean.TRUE);
    }
    
	public void tearDownData() throws Exception {
		factor = null;
    }
    
    public void testAddMedicaidFactor() throws Exception {
    	try {
    		// link MedicaidFactor to person
    		Person p = getPerson();
    		p.setMedicaidFactor(factor);
	   	
    		// save MedicaidFactor with person
    		personDao.saveObject(p);    	   
    	}
    	catch (Exception ex) {
    	    ex.printStackTrace();
    		fail("Failed to add MedicaidFactor", ex);
    	} 
    }
	 
	 public void testUpdateMedicaidFactor() throws Exception {
        
     	try {     	    
     	   	// insert a MedicaidFactor
 	        Person p = getPerson();
 	       MedicaidFactor mf = p.getMedicaidFactor();
     	    
     	   if(mf.equals(null)) {
    		p.setMedicaidFactor(mf);
       		personDao.saveObject(p);
       		mf = ((Person) personDao.getByKey(p.getEntityKey())).getMedicaidFactor();
 	    }
 	    
     	   		mf.setEligibleForMedicaid(Boolean.FALSE);
     	   		//mf.setLastUpdateDate(new Date());
     	   		personDao.saveObject(p);     		    
     	   		return;                
     	}
     	catch(Exception ex) {
     		fail("Failed to get MedicaidFactor", ex);
     	}
     }
	 
	 public void testGetMedicaidFactor() throws Exception {
	       
	    	try {
	    	    
	    	   	// insert a MedicaidFactor
		        Person p = getPerson();
		        p.setMedicaidFactor(null);
		        p.setMedicaidFactor(factor);
		   	
	    	   	// save pow with person
		     	personDao.saveObject(p);
		   	   	
	    	    // refresh data from database 
	    	    Person retrievedPerson = (Person) personDao.getByKey(p.getEntityKey());
	    	    MedicaidFactor mfactor= retrievedPerson.getMedicaidFactor();
	    	     
	    	    System.out.println("got MedicaidFactor from retrieved");
	    		    if(mfactor.equals(mfactor)) {
	    		       // logger.info("MedicaidFactor  = " + mfactor);
	    		        System.out.println("Got MedicaidFactor = " + mfactor);
	    		        return;
	    		    }
	    	}
	    	catch(Exception ex) {
	    		fail("Failed to get MedicaidFactor", ex);
	    	}
	    }
}
