<commit_before>package gov.nih.nci.cabig.caaers.api;

import gov.nih.nci.cabig.caaers.CaaersDbNoSecurityTestCase;
import gov.nih.nci.cabig.caaers.dao.InvestigatorDao;
import gov.nih.nci.cabig.caaers.dao.query.InvestigatorQuery;
import gov.nih.nci.cabig.caaers.domain.Identifier;
import gov.nih.nci.cabig.caaers.domain.Investigator;
import gov.nih.nci.cabig.caaers.domain.Organization;
import gov.nih.nci.cabig.caaers.domain.SiteInvestigator;
import gov.nih.nci.cabig.caaers.domain.repository.InvestigatorRepository;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

public class InvestigatorMigratorServiceTest extends CaaersDbNoSecurityTestCase {

	private InvestigatorMigratorService svc = null;
	private JAXBContext jaxbContext = null;
	private Unmarshaller unmarshaller = null;
	private gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff staff = null;
	private File xmlFile = null;
	private InvestigatorDao investigatorDao = null;
	private InvestigatorRepository investigatorRepository;
	Identifier identifier = null;
	Organization organization = null;
	Investigator updatedInvestigator = null;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.integration.schema.investigator");
		unmarshaller = jaxbContext.createUnmarshaller();
		svc = (InvestigatorMigratorService)getDeployedApplicationContext().getBean("investigatorMigratorService");
		investigatorRepository = (InvestigatorRepository)getDeployedApplicationContext().getBean("investigatorRepository");
		investigatorDao = (InvestigatorDao)getDeployedApplicationContext().getBean("investigatorDao");

	}

	public void testInvestigatorSave(){
		try {
			//Create or update , whatever it is new data will be populated ..
			//xmlFile = new File ("/Users/sakkala/tech-workspace/caaers12/core/src/test/resources/gov/nih/nci/cabig/caaers/api/testdata/CreateInvestigatorTest.xml");
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/CreateInvestigatorTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);	
			
			//update with modified data ..
			//xmlFile = new File ("/Users/sakkala/tech-workspace/caaers12/core/src/test/resources/gov/nih/nci/cabig/caaers/api/testdata/UpdateInvestigatorTest.xml");
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/UpdateInvestigatorTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);
			
			updatedInvestigator = fetchInvestigator("l1");
			
			//Below lines commented sine they are being fetched as null from DB.
			//Not sure how the Entity is REMOTE in DB. Flow needs to be relooked 
			//assertNotNull(updatedInvestigator);
			//assertEquals("870-098-7777", updatedInvestigator.getFaxNumber());
			//assertEquals("888-098-0099", updatedInvestigator.getPhoneNumber());
			
//			update site investigators data ..
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/UpdateSiteInvestigatorsTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);
			
			assertNotNull(updatedInvestigator);
			updatedInvestigator = fetchInvestigator("sr-1");
			
			//get site investigators.
			List<SiteInvestigator> siteInvestigators = updatedInvestigator.getSiteInvestigatorsInternal();
			for (SiteInvestigator siteInvestigator:siteInvestigators) {
				if (siteInvestigator.getEmailAddress().equals("<EMAIL>")) {
					assertEquals("NCI", siteInvestigator.getOrganization().getNciInstituteCode());
				}
//				newly added site investigator<commit_msg>fixing testcases<commit_after>package gov.nih.nci.cabig.caaers.api;

import gov.nih.nci.cabig.caaers.CaaersDbNoSecurityTestCase;
import gov.nih.nci.cabig.caaers.dao.InvestigatorDao;
import gov.nih.nci.cabig.caaers.dao.query.InvestigatorQuery;
import gov.nih.nci.cabig.caaers.domain.Identifier;
import gov.nih.nci.cabig.caaers.domain.Investigator;
import gov.nih.nci.cabig.caaers.domain.Organization;
import gov.nih.nci.cabig.caaers.domain.SiteInvestigator;
import gov.nih.nci.cabig.caaers.domain.repository.InvestigatorRepository;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

public class InvestigatorMigratorServiceTest extends CaaersDbNoSecurityTestCase {

	private InvestigatorMigratorService svc = null;
	private JAXBContext jaxbContext = null;
	private Unmarshaller unmarshaller = null;
	private gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff staff = null;
	private File xmlFile = null;
	private InvestigatorDao investigatorDao = null;
	private InvestigatorRepository investigatorRepository;
	Identifier identifier = null;
	Organization organization = null;
	Investigator updatedInvestigator = null;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		jaxbContext = JAXBContext.newInstance("gov.nih.nci.cabig.caaers.integration.schema.investigator");
		unmarshaller = jaxbContext.createUnmarshaller();
		svc = (InvestigatorMigratorService)getDeployedApplicationContext().getBean("investigatorMigratorService");
		investigatorRepository = (InvestigatorRepository)getDeployedApplicationContext().getBean("investigatorRepository");
		investigatorDao = (InvestigatorDao)getDeployedApplicationContext().getBean("investigatorDao");

	}

	public void testInvestigatorSave(){
		try {
			//Create or update , whatever it is new data will be populated ..
			//xmlFile = new File ("/Users/sakkala/tech-workspace/caaers12/core/src/test/resources/gov/nih/nci/cabig/caaers/api/testdata/CreateInvestigatorTest.xml");
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/CreateInvestigatorTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);	
			
			//update with modified data ..
			//xmlFile = new File ("/Users/sakkala/tech-workspace/caaers12/core/src/test/resources/gov/nih/nci/cabig/caaers/api/testdata/UpdateInvestigatorTest.xml");
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/UpdateInvestigatorTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);
			
			updatedInvestigator = fetchInvestigator("l1");
			
			//Below lines commented sine they are being fetched as null from DB.
			//Not sure how the Entity is REMOTE in DB. Flow needs to be relooked 
			//assertNotNull(updatedInvestigator);
			//assertEquals("870-098-7777", updatedInvestigator.getFaxNumber());
			//assertEquals("888-098-0099", updatedInvestigator.getPhoneNumber());
			
//			update site investigators data ..
			xmlFile = getResources("classpath*:gov/nih/nci/cabig/caaers/api/testdata/UpdateSiteInvestigatorsTest.xml")[0].getFile();
			staff = (gov.nih.nci.cabig.caaers.integration.schema.investigator.Staff)unmarshaller.unmarshal(xmlFile);
			svc.saveInvestigator(staff);
			
			assertNotNull(updatedInvestigator);
			updatedInvestigator = fetchInvestigator("l1");
			
			//get site investigators.
			List<SiteInvestigator> siteInvestigators = updatedInvestigator.getSiteInvestigatorsInternal();
			for (SiteInvestigator siteInvestigator:siteInvestigators) {
				if (siteInvestigator.getEmailAddress().equals("<EMAIL>")) {
					assertEquals("NCI", siteInvestigator.getOrganization().getNciInstituteCode());
				}
//				newly added site investigator
{'fraction_non_alphanumeric': 0.11449292593032934, 'fraction_numerical': 0.006895731779812151, 'mean_word_length': 5.660332541567696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2502626', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2700, 'n_words': 390}