@Override protected Person getExistingObject() { return personService.getPerson(EXISTING_ID); } }
@Test public void getPatients_shouldReturnOnlyPatients() { Person person = personService.getPerson(501); assertThat(person.getIsPatient(), is(false)); List<Patient> patients = patientService.getPatients(person.getGivenName()); assertThat(patients, is(empty())); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date) */ @Test public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception { PersonService personService = Context.getPersonService(); Person firstPerson = personService.getPerson(502); List<Relationship> relationships = personService.getRelationships(firstPerson, null, null, new Date(), new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the from person", relationships.size() > 0); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date,Date) */ @Test public void getRelationships3_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception { PersonService personService = Context.getPersonService(); Person secondPerson = personService.getPerson(7); List<Relationship> relationships = personService.getRelationships(null, secondPerson, null, new Date(), new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the to person", relationships.size() > 0); }
/** * @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); }
/** * @see PersonService#getPerson(Integer) */ @Test public void getPerson_shouldReturnNullWhenPersonNull() throws Exception { Assert.assertNull(Context.getPersonService().getPerson(null)); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType,Date) */ @Test public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception { PersonService personService = Context.getPersonService(); Person firstPerson = personService.getPerson(502); List<Relationship> relationships = personService.getRelationships(firstPerson, null, null, new Date()); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the from person", relationships.size() > 0); }
/** * @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); }
@Test public void shouldClearMillisecondsWhenUpdatingAnExistingObject() { Date dateWithMillisecond = new Date(567L); Date dateWithoutMillisecond = new Date(0L); Person person = personService.getPerson(1); person.setBirthdate(dateWithMillisecond); personService.savePerson(person); Context.flushSession(); assertThat(person.getBirthdate(), is(dateWithoutMillisecond)); }
/** * @see PersonService#getPerson(Integer) */ @Test public void getPerson_shouldReturnNullWhenNoPersonHasTheGivenId() throws Exception { Person person = Context.getPersonService().getPerson(10000); Assert.assertNull(person); }
/** * @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()); }
/** * @see PersonService#getRelationshipsByPerson(Person) */ @Test public void getRelationshipsByPerson_shouldFetchRelationshipsAssociatedWithTheGivenPerson() throws Exception { PersonService personService = Context.getPersonService(); Person person = personService.getPerson(2); List<Relationship> relationships = personService.getRelationshipsByPerson(person); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the person", relationships.size() > 0); }
/** * @see PersonService#getRelationships(Person,Person,RelationshipType) */ @Test public void getRelationships_shouldFetchRelationshipsMatchingTheGivenFromPerson() throws Exception { PersonService personService = Context.getPersonService(); Person firstPerson = personService.getPerson(502); List<Relationship> relationships = personService.getRelationships(firstPerson, null, null); Assert.assertNotNull(relationships); assertTrue("There should be relationship found given the from person", relationships.size() > 0); }
/** * @see RequireVoidReasonVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotThrowExceptionIfVoidReasonIsNullForUnsupportedTypes() { Person p = Context.getPersonService().getPerson(1); Context.getPersonService().voidPerson(p, null); } }
/** * @see PersonService#voidPerson(Person,String) */ @Test public void voidPerson_shouldVoidPatient() throws Exception { //given Person person = personService.getPerson(2); //when personService.voidPerson(person, "reason"); //then assertTrue(person.getVoided()); }
/** * @see PersonService#getRelationshipsByPerson(Person) */ @Test public void getRelationshipsByPerson_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); Assert.assertNotNull(relationships); assertTrue("There should be no relationship found given the person", relationships.isEmpty()); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldVoidNonPreferredPersonObject() throws Exception { Patient notPreferred = patientService.getPatient(2); voidOrders(Collections.singleton(notPreferred)); Context.getPatientService().mergePatients(patientService.getPatient(6), notPreferred); Assert.assertTrue(Context.getPersonService().getPerson(2).getVoided()); }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldUpdateExistingObjectWhenPersonIdIsNotNull() throws Exception { Person personSaved = Context.getPersonService().getPerson(1); Assert.assertNotNull(personSaved.getId()); personSaved.setGender("M"); Person personUpdated = Context.getPersonService().savePerson(personSaved); Assert.assertEquals("M", personUpdated.getGender()); }
/** * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[]) */ @Test public void onSave_shouldBeCalledWhenSavingOpenmrsObject() { User u = new User(); u.setSystemId("user"); u.setPerson(Context.getPersonService().getPerson(1)); Context.getUserService().createUser(u, "Admin123"); Assert.assertSame(Context.getAuthenticatedUser(), u.getCreator()); Assert.assertNotNull(u.getDateCreated()); }
@Test public void onSave_shouldPopulatePersonChangedByandPersonDateChangedIfPersonAlreadyExists() { Person person = Context.getPersonService().getPerson(1); Assert.assertNull(person.getPersonChangedBy()); Assert.assertNull(person.getPersonDateChanged()); person.setGender("F"); Context.flushSession(); Context.getPersonService().savePerson(person); Assert.assertNotNull(person.getPersonChangedBy()); Assert.assertNotNull(person.getPersonDateChanged()); }