@Test public void testGetAllAssignedCoaches() throws ObjectNotFoundException { // basically the same as testGetAllAssignedCoachesLite() except // we expect Persons instead final Collection<UUID> expected = Lists.newArrayList(ADVISOR_0.id(), COACH_1.id()); final PagingWrapper<Person> result1 = personService.getAllAssignedCoaches(null); assertPersonCollectionsHaveSameIds(expected, result1.getRows()); // zero b/c the request specified no pagination, so impl skips total // result size calculation assertEquals(0, result1.getResults()); // now prove that getAllAssignedCoaches() doesn't lazily // create/return new coaches by creating a fixture where it could do so, // run the same method again, then checking that we get the exact // same results as before final Set<String> newExternalCoachUsernames = addCoachesToExternalDataAndAttributeService(5); final PagingWrapper<Person> result2 = personService.getAllAssignedCoaches(null); assertPersonCollectionsHaveSameIds(expected, result2.getRows()); // zero b/c the request specified no pagination, so impl skips total // result size calculation assertEquals(0, result2.getResults()); }
@Test public void testGetAllCurrentCoaches() throws ObjectNotFoundException { // unlike the getAllAssignedCoaches()/getAllAssignedCoachesLite() // pair, getAllCurrentCoaches()/getAllCurrentCoachesLite() have // significantly different behavior. Specifically the non-lite version, // tested here, *does* lazily create and return new Persons. The lite // version does not. final SortedSet<Person> result1 = personService.getAllCurrentCoaches(null); assertPersonCollectionsHaveSameIds(Lists.newArrayList(ADVISOR_0.id(), COACH_1.id()), result1); final Set<String> newExternalCoachUsernames = addCoachesToExternalDataAndAttributeService(2); final SortedSet<Person> result2 = personService.getAllCurrentCoaches(null); assertPersonCollectionsHaveSameIds( Lists.newArrayList( personService.personFromUsername("bulk_coach_001").getId(), personService.personFromUsername("bulk_coach_002").getId(), ADVISOR_0.id(), COACH_1.id()), result2); }
@Test public void testGetAllCurrentCoachesFiltersDuplicatesByIdNotName() throws ObjectNotFoundException { final String duplicatePersonSchoolId = ADVISOR_0.schoolId() + "_foo"; this.createExternalPerson( duplicatePersonSchoolId, ADVISOR_0.username() + "_foo", ADVISOR_0.firstName(), // everything else the same ADVISOR_0.lastName(), ADVISOR_0.middleName(), ADVISOR_0.primaryEmailAddress()); // this should create the person record Person duplicatePerson = personService.getBySchoolId(duplicatePersonSchoolId, true); assertNotNull(duplicatePerson); // sanity check final Person jamesDoe = person(JAMES_DOE); jamesDoe.setCoach(duplicatePerson); personService.save(jamesDoe); sessionFactory.getCurrentSession().flush(); final SortedSet<Person> result = personService.getAllCurrentCoaches(null); assertEquals(3, result.size()); }