/** * @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); }
/** * You should be able to add a transient tag with an existing tag name. * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists() { LocationService ls = Context.getLocationService(); // First, create a new Location Location location = new Location(); location.setName("name"); location.setDescription("is a location"); // Add a transient tag with an existing name location.addTag(new LocationTag("General Hospital", null)); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); // Saved parent location should have exactly 1 tag assertEquals(1, newSavedLocation.getTags().size()); // Tag must be overwritten with tag with locationTagId == 1 assertNotNull("Location tag should have an ID now", newSavedLocation.getTags().iterator().next().getLocationTagId()); assertEquals(1, newSavedLocation.getTags().iterator().next().getLocationTagId().intValue()); }
/** * @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 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 OpenmrsMetadataSaveHandler#handle(OpenmrsMetadata,User,Date,String) */ @Test public void handle_shouldTrimWhitespaceFromDescription() { String DESC = "the location desc"; OpenmrsMetadataSaveHandler handler = new OpenmrsMetadataSaveHandler(); Location loc = new Location(); loc.setName("a name"); loc.setDescription(" " + DESC + " "); handler.handle(loc, null, null, null); Assert.assertEquals(DESC, loc.getDescription()); } }
/** * @see org.openmrs.validator.LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfLocationNameAlreadyExist() { Location location = new Location(); location.setName("Unknown Location"); location.setDescription("desc"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertTrue(errors.hasErrors()); }
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfAllFieldsAreCorrect() { Location location = new Location(); location.setName("County General"); location.setDescription("desc"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
location.setDescription(newDesc);
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfNameIsNullOrEmpty() { Location location = new Location(); location.setDescription("desc"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertFalse(errors.hasFieldErrors("description")); }
location.setDescription("is the parent"); ls.saveLocation(location); childA.setDescription("is a child"); location.addChildLocation(childA); childB.setDescription("is a child"); childA.addChildLocation(childB);
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfRetiredLocationIsGivenRetiredReason() { Location location = new Location(); location.setName("County General"); location.setDescription("desc"); location.setRetired(true); location.setRetireReason("Because I don't like County General"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
location.setDescription("is a location"); ls.saveLocation(location);
/** * Test to make sure that a simple save to a new location gets persisted to the database * * @see LocationService#saveLocation(Location) */ @Test public void saveLocation_shouldCreateLocationSuccessfully() { Location location = new Location(); location.setName("testing"); location.setDescription("desc"); location.setAddress1("123"); location.setAddress1("456"); location.setCityVillage("city"); location.setStateProvince("state"); location.setCountry("country"); location.setPostalCode("post"); location.setLatitude("lat"); location.setLongitude("lon"); LocationService ls = Context.getLocationService(); ls.saveLocation(location); Location newSavedLocation = ls.getLocation(location.getLocationId()); assertNotNull("The saved location should have an id now", location.getLocationId()); assertNotNull("We should get back a location", newSavedLocation); assertTrue("The created location needs to equal the pojo location", location.equals(newSavedLocation)); }
/** * @see HibernateAdministrationDAO#validate(Object,Errors) */ @Test public void validate_shouldPassValidationForLocationClassIfFieldLengthsAreCorrect() { Location location = new Location(); location.setName("name"); location.setDescription("description"); location.setAddress1("address1"); location.setAddress2("address2"); location.setAddress3("address3"); location.setAddress4("address4"); location.setAddress5("address5"); location.setAddress6("address6"); location.setCityVillage("cityVillage"); location.setStateProvince("stateProvince"); location.setCountry("country"); location.setPostalCode("postalCode"); location.setLatitude("latitude"); location.setLongitude("longitude"); location.setCountyDistrict("countyDistrict"); location.setRetireReason("retireReason"); Errors errors = new BindException(location, "location"); dao.validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see LocationValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Location location = new Location(); location.setName("name"); location.setDescription("description"); location.setAddress1("address1"); location.setAddress2("address2"); location.setAddress3("address3"); location.setAddress4("address4"); location.setAddress5("address5"); location.setAddress6("address6"); location.setCityVillage("cityVillage"); location.setStateProvince("stateProvince"); location.setCountry("country"); location.setPostalCode("postalCode"); location.setLatitude("latitude"); location.setLongitude("longitude"); location.setCountyDistrict("countyDistrict"); location.setRetireReason("retireReason"); Errors errors = new BindException(location, "location"); new LocationValidator().validate(location, errors); Assert.assertFalse(errors.hasErrors()); }
location.setDescription(longString); location.setAddress1(longString); location.setAddress2(longString);
String longString = "too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"; location.setName(longString); location.setDescription(longString); location.setAddress1(longString); location.setAddress2(longString);