/** * @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#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#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) {} }
/** * @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 org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#delete(java.lang.Object, * java.lang.String, org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected void delete(Cohort cohort, String reason, RequestContext context) throws ResponseException { if (cohort.isVoided()) { // http operation DELETE is idempotent, so we return success here return; } Context.getCohortService().voidCohort(cohort, reason); }