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

import gov.nih.nci.cabig.caaers.CaaersTestCase;
import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.service.InteroperationService;
import gov.nih.nci.cabig.caaers.web.ae.CreateAdverseEventAjaxFacade;
import gov.nih.nci.cabig.caaers.dao.CtcDao;
import gov.nih.nci.cabig.caaers.dao.CtcTermDao;
import gov.nih.nci.cabig.caaers.dao.ParticipantDao;
import gov.nih.nci.cabig.caaers.dao.StudyDao;
import gov.nih.nci.cabig.caaers.dao.AdverseEventReportDao;
import gov.nih.nci.cabig.caaers.domain.Ctc;
import gov.nih.nci.cabig.caaers.domain.CtcCategory;
import gov.nih.nci.cabig.caaers.domain.CtcTerm;
import static gov.nih.nci.cabig.caaers.domain.Fixtures.*;
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.AdverseEventReport;
import static org.easymock.classextension.EasyMock.*;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Date;
import java.util.Arrays;

/**
 * @author <NAME>
 */
public class CreateAdverseEventAjaxFacadeTest extends CaaersTestCase {
    private CreateAdverseEventAjaxFacade facade;
    private StudyDao studyDao;
    private ParticipantDao participantDao;
    private CtcDao ctcDao;
    private CtcTermDao ctcTermDao;
    private AdverseEventReportDao aeReportDao;
    private InteroperationService interoperationService;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        studyDao = registerDaoMockFor(StudyDao.class);
        participantDao = registerDaoMockFor(ParticipantDao.class);
        ctcDao = registerDaoMockFor(CtcDao.class);
        ctcTermDao = registerDaoMockFor(CtcTermDao.class);
        aeReportDao = registerDaoMockFor(AdverseEventReportDao.class);
        interoperationService = registerMockFor(InteroperationService.class);

        facade = new CreateAdverseEventAjaxFacade();
        facade.setParticipantDao(participantDao);
        facade.setStudyDao(studyDao);
        facade.setCtcDao(ctcDao);
        facade.setCtcTermDao(ctcTermDao);
        facade.setAeReportDao(aeReportDao);
        facade.setInteroperationService(interoperationService);
    }

    public void testMatchParticipants() throws Exception {
        Participant expectedMatch = setId(3, createParticipant("Foo", "B"));
        expectedMatch.setDateOfBirth(new Date());  // set not null so we can be sure it isn't copied
        expect(participantDao.getBySubnames(aryEq(new String[] { "foo" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("foo", null);
        verifyMocks();

        assertEquals("Wrong number of results", 1, actualList.size());
        Participant actualMatch = actualList.get(0);
        assertNotSame("Returned match is not copy", expectedMatch, actualMatch);
        assertEquals("id not copied", 3, (int) actualMatch.getId());
        assertEquals("first not copied", "Foo", actualMatch.getFirstName());
        assertEquals("last not copied", "B", actualMatch.getLastName());
        assertNull("other field incorrectly copied", actualMatch.getDateOfBirth());
    }
    
    public void testMatchParticipantsMultipleSubnames() throws Exception {
        Participant expectedMatch = setId(5, new Participant());
        expect(participantDao.getBySubnames(aryEq(new String[] { "foo", "zappa" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("foo zappa", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
    }

    public void testMatchParticipantsFiltersByStudyId() throws Exception {
        List<Participant> expectedList = new ArrayList<Participant>();
        expectedList.add(createParticipant("Joe", "One"));
        expectedList.add(createParticipant("Joe", "Two"));
        Study study = setId(4, new Study());
        assignParticipant(expectedList.get(1), study, new Site());

        expect(participantDao.getBySubnames(aryEq(new String[] { "joe" })))
            .andReturn(expectedList);

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("joe", 4);
        verifyMocks();

        assertEquals("Wrong number of participants returned", 1, actualList.size());
        assertEquals("Wrong participant included", "Two", actualList.get(0).getLastName());
    }

    public void testMatchStudies() throws Exception {
        Study expectedMatch = setId(22, createStudy("Jim's Study"));
        expect(studyDao.getBySubnames(aryEq(new String[] { "jim" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Study> actualList = facade.matchStudies("jim", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
        Study actualMatch = actualList.get(0);
        assertNotSame("Returned match is not copy", expectedMatch, actualMatch);
        assertEquals("id not copied", 22, (int) actualMatch.getId());
        assertEquals("shortTitle not copied", "Jim's Study", actualMatch.getShortTitle());
        assertNull("extra field incorrectly copied", actualMatch.getLongTitle());
    }

    public void testMatchStudiesMultipleSubnames() throws Exception {
        Study expectedMatch = setId(22, createStudy("Jim's Study"));
        expect(studyDao.getBySubnames(aryEq(new String[] { "jules", "jim" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Study> actualList = facade.matchStudies("jules jim", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
    }<commit_msg>Test for response to whitespace-only autocomplete attempts<commit_after>package gov.nih.nci.cabig.caaers.web;

import gov.nih.nci.cabig.caaers.CaaersTestCase;
import gov.nih.nci.cabig.caaers.CaaersSystemException;
import gov.nih.nci.cabig.caaers.service.InteroperationService;
import gov.nih.nci.cabig.caaers.web.ae.CreateAdverseEventAjaxFacade;
import gov.nih.nci.cabig.caaers.dao.CtcDao;
import gov.nih.nci.cabig.caaers.dao.CtcTermDao;
import gov.nih.nci.cabig.caaers.dao.ParticipantDao;
import gov.nih.nci.cabig.caaers.dao.StudyDao;
import gov.nih.nci.cabig.caaers.dao.AdverseEventReportDao;
import gov.nih.nci.cabig.caaers.domain.Ctc;
import gov.nih.nci.cabig.caaers.domain.CtcCategory;
import gov.nih.nci.cabig.caaers.domain.CtcTerm;
import static gov.nih.nci.cabig.caaers.domain.Fixtures.*;
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.AdverseEventReport;
import static org.easymock.classextension.EasyMock.*;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Date;
import java.util.Arrays;
import java.util.Collections;

/**
 * @author <NAME>
 */
public class CreateAdverseEventAjaxFacadeTest extends CaaersTestCase {
    private CreateAdverseEventAjaxFacade facade;
    private StudyDao studyDao;
    private ParticipantDao participantDao;
    private CtcDao ctcDao;
    private CtcTermDao ctcTermDao;
    private AdverseEventReportDao aeReportDao;
    private InteroperationService interoperationService;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        studyDao = registerDaoMockFor(StudyDao.class);
        participantDao = registerDaoMockFor(ParticipantDao.class);
        ctcDao = registerDaoMockFor(CtcDao.class);
        ctcTermDao = registerDaoMockFor(CtcTermDao.class);
        aeReportDao = registerDaoMockFor(AdverseEventReportDao.class);
        interoperationService = registerMockFor(InteroperationService.class);

        facade = new CreateAdverseEventAjaxFacade();
        facade.setParticipantDao(participantDao);
        facade.setStudyDao(studyDao);
        facade.setCtcDao(ctcDao);
        facade.setCtcTermDao(ctcTermDao);
        facade.setAeReportDao(aeReportDao);
        facade.setInteroperationService(interoperationService);
    }

    public void testMatchParticipants() throws Exception {
        Participant expectedMatch = setId(3, createParticipant("Foo", "B"));
        expectedMatch.setDateOfBirth(new Date());  // set not null so we can be sure it isn't copied
        expect(participantDao.getBySubnames(aryEq(new String[] { "foo" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("foo", null);
        verifyMocks();

        assertEquals("Wrong number of results", 1, actualList.size());
        Participant actualMatch = actualList.get(0);
        assertNotSame("Returned match is not copy", expectedMatch, actualMatch);
        assertEquals("id not copied", 3, (int) actualMatch.getId());
        assertEquals("first not copied", "Foo", actualMatch.getFirstName());
        assertEquals("last not copied", "B", actualMatch.getLastName());
        assertNull("other field incorrectly copied", actualMatch.getDateOfBirth());
    }
    
    public void testMatchParticipantsMultipleSubnames() throws Exception {
        Participant expectedMatch = setId(5, new Participant());
        expect(participantDao.getBySubnames(aryEq(new String[] { "foo", "zappa" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("foo zappa", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
    }

    public void testMatchParticipantsFiltersByStudyId() throws Exception {
        List<Participant> expectedList = new ArrayList<Participant>();
        expectedList.add(createParticipant("Joe", "One"));
        expectedList.add(createParticipant("Joe", "Two"));
        Study study = setId(4, new Study());
        assignParticipant(expectedList.get(1), study, new Site());

        expect(participantDao.getBySubnames(aryEq(new String[] { "joe" })))
            .andReturn(expectedList);

        replayMocks();
        List<Participant> actualList = facade.matchParticipants("joe", 4);
        verifyMocks();

        assertEquals("Wrong number of participants returned", 1, actualList.size());
        assertEquals("Wrong participant included", "Two", actualList.get(0).getLastName());
    }

    public void testMatchParticipantsWithBlankToken() throws Exception {
        expect(participantDao.getBySubnames(aryEq(new String[] { })))
            .andReturn(Collections.<Participant>emptyList());

        replayMocks();
        List<Participant> actualList = facade.matchParticipants(" ", null);
        verifyMocks();

        assertEquals("Should return nothing", 0, actualList.size());
    }

    public void testMatchStudies() throws Exception {
        Study expectedMatch = setId(22, createStudy("Jim's Study"));
        expect(studyDao.getBySubnames(aryEq(new String[] { "jim" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Study> actualList = facade.matchStudies("jim", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
        Study actualMatch = actualList.get(0);
        assertNotSame("Returned match is not copy", expectedMatch, actualMatch);
        assertEquals("id not copied", 22, (int) actualMatch.getId());
        assertEquals("shortTitle not copied", "Jim's Study", actualMatch.getShortTitle());
        assertNull("extra field incorrectly copied", actualMatch.getLongTitle());
    }

    public void testMatchStudiesMultipleSubnames() throws Exception {
        Study expectedMatch = setId(22, createStudy("Jim's Study"));
        expect(studyDao.getBySubnames(aryEq(new String[] { "jules", "jim" })))
            .andReturn(Arrays.asList(expectedMatch));

        replayMocks();
        List<Study> actualList = facade.matchStudies("<NAME>", null);
        verifyMocks();

        assertEquals("Result not forwarded", 1, actualList.size());
    }
{'fraction_non_alphanumeric': 0.11875050974635022, 'fraction_numerical': 0.0033439360574178288, 'mean_word_length': 3.877486077963405, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3321283', 'n_tokens_mistral': 3829, 'n_tokens_neox': 3750, 'n_words': 678}