use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getAllRelationships_shouldReturnAllRelationshipExcludingVoidedWhenIncludeVoidedEqualsFalse.
/**
* @see PersonService#getAllRelationships(null)
*/
@Test
public void getAllRelationships_shouldReturnAllRelationshipExcludingVoidedWhenIncludeVoidedEqualsFalse() throws Exception {
executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
List<Relationship> relationships = Context.getPersonService().getAllRelationships(false);
assertTrue("At least one element, otherwise no checking for voided will take place", relationships.size() > 0);
boolean foundVoided = false;
for (Relationship relationship : relationships) {
if (relationship.getVoided()) {
foundVoided = true;
break;
}
}
Assert.assertFalse("There should be no voided relationship here", foundVoided);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided.
@Test
public void voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided() {
Relationship relationship = personService.getRelationship(1);
assertFalse("We need an unvoided relationship to test the method", relationship.getVoided());
String voidReason = "Something";
User user = Context.getUserService().getUser(501);
assertNotNull("need a user to void", user);
relationship.setVoidedBy(user);
// TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship
// is executed. Coverage of voidRelationship is low because relationship.getVoided() is true
// when entering voidRelationship
// Documented at TRUNK-5151
personService.voidRelationship(relationship, voidReason);
Relationship voidedRelationship = personService.getRelationship(1);
assertTrue(voidedRelationship.getVoided());
assertThat(voidedRelationship.getVoidReason(), is(voidReason));
assertNotNull(voidedRelationship.getDateVoided());
assertEquals(voidedRelationship.getVoidedBy(), user);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationshipsByPerson2_shouldFetchUnvoidedRelationshipsOnly.
/**
* @see PersonService#getRelationshipsByPerson(Person)
*/
@Test
public void getRelationshipsByPerson2_shouldFetchUnvoidedRelationshipsOnly() throws Exception {
executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredRelationship.xml");
PersonService personService = Context.getPersonService();
Person person = personService.getPerson(6);
List<Relationship> relationships = personService.getRelationshipsByPerson(person, new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be no relationship found given the person", relationships.isEmpty());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationship_shouldReturnNullWhenRelationshipWithGivenIdDoesNotExist.
/**
* @see PersonService#getRelationship(Integer)
*/
@Test
public void getRelationship_shouldReturnNullWhenRelationshipWithGivenIdDoesNotExist() throws Exception {
Relationship relationship = Context.getPersonService().getRelationship(10000);
Assert.assertNull(relationship);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships3_shouldFetchRelationshipsMatchingTheGivenRelType.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date)
*/
@Test
public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenRelType() throws Exception {
PersonService personService = Context.getPersonService();
RelationshipType relationshipType = personService.getRelationshipType(1);
List<Relationship> relationships = personService.getRelationships(null, null, relationshipType, new Date(), new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the relationship type", relationships.size() > 0);
}
Aggregations