dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24723
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12170: finished basic testing of PersonService
------------------------------------------------------------
revno: 12170
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-19 16:00:03 +0200
message:
finished basic testing of PersonService
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java 2013-09-19 13:34:03 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java 2013-09-19 14:00:03 +0000
@@ -30,8 +30,13 @@
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dxf2.events.person.DateOfBirth;
+import org.hisp.dhis.dxf2.events.person.DateOfBirthType;
import org.hisp.dhis.dxf2.events.person.Gender;
+import org.hisp.dhis.dxf2.events.person.Person;
import org.hisp.dhis.dxf2.events.person.PersonService;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.program.Program;
@@ -41,9 +46,12 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.Arrays;
+import java.util.Date;
import java.util.HashSet;
+import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -78,10 +86,10 @@
organisationUnitB.setParent( organisationUnitA );
- maleA = createPatient( 'B', Patient.MALE, organisationUnitA );
+ maleA = createPatient( 'A', Patient.MALE, organisationUnitA );
maleB = createPatient( 'B', Patient.MALE, organisationUnitB );
- femaleA = createPatient( 'A', Patient.FEMALE, organisationUnitA );
- femaleB = createPatient( 'A', Patient.FEMALE, organisationUnitB );
+ femaleA = createPatient( 'C', Patient.FEMALE, organisationUnitA );
+ femaleB = createPatient( 'D', Patient.FEMALE, organisationUnitB );
programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnitA );
programA.setUseBirthDateAsEnrollmentDate( true );
@@ -138,8 +146,86 @@
@Test
@Ignore
+ public void testGetPersonByOrganisationUnitAndGenderAndProgram()
+ {
+ assertEquals( 1, personService.getPersons( organisationUnitA, programA, Gender.MALE ).getPersons().size() );
+ assertEquals( 1, personService.getPersons( organisationUnitA, programA, Gender.FEMALE ).getPersons().size() );
+ assertEquals( 0, personService.getPersons( organisationUnitB, programA, Gender.MALE ).getPersons().size() );
+ assertEquals( 0, personService.getPersons( organisationUnitB, programA, Gender.FEMALE ).getPersons().size() );
+ }
+
+ @Test
+ public void getPersonByPatients()
+ {
+ List<Patient> patients = Arrays.asList( maleA, femaleB );
+ assertEquals( 2, personService.getPersons( patients ).getPersons().size() );
+ }
+
+ @Test
+ public void getPersonByUid()
+ {
+ assertEquals( maleA.getUid(), personService.getPerson( maleA.getUid() ).getPerson() );
+ assertEquals( femaleB.getUid(), personService.getPerson( femaleB.getUid() ).getPerson() );
+ assertNotEquals( femaleA.getUid(), personService.getPerson( femaleB.getUid() ).getPerson() );
+ assertNotEquals( maleA.getUid(), personService.getPerson( maleB.getUid() ).getPerson() );
+ }
+
+ @Test
+ public void getPersonByPatient()
+ {
+ assertEquals( maleA.getUid(), personService.getPerson( maleA ).getPerson() );
+ assertEquals( femaleB.getUid(), personService.getPerson( femaleB ).getPerson() );
+ assertNotEquals( femaleA.getUid(), personService.getPerson( femaleB ).getPerson() );
+ assertNotEquals( maleA.getUid(), personService.getPerson( maleB ).getPerson() );
+ }
+
+ @Test
+ @Ignore
public void testGetPersonByProgram()
{
assertEquals( 2, personService.getPersons( programA ).getPersons().size() );
}
+
+ @Test
+ public void testUpdatePerson()
+ {
+ Person person = personService.getPerson( maleA.getUid() );
+ person.setName( "UPDATED_NAME" );
+ person.setGender( Gender.TRANSGENDER );
+
+ ImportSummary importSummary = personService.updatePerson( person );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( "UPDATED_NAME", personService.getPerson( maleA.getUid() ).getName() );
+ assertEquals( Gender.TRANSGENDER, personService.getPerson( maleA.getUid() ).getGender() );
+ }
+
+ @Test
+ public void testSavePerson()
+ {
+ Person person = new Person();
+ person.setName( "NAME" );
+ person.setGender( Gender.MALE );
+ person.setOrgUnit( organisationUnitA.getUid() );
+
+ DateOfBirth dateOfBirth = new DateOfBirth( new Date(), DateOfBirthType.VERIFIED );
+ person.setDateOfBirth( dateOfBirth );
+
+ ImportSummary importSummary = personService.savePerson( person );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( "NAME", personService.getPerson( importSummary.getReference() ).getName() );
+ assertEquals( Gender.MALE, personService.getPerson( importSummary.getReference() ).getGender() );
+ assertEquals( DateOfBirthType.VERIFIED, personService.getPerson( importSummary.getReference() ).getDateOfBirth().getType() );
+ }
+
+ @Test
+ public void testDeletePerson()
+ {
+ Person person = personService.getPerson( maleA.getUid() );
+ personService.deletePerson( person );
+
+ assertNull( personService.getPerson( maleA.getUid() ) );
+ assertNotNull( personService.getPerson( maleB.getUid() ) );
+ }
}
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-19 13:34:03 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-19 14:00:03 +0000
@@ -137,6 +137,8 @@
emptyTable( "programstage" );
emptyTable( "program_organisationunits" );
emptyTable( "program" );
+ emptyTable( "patientidentifier" );
+ emptyTable( "patientidentifier_patient" );
emptyTable( "patient" );
emptyTable( "organisationunit" );
=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2013-09-19 13:34:03 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2013-09-19 14:00:03 +0000
@@ -945,6 +945,7 @@
patient.setName( "FirstName" + uniqueChar );
patient.setGender( Patient.MALE );
+ patient.setDobType( Patient.DOB_TYPE_VERIFIED );
patient.setBirthDate( getDate( 1970, 1, 1 ) );
patient.setRegistrationDate( new Date() );
patient.setOrganisationUnit( organisationUnit );
@@ -959,6 +960,7 @@
patient.setName( "FirstName" + uniqueChar );
patient.setGender( gender );
+ patient.setDobType( Patient.DOB_TYPE_VERIFIED );
patient.setBirthDate( getDate( 1970, 1, 1 ) );
patient.setRegistrationDate( new Date() );
patient.setOrganisationUnit( organisationUnit );