/** * @see CohortService#getCohort(String) */ @Test public void getCohort_shouldGetCohortGivenAName() { executeDataSet(COHORT_XML); Cohort cohortToGet = service.getCohortByName("Example Cohort"); assertTrue(cohortToGet.getCohortId() == 2); }
/** * @see CohortService#getCohort(String) */ @Test public void getCohort_shouldGetTheNonvoidedCohortIfTwoExistWithSameName() { executeDataSet(COHORT_XML); // check to see if both cohorts have the same name and if one is voided List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(allCohorts.get(0).getName(), allCohorts.get(1).getName()); assertTrue(allCohorts.get(0).getVoided()); assertFalse(allCohorts.get(1).getVoided()); // the non-voided cohort should have an id of 2 assertTrue(allCohorts.get(1).getCohortId() == 2); // ask for the cohort by name Cohort cohortToGet = service.getCohortByName("Example Cohort"); // see if the non-voided one got returned assertTrue(cohortToGet.getCohortId() == 2); }
/** * @see CohortService#voidCohort(Cohort,String) */ @Test public void voidCohort_shouldFailIfReasonIsEmpty() { executeDataSet(COHORT_XML); // Get a non-voided, valid Cohort and try to void it with a null reason Cohort exampleCohort = service.getCohortByName("Example Cohort"); assertNotNull(exampleCohort); assertFalse(exampleCohort.getVoided()); // Now get the Cohort and try to void it with an empty reason exampleCohort = service.getCohortByName("Example Cohort"); assertNotNull(exampleCohort); assertFalse(exampleCohort.getVoided()); try { service.voidCohort(exampleCohort, ""); Assert.fail("voidCohort should fail with exception if reason is empty"); } catch (Exception e) {} }
/** * @see CohortService#getCohort(String) */ @Test public void getCohort_shouldOnlyGetNonVoidedCohortsByName() { executeDataSet(COHORT_XML); // make sure we have two cohorts with the same name and the first is voided List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(2, allCohorts.size()); assertTrue(allCohorts.get(0).getVoided()); assertFalse(allCohorts.get(1).getVoided()); // now do the actual test: getCohort by name and expect a non voided cohort Cohort exampleCohort = service.getCohortByName("Example Cohort"); assertNotNull(exampleCohort); // since TRUNK-5450 also non-active cohorts (with an end-date) are counted assertEquals(2, exampleCohort.size()); assertFalse(exampleCohort.getVoided()); }
/** * @see CohortService#voidCohort(Cohort,String) */ @Test public void voidCohort_shouldFailIfReasonIsNull() { executeDataSet(COHORT_XML); // Get a non-voided, valid Cohort and try to void it with a null reason Cohort exampleCohort = service.getCohortByName("Example Cohort"); assertNotNull(exampleCohort); assertFalse(exampleCohort.getVoided()); try { service.voidCohort(exampleCohort, null); Assert.fail("voidCohort should fail with exception if reason is null."); } catch (Exception e) {} // Now get the Cohort and try to void it with an empty reason exampleCohort = service.getCohortByName("Example Cohort"); assertNotNull(exampleCohort); assertFalse(exampleCohort.getVoided()); try { service.voidCohort(exampleCohort, ""); Assert.fail("voidCohort should fail with exception if reason is empty"); } catch (Exception e) {} }