/*
 * Created on Aug 29, 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;

//EDB Classes
//import java.util.Date;
import java.math.BigDecimal;

import gov.va.med.esr.common.util.DataSetupTestCase;
//import gov.va.med.esr.common.infra.ImpreciseDate;
//import gov.va.med.esr.common.infra.ImpreciseDate;
import gov.va.med.esr.common.model.ee.MonetaryBenefitAward;
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 MonetaryBenefitAwardTest extends DataSetupTestCase {
	private MonetaryBenefitAward award = null;

	
	public MonetaryBenefitAwardTest(String name) {
		super(name);
		super.setDefaultRollback(false);
		
	}

	public void setUpData() throws Exception {
		award  = new MonetaryBenefitAward();
 
		award.setCheckAmount(new BigDecimal(1000));
    }
    
	public void tearDownData() throws Exception {
		award = null;
    }
    
    public void testAddMonetaryBenefitAward() throws Exception {
    	try {
    		// link MonetaryBenefitAward to person
    		Person p = getPerson();
    		p.setMonetaryBenefitAward(award);
	   	
    		// save MonetaryBenefitAward with person
    		personDao.saveObject(p);    	   
    	}
    	catch (Exception ex) {
    	    ex.printStackTrace();
    		fail("Failed to add MonetaryBenefitAward", ex);
    	} 
    }
	 
	 public void testUpdateMonetaryBenefitAward() throws Exception {
        
     	try {     	    
     	   	// insert a MonetaryBenefitAward
 	        Person p = getPerson();
 	       MonetaryBenefitAward mba = p.getMonetaryBenefitAward();
     	    
     	   if(mba.equals(null)) {
    		p.setMonetaryBenefitAward(mba);
       		personDao.saveObject(p);
       		mba = ((Person) personDao.getByKey(p.getEntityKey())).getMonetaryBenefitAward();
 	    }
 	    
     	   		mba.setCheckAmount(new BigDecimal(2000));
     	   		personDao.saveObject(p);     		    
     	   		return;                
     	}
     	catch(Exception ex) {
     		fail("Failed to get MonetaryBenefitAward", ex);
     	}
     }
	 
	 public void testGetMonetaryBenefitAward() throws Exception {
	       
	    	try {
	    	    
	    	   	// insert a MonetaryBenefitAward
		        Person p = getPerson();
		        p.setMonetaryBenefitAward(null);
		        p.setMonetaryBenefitAward(award);
		   	
	    	   	// save pow with person
		     	personDao.saveObject(p);
		   	   	
	    	    // refresh data from database 
	    	    Person retrievedPerson = (Person) personDao.getByKey(p.getEntityKey());
	    	    MonetaryBenefitAward benefit= retrievedPerson.getMonetaryBenefitAward();
	    	     
	    	    System.out.println("got MonetaryBenefitAward from retrieved");
	    		    if(benefit.equals(benefit)) {
	    		       // logger.info("Got MonetaryBenefitAward = " + benefit);
	    		        System.out.println("Got MonetaryBenefitAward = " + benefit);
	    		        return;
	    		    }
	    	}
	    	catch(Exception ex) {
	    		fail("Failed to get MonetaryBenefitAward", ex);
	    	}
	    }
}
