← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12169: more PersonService tests

 

------------------------------------------------------------
revno: 12169
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-19 15:34:03 +0200
message:
  more PersonService tests
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:06:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java	2013-09-19 13:34:03 +0000
@@ -34,10 +34,17 @@
 import org.hisp.dhis.dxf2.events.person.PersonService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
-import org.junit.Assert;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramStage;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -48,6 +55,9 @@
     private PersonService personService;
 
     @Autowired
+    private ProgramInstanceService programInstanceService;
+
+    @Autowired
     private IdentifiableObjectManager manager;
 
     private Patient maleA;
@@ -58,6 +68,8 @@
     private OrganisationUnit organisationUnitA;
     private OrganisationUnit organisationUnitB;
 
+    private Program programA;
+
     @Override
     protected void setUpTest() throws Exception
     {
@@ -71,12 +83,20 @@
         femaleA = createPatient( 'A', Patient.FEMALE, organisationUnitA );
         femaleB = createPatient( 'A', Patient.FEMALE, organisationUnitB );
 
+        programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnitA );
+        programA.setUseBirthDateAsEnrollmentDate( true );
+        programA.setUseBirthDateAsIncidentDate( true );
+
         manager.save( organisationUnitA );
         manager.save( organisationUnitB );
         manager.save( maleA );
         manager.save( maleB );
         manager.save( femaleA );
         manager.save( femaleB );
+        manager.save( programA );
+
+        programInstanceService.enrollPatient( maleA, programA, null, null, organisationUnitA, null );
+        programInstanceService.enrollPatient( femaleA, programA, null, null, organisationUnitA, null );
     }
 
     @Override
@@ -88,13 +108,38 @@
     @Test
     public void testGetPersons()
     {
-        Assert.assertEquals( 4, personService.getPersons().getPersons().size() );
+        assertEquals( 4, personService.getPersons().getPersons().size() );
     }
 
     @Test
     public void testGetPersonByGender()
     {
-        Assert.assertEquals( 2, personService.getPersons( Gender.MALE ).getPersons().size() );
-        Assert.assertEquals( 2, personService.getPersons( Gender.FEMALE ).getPersons().size() );
+        assertEquals( 2, personService.getPersons( Gender.MALE ).getPersons().size() );
+        assertEquals( 2, personService.getPersons( Gender.FEMALE ).getPersons().size() );
+    }
+
+    @Test
+    public void testGetPersonByOrganisationUnit()
+    {
+        assertEquals( 2, personService.getPersons( organisationUnitA ).getPersons().size() );
+        assertEquals( 2, personService.getPersons( organisationUnitB ).getPersons().size() );
+    }
+
+    @Test
+    public void testGetPersonByOrganisationUnitAndGender()
+    {
+        assertEquals( 0, personService.getPersons( organisationUnitA, Gender.TRANSGENDER ).getPersons().size() );
+        assertEquals( 1, personService.getPersons( organisationUnitA, Gender.MALE ).getPersons().size() );
+        assertEquals( 1, personService.getPersons( organisationUnitA, Gender.FEMALE ).getPersons().size() );
+        assertEquals( 0, personService.getPersons( organisationUnitB, Gender.TRANSGENDER ).getPersons().size() );
+        assertEquals( 1, personService.getPersons( organisationUnitB, Gender.MALE ).getPersons().size() );
+        assertEquals( 1, personService.getPersons( organisationUnitB, Gender.FEMALE ).getPersons().size() );
+    }
+
+    @Test
+    @Ignore
+    public void testGetPersonByProgram()
+    {
+        assertEquals( 2, personService.getPersons( programA ).getPersons().size() );
     }
 }

=== 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:06:14 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java	2013-09-19 13:34:03 +0000
@@ -132,6 +132,11 @@
         emptyTable( "categorycombos_categories" );
         emptyTable( "categories_categoryoptions" );
 
+        emptyTable( "programstageinstance" );
+        emptyTable( "programinstance" );
+        emptyTable( "programstage" );
+        emptyTable( "program_organisationunits" );
+        emptyTable( "program" );
         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:06:14 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2013-09-19 13:34:03 +0000
@@ -28,16 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.File;
-import java.io.StringReader;
-import java.lang.reflect.Method;
-import java.util.*;
-import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.aggregation.AggregatedDataValueService;
@@ -107,6 +97,22 @@
 import org.springframework.aop.support.AopUtils;
 import org.xml.sax.InputSource;
 
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import java.io.File;
+import java.io.StringReader;
+import java.lang.reflect.Method;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -193,9 +199,9 @@
     /**
      * Creates a date.
      *
-     * @param year the year.
+     * @param year  the year.
      * @param month the month.
-     * @param day the day of month.
+     * @param day   the day of month.
      * @return a date.
      */
     public static Date getDate( int year, int month, int day )
@@ -232,7 +238,7 @@
      * method. This is useful for black-box testing where one will not know the
      * implementation type of the returned collection for a method.
      *
-     * @param actual the actual collection to check.
+     * @param actual    the actual collection to check.
      * @param reference the reference objects to check against.
      * @return true if the collections are equal, false otherwise.
      */
@@ -306,8 +312,8 @@
      * assumed.
      *
      * @param targetService the target service.
-     * @param fieldName the name of the dependency field in the target service.
-     * @param dependency the dependency.
+     * @param fieldName     the name of the dependency field in the target service.
+     * @param dependency    the dependency.
      */
     protected void setDependency( Object targetService, String fieldName, Object dependency )
     {
@@ -326,9 +332,9 @@
      * assumed.
      *
      * @param targetService the target service.
-     * @param fieldName the name of the dependency field in the target service.
-     * @param dependency the dependency.
-     * @param clazz the class type of the dependency.
+     * @param fieldName     the name of the dependency field in the target service.
+     * @param dependency    the dependency.
+     * @param clazz         the class type of the dependency.
      */
     protected void setDependency( Object targetService, String fieldName, Object dependency, Class<?> clazz )
     {
@@ -339,7 +345,7 @@
             String setMethodName = "set" + fieldName.substring( 0, 1 ).toUpperCase()
                 + fieldName.substring( 1, fieldName.length() );
 
-            Class<?>[] argumentClass = new Class<?>[] { clazz };
+            Class<?>[] argumentClass = new Class<?>[]{ clazz };
 
             Method method = targetService.getClass().getMethod( setMethodName, argumentClass );
 
@@ -357,7 +363,7 @@
      *
      * @param object the object.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     private <T> T getRealObject( T object )
         throws Exception
     {
@@ -395,7 +401,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param categoryCombo The category combo.
+     * @param categoryCombo   The category combo.
      */
     public static DataElement createDataElement( char uniqueCharacter, DataElementCategoryCombo categoryCombo )
     {
@@ -408,8 +414,8 @@
     }
 
     /**
-     * @param uniqueCharacter A unique character to identify the object.
-     * @param valueType The value type.
+     * @param uniqueCharacter     A unique character to identify the object.
+     * @param valueType           The value type.
      * @param aggregationOperator The aggregation operator.
      */
     public static DataElement createDataElement( char uniqueCharacter, String type, String aggregationOperator )
@@ -423,10 +429,10 @@
     }
 
     /**
-     * @param uniqueCharacter A unique character to identify the object.
-     * @param valueType The value type.
+     * @param uniqueCharacter     A unique character to identify the object.
+     * @param valueType           The value type.
      * @param aggregationOperator The aggregation operator.
-     * @param categoryCombo The category combo.
+     * @param categoryCombo       The category combo.
      */
     public static DataElement createDataElement( char uniqueCharacter, String type, String aggregationOperator,
         DataElementCategoryCombo categoryCombo )
@@ -442,9 +448,10 @@
 
     /**
      * @param categoryComboUniqueIdentifier A unique character to identify the
-     *        category combo.
-     * @param categoryOptionUniqueIdentifiers Unique characters to identify the
-     *        category options.
+     *                                      category combo.
+     * @param categoryOptionUniqueIdentifiers
+     *                                      Unique characters to identify the
+     *                                      category options.
      * @return
      */
     public static DataElementCategoryOptionCombo createCategoryOptionCombo( char categoryComboUniqueIdentifier,
@@ -465,7 +472,7 @@
     }
 
     /**
-     * @param categoryCombo the category combo.
+     * @param categoryCombo   the category combo.
      * @param categoryOptions the category options.
      * @return
      */
@@ -540,7 +547,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param type The type.
+     * @param type            The type.
      */
     public static Indicator createIndicator( char uniqueCharacter, IndicatorType type )
     {
@@ -589,7 +596,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param periodType The period type.
+     * @param periodType      The period type.
      */
     public static DataSet createDataSet( char uniqueCharacter, PeriodType periodType )
     {
@@ -626,7 +633,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param parent The parent.
+     * @param parent          The parent.
      */
     public static OrganisationUnit createOrganisationUnit( char uniqueCharacter, OrganisationUnit parent )
     {
@@ -668,9 +675,9 @@
     }
 
     /**
-     * @param type The PeriodType.
+     * @param type      The PeriodType.
      * @param startDate The start date.
-     * @param endDate The end date.
+     * @param endDate   The end date.
      */
     public static Period createPeriod( PeriodType type, Date startDate, Date endDate )
     {
@@ -693,7 +700,7 @@
 
     /**
      * @param startDate The start date.
-     * @param endDate The end date.
+     * @param endDate   The end date.
      */
     public static Period createPeriod( Date startDate, Date endDate )
     {
@@ -707,10 +714,10 @@
     }
 
     /**
-     * @param dataElement The data element.
-     * @param period The period.
-     * @param source The source.
-     * @param value The value.
+     * @param dataElement         The data element.
+     * @param period              The period.
+     * @param source              The source.
+     * @param value               The value.
      * @param categoryOptionCombo The data element category option combo.
      */
     public static DataValue createDataValue( DataElement dataElement, Period period, OrganisationUnit source, String value,
@@ -731,11 +738,11 @@
     }
 
     /**
-     * @param dataElement The data element.
-     * @param period The period.
-     * @param source The source.
-     * @param value The value.
-     * @param lastupdated The date.
+     * @param dataElement         The data element.
+     * @param period              The period.
+     * @param source              The source.
+     * @param value               The value.
+     * @param lastupdated         The date.
      * @param categoryOptionCombo The data element category option combo.
      */
     public static DataValue createDataValue( DataElement dataElement, Period period, OrganisationUnit source, String value,
@@ -757,10 +764,10 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param operator The operator.
-     * @param leftSide The left side expression.
-     * @param rightSide The right side expression.
-     * @param periodType The period-type.
+     * @param operator        The operator.
+     * @param leftSide        The left side expression.
+     * @param rightSide       The right side expression.
+     * @param periodType      The period-type.
      */
     public static ValidationRule createValidationRule( char uniqueCharacter, Operator operator, Expression leftSide,
         Expression rightSide, PeriodType periodType )
@@ -793,10 +800,10 @@
     }
 
     /**
-     * @param uniqueCharacter A unique character to identify the object.
-     * @param expressionString The expression string.
+     * @param uniqueCharacter          A unique character to identify the object.
+     * @param expressionString         The expression string.
      * @param dataElementsInExpression A collection of the data elements
-     *        entering into the expression.
+     *                                 entering into the expression.
      */
     public static Expression createExpression( char uniqueCharacter, String expressionString,
         Set<DataElement> dataElementsInExpression, Set<DataElementCategoryOptionCombo> optionCombosInExpression )
@@ -812,12 +819,12 @@
     }
 
     /**
-     * @param dataElementId The data element identifier.
+     * @param dataElementId         The data element identifier.
      * @param categoryOptionComboId The data element category option combo
-     *        identifier.
-     * @param periodId The period identifier.
-     * @param sourceId The source identifier.
-     * @param status The status.
+     *                              identifier.
+     * @param periodId              The period identifier.
+     * @param sourceId              The source identifier.
+     * @param status                The status.
      */
     public static ImportDataValue createImportDataValue( int dataElementId, int categoryOptionComboId, int periodId,
         int sourceId, ImportObjectStatus status )
@@ -909,17 +916,24 @@
         program.setDateOfEnrollmentDescription( "DateOfEnrollmentDescription" );
         program.setDateOfIncidentDescription( "DateOfIncidentDescription" );
         program.setProgramStages( programStages );
+        program.getOrganisationUnits().add( organisationUnit );
 
         return program;
     }
 
     public static ProgramStage createProgramStage( char uniqueCharacter, int minDays )
     {
+        return createProgramStage( uniqueCharacter, minDays, false );
+    }
+
+    public static ProgramStage createProgramStage( char uniqueCharacter, int minDays, boolean irregular )
+    {
         ProgramStage programStage = new ProgramStage();
 
         programStage.setName( "name" + uniqueCharacter );
         programStage.setDescription( "description" + uniqueCharacter );
         programStage.setMinDaysFromStart( minDays );
+        programStage.setIrregular( irregular );
 
         return programStage;
     }
@@ -972,8 +986,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param sql A query statement to retreive record/data from database.
-     *
+     * @param sql             A query statement to retreive record/data from database.
      * @return a sqlView instance
      */
     protected static SqlView createSqlView( char uniqueCharacter, String sql )
@@ -989,7 +1002,6 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     *
      * @return a concept instance
      */
     protected static Concept createConcept( char uniqueCharacter )
@@ -1004,8 +1016,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * @param value The value for constant
-     *
+     * @param value           The value for constant
      * @return a constant instance
      */
     protected static Constant createConstant( char uniqueCharacter, double value )
@@ -1028,7 +1039,7 @@
      * from the context up front.
      *
      * @param locationManager The LocationManager to be injected with the
-     *        external directory.
+     *                        external directory.
      */
     public void setExternalTestDir( LocationManager locationManager )
     {