Search in sources :

Example 6 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists.

/**
 * 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());
}
Also used : LocationTag(org.openmrs.LocationTag) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound.

/**
 * @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);
}
Also used : LocationTag(org.openmrs.LocationTag) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method retireLocationTag_shouldRetireLocationTagSuccessfully.

/**
 * @see LocationService#retireLocationTag(LocationTag,String)
 */
@Test
public void retireLocationTag_shouldRetireLocationTagSuccessfully() {
    LocationService ls = Context.getLocationService();
    // Get all tags.
    List<LocationTag> tagsBeforeRetired = ls.getAllLocationTags(true);
    List<LocationTag> tagsNotRetiredBefore = ls.getAllLocationTags(false);
    // Get a non-retired tag
    LocationTag tag = ls.getLocationTag(1);
    LocationTag retiredTag = ls.retireLocationTag(tag, "Just Testing");
    // make sure its still the same object
    assertEquals(retiredTag, tag);
    // Get all tags again.
    List<LocationTag> tagsAfterRetired = ls.getAllLocationTags(true);
    List<LocationTag> tagsNotRetiredAfter = ls.getAllLocationTags(false);
    // Make sure that all the values were filled in
    assertTrue(retiredTag.getRetired());
    assertNotNull(retiredTag.getDateRetired());
    assertEquals(Context.getAuthenticatedUser(), retiredTag.getRetiredBy());
    assertEquals("Just Testing", retiredTag.getRetireReason());
    // Both tag lists that include retired should be equal.
    assertEquals(tagsBeforeRetired, tagsAfterRetired);
    // Both tag lists that do not include retired should not be the same.
    assertNotSame(tagsNotRetiredBefore, tagsNotRetiredAfter);
}
Also used : LocationTag(org.openmrs.LocationTag) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocationTag_shouldThrowAPIExceptionIfTagHasNoName.

/**
 * @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);
}
Also used : LocationTag(org.openmrs.LocationTag) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with LocationTag

use of org.openmrs.LocationTag in project openmrs-core by openmrs.

the class LocationServiceTest method saveLocationTag_shouldUpdateLocationTagSuccessfully.

/**
 * Test a simple update to a location tag that is already in the database.
 *
 * @see LocationService#saveLocationTag(LocationTag)
 */
@Test
public void saveLocationTag_shouldUpdateLocationTagSuccessfully() {
    LocationService ls = Context.getLocationService();
    // get the location tag from the database
    LocationTag tag = ls.getLocationTag(1);
    // save the current values for comparison later
    String origName = tag.getName();
    String origDesc = tag.getDescription();
    // add values that are different than the ones in the initialData.xml file
    String newName = "new name";
    String newDesc = "new desc";
    tag.setName(newName);
    tag.setDescription(newDesc);
    // save to the db
    ls.saveLocationTag(tag);
    // fetch that encounter from the db
    LocationTag newestTag = ls.getLocationTag(tag.getLocationTagId());
    assertFalse("The name should be different", origName.equals(newName));
    assertTrue("The name should NOT be different", newestTag.getName().equals(newName));
    assertFalse("The name should be different", origDesc.equals(newDesc));
    assertTrue("The name should NOT be different", newestTag.getDescription().equals(newDesc));
}
Also used : LocationTag(org.openmrs.LocationTag) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

LocationTag (org.openmrs.LocationTag)21 Test (org.junit.Test)17 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)16 Location (org.openmrs.Location)8 BindException (org.springframework.validation.BindException)2 Errors (org.springframework.validation.Errors)2 Criteria (org.hibernate.Criteria)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1 Patient (org.openmrs.Patient)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Visit (org.openmrs.Visit)1 APIException (org.openmrs.api.APIException)1 LocationService (org.openmrs.api.LocationService)1 VisitService (org.openmrs.api.VisitService)1 AdtService (org.openmrs.module.emrapi.adt.AdtService)1 LocationDescriptor (org.openmrs.module.metadatadeploy.descriptor.LocationDescriptor)1 PaperRecord (org.openmrs.module.paperrecord.PaperRecord)1 PaperRecordServiceImpl (org.openmrs.module.paperrecord.PaperRecordServiceImpl)1 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1