/*
 * Created on January, 2015
 *
 * 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
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;





import gov.va.med.esr.common.model.ee.AgentOrangeExposure;
import gov.va.med.esr.common.model.ee.CampLejeuneVerification;
//ESR classes

import gov.va.med.esr.common.model.ee.CampLejeuneVerificationMethod;
import gov.va.med.esr.common.model.ee.EnvironmentalContaminationExposure;
import gov.va.med.esr.common.model.ee.RadiationExposure;
import gov.va.med.esr.common.model.ee.SpecialFactor;
import gov.va.med.esr.common.model.lookup.CampLejeuneVerificationType;
import gov.va.med.esr.common.model.person.Person;
import gov.va.med.esr.common.model.person.id.VPIDEntityKeyImpl;
import gov.va.med.esr.common.persistent.person.PersonDAO;
import gov.va.med.esr.common.util.DataSetupTestCase;

/**
 * @author DNS   ZHANGS
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CampLejeuneTest extends DataSetupTestCase {
	
	public CampLejeuneTest(String name) {
        super(name);
        super.setDefaultRollback(false);
}
	public void setUpData() throws Exception {
		//Person p = buildSimplePerson();
		//p.addSpecialFactor(createCampLejeuneVerification());
    }
	
	public void tearDownData() throws Exception {
    	
    }
	 
	
	 
	 public void testRemoveCLVerificationMethod() throws Exception {
	    	try {
	    		
	    		PersonDAO dao = (PersonDAO) applicationContext.getBean("personDAO");
	   		 
	    		Person person = dao.getByVPID(new VPIDEntityKeyImpl("1008533405V377263"));
	    	
	    		System.out.println("Person Key = " + person.getPersonEntityKey());
	    		Set specialFactors = person.getSpecialFactors(); 
	    	

	    		if (specialFactors != null) {
	    			CampLejeuneVerification campLejeune = null;

	    			Iterator iterSpecialFactors = specialFactors.iterator();
	    			while (iterSpecialFactors.hasNext()) {
	    				SpecialFactor theSpecialFactor = (SpecialFactor) iterSpecialFactors
	    						.next();
	    			   if (theSpecialFactor instanceof CampLejeuneVerification) {
						   campLejeune = (CampLejeuneVerification) theSpecialFactor;
						   break;
	    			   }
	    			 
	    			}
	    			
	    		     if (campLejeune != null) {
	    		    	 campLejeune.removeAllCampLejeuneVerificationMethods();    
	    		     }
	    		
	    		}
	    			   	
	    		// save cl with person
	    		personDao.saveObject(person);
	    		setComplete(); 
	    		
	    	}
	    	catch (Exception ex) {
	    	    ex.printStackTrace();
	    		fail("Failed to remove Camp Lejeune Verification method", ex);
	    	} 
	    }
		 
	
	 public void testGetCLVerification() throws Exception {
	       
	    	try {
	    	    
	    		PersonDAO dao = (PersonDAO) applicationContext.getBean("personDAO");
	      		 
	    		Person retrievedPerson = dao.getByVPID(new VPIDEntityKeyImpl("1008533405V377263"));	   	   	
	    	    
	    	    Set clv = retrievedPerson.getSpecialFactors();
	    	    		
	    	    Iterator iter = clv.iterator();
	    	    System.out.println("got Special Factors from retrieved");
	    	    while (iter.hasNext()) {
	    	        SpecialFactor spFactor = (SpecialFactor)iter.next();
	    	        
	    	        if (spFactor instanceof CampLejeuneVerification) {
	    		       
	    		       // logger.info("Got CL = " + cl);
	    		        System.out.println("Got Camp Lejeune = " + spFactor);
	    		     }
	    	    }
	          
	           
	    	}
	    	catch(Exception ex) {
	    		fail("Failed to get Camp Lejeune", ex);
	    	}
	    }
}
