/*
 * 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.common.persistent.hibernate;

//Java classes

//ESR classes
import gov.va.med.esr.common.model.ee.PrisonerOfWarRecord;
import gov.va.med.esr.common.model.lookup.PrisonerOfWarLocation;
import gov.va.med.esr.common.model.person.Person;
import gov.va.med.esr.common.util.DataSetupTestCase;



/**
 * @author DNS   MERCHA
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PrisonerOfWarRecordTest extends DataSetupTestCase {
	private PrisonerOfWarRecord pow = null;
	
	public PrisonerOfWarRecordTest(String name) {
        super(name);
        super.setDefaultRollback(false);
    }
	
	 public void setUpData() throws Exception {
        pow = new PrisonerOfWarRecord();
        PrisonerOfWarLocation loc = getLookupService().getPrisonerOfWarLocationByCode("1");
        pow.setConfinementLocation(loc);
    }
	 
	 public void tearDownData() throws Exception {
    	pow = null;
    }
	 
	 public void testAddPOW() throws Exception {
    	try {
    		// link pow to person
    		Person p = getPerson();
            // FIXME
            /*
    		p.addPrisonerOfWarRecord(pow);
            */
	   	
    		// save pow with person
    		personDao.saveObject(p);    	   
    	}
    	catch (Exception ex) {
    	    ex.printStackTrace();
    		fail("Failed to add pow", ex);
    	} 
    }
	 
	 public void testUpdatePOW() throws Exception {
         // FIXME
         /*
     	try {     	    
     	   	// insert a pow
 	        Person p = getPerson();
            
     	    Set pows = p.getPrisonerOfWarRecords();
     	    
     	   if(pows.isEmpty()) {
    		p.addPrisonerOfWarRecord(pow);
       		personDao.saveObject(p);
       		pows = ((Person) personDao.getByKey(p.getEntityKey())).getPrisonerOfWarRecords();
 	    }
     	   
     	    Iterator iter = pows.iterator();
     	   if (iter.hasNext()) 
     	   {
     	   		PrisonerOfWarRecord pw = (PrisonerOfWarRecord) iter.next();
     	   		pw.setConfinementLocation(getLookupService().getPrisonerOfWarLocationByCode("2"));
     	   		personDao.saveObject(p);     		    
     	   		return;                
            }
  	        fail("Did not update pow");
     	}
     	catch(Exception ex) {
     		fail("Failed to get pow", ex);
     	}
        */
     }
	 
	 public void testGetPOW() throws Exception {
         // FIXME
         /*
	    	try {
	    	    
	    	   	// insert a pow
		        Person p = getPerson();
		        p.removeAllPrisonerOfWarRecords();
		        p.addPrisonerOfWarRecord(pow);
		   	
	    	   	// save pow with person
		     	personDao.saveObject(p);
		   	   	
	    	    // refresh data from database 
	    	    Person retrievedPerson = (Person) personDao.getByKey(p.getEntityKey());
	    	    Set pows = retrievedPerson.getPrisonerOfWarRecords();
	    	    Iterator iter = pows.iterator();
	    	    System.out.println("got pow from retrieved");
	    	    while (iter.hasNext()) {
	    	        PrisonerOfWarRecord pw = (PrisonerOfWarRecord)iter.next();
	    		    if(pow.equals(pw)) {
	    		       // logger.info("Got POW = " + pw);
	    		        System.out.println("Got POW = " + pw);
	    		        return;
	    		    }
	            }
	            fail("Could not find POW ");
	    	}
	    	catch(Exception ex) {
	    		fail("Failed to get POW", ex);
	    	}
            */
	    }
        
}
