/** * @see RequiredDataAdvice#isOpenmrsObjectCollection(Class<*>,Object) */ @Test public void isOpenmrsObjectCollection_shouldReturnTrueIfClassIsOpenmrsObjectList() throws Exception { List<Location> locations = new ArrayList<>(); Location location = new Location(); locations.add(location); Assert.assertTrue(RequiredDataAdvice.isOpenmrsObjectCollection(locations)); }
/** * @see RequiredDataAdvice#isOpenmrsObjectCollection(Class<*>,Object) */ @Test public void isOpenmrsObjectCollection_shouldReturnTrueIfClassIsOpenmrsObjectSet() throws Exception { Set<Location> locations = new HashSet<>(); Location location = new Location(); locations.add(location); Assert.assertTrue(RequiredDataAdvice.isOpenmrsObjectCollection(locations)); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotSetDateRetiredIfNonNull() { Date d = new Date(new Date().getTime() - 1000); // a time that is not "now" RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setDateRetired(d); // make dateRetired non null handler.handle(retireable, null, new Date(), " "); Assert.assertEquals(d, retireable.getDateRetired()); }
/** * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean) * @see ObsService#getObservationCount(List,List,List,List,List,List,Integer,Date,Date,boolean,String) */ @Test public void getObservationCount_shouldReturnCountOfObsWithLocationInGivenLocationsParameter() { ObsService obsService = Context.getObsService(); Integer count = obsService.getObservationCount(null, null, null, null, null, Collections.singletonList(new Location(1)), null, null, null, false, null); Assert.assertEquals(8, count.intValue()); }
/** * @see BaseOpenmrsDatatype#serialize(org.openmrs.OpenmrsObject) */ @Test public void serialize_shouldReturnTheUuidOfTheObject() { OpenmrsObject location = new Location(); String expectedUuid = "some uuid"; location.setUuid(expectedUuid); BaseOpenmrsDatatype datatype = new MockLocationDatatype(); Assert.assertEquals(expectedUuid, datatype.serialize(location)); } }
@Test public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception { PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1)); Patient associatedPatient = patientService.getPatient(2); patientIdentifier.setPatient(associatedPatient); PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier); Assert.assertNotNull(createdPatientIdentifier); Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId()); }
/** * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection, * java.util.Collection, java.util.Collection, boolean) */ @Test public void getEncounters_shouldGetEncountersByLocation() { EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setLocation(new Location(1)) .setIncludeVoided(true).createEncounterSearchCriteria(); List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria); assertEquals(6, encounters.size()); }
/** * @see BaseUnretireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldUnsetTheRetiredBit() { UnretireHandler<Retireable> handler = new BaseUnretireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); // make sure isRetired is set handler.handle(retireable, null, null, null); Assert.assertFalse(retireable.getRetired()); }
/** * @see BaseUnretireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotActOnAlreadyUnretiredObjects() { UnretireHandler<Retireable> handler = new BaseUnretireHandler(); Retireable retireable = new Location(); retireable.setRetired(false); handler.handle(retireable, null, null, "SOME REASON"); Assert.assertNull(retireable.getRetireReason()); }
/** * @see OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String) */ @Test public void handle_shouldTrimWhitespaceFromName() { String NAME = "the location name"; OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler(); Location loc = new Location(); loc.setName(" " + NAME + " "); handler.handle(loc, null, null, null); Assert.assertEquals(NAME, loc.getName()); }
private Obs buildObs() { Obs newObs = new Obs(); newObs.setConcept(Context.getConceptService().getConcept(1)); newObs.setValueNumeric(50d); newObs.setLocation(new Location(2)); return newObs; }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldSetRetiredByEvenIfRetiredBitIsSetButRetiredByIsNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); handler.handle(retireable, null, null, "THE REASON"); Assert.assertEquals("THE REASON", retireable.getRetireReason()); }
/** * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldReturnSavedObject() { Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); Location savedLocation = Context.getLocationService().saveLocation(location); Assert.assertEquals(location, savedLocation); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotSetRetiredByIfNonNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetiredBy(new User(3)); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(3, retireable.getRetiredBy().getId().intValue()); }
/** * @see BaseUnretireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldUnsetTheRetireReason() { UnretireHandler<Retireable> handler = new BaseUnretireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); retireable.setRetireReason("SOME REASON"); handler.handle(retireable, null, null, null); Assert.assertNull(retireable.getRetireReason()); }
/** * @see LocationService#saveLocation(Location) */ @Test(expected = APIException.class) public void saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound() { LocationTag tagWithoutName = new LocationTag("some random tag name", "a nonexistant tag"); Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); location.addTag(tagWithoutName); Context.getLocationService().saveLocation(location); }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test(expected = APIException.class) public void saveLocationTag_shouldThrowAPIExceptionIfTagHasNoName() { LocationTag tagWithoutName = new LocationTag(); Location location = new Location(); location.setName("Some name"); location.setDescription("Some description"); location.addTag(tagWithoutName); Context.getLocationService().saveLocation(location); }
/** * @see BaseUnretireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldUnsetTheRetirer() { UnretireHandler<Retireable> handler = new BaseUnretireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); retireable.setRetiredBy(new User(1)); handler.handle(retireable, null, null, null); Assert.assertNull(retireable.getRetiredBy()); }
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfRetiredAndRetireReasonIsNullOrEmpty() { Location location = new Location(); location.setName("County General"); location.setRetired(true); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertTrue(errors.hasFieldErrors("retireReason")); }
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldSetRetiredToFalseIfRetireReasonIsNullOrEmpty() { Location location = new Location(); location.setName("County General"); location.setRetired(true); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertFalse(location.getRetired()); }