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

import java.util.Date;

import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.dao.ParticipantDao;
import gov.nih.nci.cabig.caaers.dao.SiteDao;
import gov.nih.nci.cabig.caaers.domain.Participant;
import gov.nih.nci.cabig.caaers.domain.Site;
import gov.nih.nci.cabig.caaers.domain.Study;
import gov.nih.nci.cabig.caaers.domain.StudyParticipantAssignment;
import gov.nih.nci.cabig.caaers.domain.StudySite;

/**
 * @author <a href="mailto:<EMAIL>><NAME></a>
 * 
 */
public class StudyServiceTest extends CaaersDbTestCase {

    private SiteDao siteDao = (SiteDao) getApplicationContext().getBean("siteDao");
    private ParticipantDao participantDao = (ParticipantDao) getApplicationContext().getBean("participantDao");

    public String getTestDataFileName() {
        String fileName = "testdata/StudyServiceTest.xml";
        return fileName;
    }
    
    public void testCreateAssignNewParticipant() {

        try {
            int studySiteId = -3001;
            String siteGridId = "gridSite";
            Integer participantId = null;
            {
                Site site = siteDao.getByGridId(siteGridId);
                StudySite studySite = site.getStudySites().get(0);
                assertEquals("Wrong study site found in test setup", siteGridId, studySite.getGridId());
                Study study = studySite.getStudy();

                Participant participant = new Participant();
                participant.setFirstName("Mighty");
                participant.setMiddleName("A");
                participant.setLastName("Mouse");
                participant.setInstitution("Some institution");
                participant.setInstitutionalPatientNumber("Some patient number");
                participant.setDateOfBirth(new Date());

                StudyService svc = (StudyService) getApplicationContext()
                                .getBean("studyServiceAPI");
                StudyParticipantAssignment assignment = svc.assignParticipant(study, participant,
                                site);
                assertNotNull("Assignment is null", assignment);
                assertNotNull("Assignment not flushed", assignment.getId());
                assertNotNull("Assignment gridId is null", assignment.getGridId());
                participantId = assignment.getParticipant().getId();<commit_msg>Fixed data problem<commit_after>/**
 * 
 */
package gov.nih.nci.cabig.caaers.api;

import java.util.Date;

import gov.nih.nci.cabig.caaers.CaaersDbTestCase;
import gov.nih.nci.cabig.caaers.dao.ParticipantDao;
import gov.nih.nci.cabig.caaers.dao.SiteDao;
import gov.nih.nci.cabig.caaers.domain.Participant;
import gov.nih.nci.cabig.caaers.domain.Site;
import gov.nih.nci.cabig.caaers.domain.Study;
import gov.nih.nci.cabig.caaers.domain.StudyParticipantAssignment;
import gov.nih.nci.cabig.caaers.domain.StudySite;

/**
 * @author <a href="mailto:<EMAIL>><NAME></a>
 * 
 */
public class StudyServiceTest extends CaaersDbTestCase {

    private SiteDao siteDao = (SiteDao) getApplicationContext().getBean("siteDao");
    private ParticipantDao participantDao = (ParticipantDao) getApplicationContext().getBean("participantDao");

    public String getTestDataFileName() {
        String fileName = "testdata/StudyServiceTest.xml";
        return fileName;
    }
    
    public void testCreateAssignNewParticipant() {

        try {
            int studySiteId = -3001;
            String siteGridId = "gridSite";            
            Integer participantId = null;
            {
                Site site = siteDao.getByGridId(siteGridId);
                StudySite studySite = site.getStudySites().get(0);
                assertEquals("Wrong study site found in test setup", studySiteId, studySite.getId().intValue());
                Study study = studySite.getStudy();

                Participant participant = new Participant();
                participant.setFirstName("Mighty");
                participant.setMiddleName("A");
                participant.setLastName("Mouse");
                participant.setInstitution("Some institution");
                participant.setInstitutionalPatientNumber("Some patient number");
                participant.setDateOfBirth(new Date());
                participant.setGridId("gridParticipant");

                StudyService svc = (StudyService) getApplicationContext()
                                .getBean("studyServiceAPI");
                StudyParticipantAssignment assignment = svc.assignParticipant(study, participant,
                                site);
                assertNotNull("Assignment is null", assignment);
                assertNotNull("Assignment not flushed", assignment.getId());
                assertNotNull("Assignment gridId is null", assignment.getGridId());
                participantId = assignment.getParticipant().getId();
{'fraction_non_alphanumeric': 0.10665857113944546, 'fraction_numerical': 0.0020238818053025702, 'mean_word_length': 2.596797671033479, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1119138', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1384, 'n_words': 236}