/** * @see org.openmrs.api.CohortService#getAllCohorts() */ @Override @Transactional(readOnly = true) public List<Cohort> getAllCohorts() throws APIException { return Context.getCohortService().getAllCohorts(false); }
/** * @see CohortService#purgeCohort(Cohort) */ @Test public void purgeCohort_shouldDeleteCohortFromDatabase() { executeDataSet(COHORT_XML); List<Cohort> allCohorts = service.getAllCohorts(true); assertEquals(2, allCohorts.size()); service.purgeCohort(allCohorts.get(0)); allCohorts = service.getAllCohorts(true); assertEquals(1, allCohorts.size()); }
@Test public void getAllCohorts_shouldGetAllNonvoidedCohortsInDatabase() { executeDataSet(COHORT_XML); // call the method List<Cohort> allCohorts = service.getAllCohorts(); assertNotNull(allCohorts); // there is only one non-voided cohort in the data set assertEquals(1, allCohorts.size()); assertFalse(allCohorts.get(0).getVoided()); }
/** * @see CohortService#saveCohort(Cohort) */ @Test public void saveCohort_shouldCreateNewCohorts() { executeDataSet(COHORT_XML); // make sure we have two cohorts List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(2, allCohorts.size()); // make and save a new one Integer[] ids = { 2, 3 }; Cohort newCohort = new Cohort("a third cohort", "a cohort to add for testing", ids); service.saveCohort(newCohort); // see if the new cohort shows up in the list of cohorts allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(3, allCohorts.size()); }
/** * @see CohortService#voidCohort(Cohort,String) */ @Test public void voidCohort_shouldVoidCohort() { executeDataSet(COHORT_XML); // make sure we have a cohort that is not voided List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(2, allCohorts.size()); assertFalse(allCohorts.get(1).getVoided()); service.voidCohort(allCohorts.get(1), "voided for Test"); assertTrue(allCohorts.get(1).getVoided()); }
/** * @see CohortService#getAllCohorts() */ @Test public void getAllCohorts_shouldNotReturnAnyVoidedCohorts() { executeDataSet(COHORT_XML); // make sure we have two cohorts, the first of which 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 call the target method and see if the voided cohort shows up allCohorts = service.getAllCohorts(); assertNotNull(allCohorts); // only the non-voided cohort should be returned assertEquals(1, allCohorts.size()); assertFalse(allCohorts.get(0).getVoided()); }
/** * @see CohortService#getAllCohorts(boolean) */ @Test public void getAllCohorts_shouldReturnAllCohortsAndVoided() { executeDataSet(COHORT_XML); //data set should have two cohorts, one of which is voided List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(2, allCohorts.size()); assertTrue(allCohorts.get(0).getVoided()); assertFalse(allCohorts.get(1).getVoided()); // if called with false parameter, should not return the voided one allCohorts = service.getAllCohorts(false); assertNotNull(allCohorts); // only the non-voided cohort should be returned assertEquals(1, allCohorts.size()); assertFalse(allCohorts.get(0).getVoided()); }
/** * @see CohortService#voidCohort(Cohort,String) */ @Test public void voidCohort_shouldNotChangeAnAlreadyVoidedCohort() { executeDataSet(COHORT_XML); // make sure we have an already voided cohort List<Cohort> allCohorts = service.getAllCohorts(true); assertNotNull(allCohorts); assertEquals(2, allCohorts.size()); assertTrue(allCohorts.get(0).getVoided()); // Make sure the void reason is different from the reason to be given in the test assertNotNull(allCohorts.get(0).getVoidReason()); String reasonAlreadyVoided = allCohorts.get(0).getVoidReason(); String voidedForTest = "Voided for test"; assertFalse(voidedForTest.equals(reasonAlreadyVoided)); // Try to void and see if the void reason changes as a result Cohort voidedCohort = service.voidCohort(allCohorts.get(0), voidedForTest); assertFalse(voidedCohort.getVoidReason().equals(voidedForTest)); assertTrue(voidedCohort.getVoidReason().equals(reasonAlreadyVoided)); }
/** * @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#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 org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<Cohort> doGetAll(RequestContext context) throws ResponseException { return new NeedsPaging<Cohort>(Context.getCohortService().getAllCohorts(context.getIncludeAll()), context); }