use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationshipsByPerson2_shouldFetchRelationshipsAssociatedWithTheGivenPerson.
/**
* @see PersonService#getRelationshipsByPerson(Person)
*/
@Test
public void getRelationshipsByPerson2_shouldFetchRelationshipsAssociatedWithTheGivenPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person person = personService.getPerson(2);
List<Relationship> relationships = personService.getRelationshipsByPerson(person, new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the person", relationships.size() > 0);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsMatchingTheGivenToPerson.
/**
* @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
*/
@Test
public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception {
PersonService personService = Context.getPersonService();
Person secondPerson = personService.getPerson(7);
List<Relationship> relationships = personService.getRelationships(null, secondPerson, null, new Date());
Assert.assertNotNull(relationships);
assertTrue("There should be relationship found given the to person", relationships.size() > 0);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class PersonServiceTest method getRelationship_shouldReturnRelationshipWithGivenId.
/**
* @see PersonService#getRelationship(Integer)
*/
@Test
public void getRelationship_shouldReturnRelationshipWithGivenId() throws Exception {
Relationship relationship = Context.getPersonService().getRelationship(1);
Assert.assertNotNull(relationship);
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldFailIfEndDateIsBeforeStartDate.
/**
* @throws ParseException
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfEndDateIsBeforeStartDate() throws ParseException {
Relationship relationship = new Relationship(1);
relationship.setStartDate(Context.getDateFormat().parse("18/02/2012"));
relationship.setEndDate(Context.getDateFormat().parse("18/02/2001"));
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
new RelationshipValidator().validate(relationship, errors);
Assert.assertEquals(true, errors.hasErrors());
}
use of org.openmrs.Relationship in project openmrs-core by openmrs.
the class RelationshipValidatorTest method validate_shouldPassIfStartDateIsNotInFuture.
/**
* @see RelationshipValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassIfStartDateIsNotInFuture() {
Relationship relationship = new Relationship(1);
Map<String, String> map = new HashMap<>();
MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, -1);
Date lastYear = cal.getTime();
relationship.setStartDate(lastYear);
new RelationshipValidator().validate(relationship, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations