← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12168: basic tests for PersonService

 

------------------------------------------------------------
revno: 12168
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-19 15:06:14 +0200
message:
  basic tests for PersonService
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/JacksonUtilsTest.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
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events'
=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/PersonServiceTest.java	2013-09-19 13:06:14 +0000
@@ -0,0 +1,100 @@
+package org.hisp.dhis.dxf2.events;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.dxf2.events.person.Gender;
+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.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class PersonServiceTest
+    extends DhisTest
+{
+    @Autowired
+    private PersonService personService;
+
+    @Autowired
+    private IdentifiableObjectManager manager;
+
+    private Patient maleA;
+    private Patient maleB;
+    private Patient femaleA;
+    private Patient femaleB;
+
+    private OrganisationUnit organisationUnitA;
+    private OrganisationUnit organisationUnitB;
+
+    @Override
+    protected void setUpTest() throws Exception
+    {
+        organisationUnitA = createOrganisationUnit( 'A' );
+        organisationUnitB = createOrganisationUnit( 'B' );
+
+        organisationUnitB.setParent( organisationUnitA );
+
+        maleA = createPatient( 'B', Patient.MALE, organisationUnitA );
+        maleB = createPatient( 'B', Patient.MALE, organisationUnitB );
+        femaleA = createPatient( 'A', Patient.FEMALE, organisationUnitA );
+        femaleB = createPatient( 'A', Patient.FEMALE, organisationUnitB );
+
+        manager.save( organisationUnitA );
+        manager.save( organisationUnitB );
+        manager.save( maleA );
+        manager.save( maleB );
+        manager.save( femaleA );
+        manager.save( femaleB );
+    }
+
+    @Override
+    public boolean emptyDatabaseAfterTest()
+    {
+        return true;
+    }
+
+    @Test
+    public void testGetPersons()
+    {
+        Assert.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() );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/JacksonUtilsTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/JacksonUtilsTest.java	2013-09-19 12:37:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/JacksonUtilsTest.java	2013-09-19 13:06:14 +0000
@@ -30,7 +30,6 @@
 
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.common.view.ExportView;
-import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.junit.Test;
 

=== 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-08-23 16:05:01 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java	2013-09-19 13:06:14 +0000
@@ -132,6 +132,8 @@
         emptyTable( "categorycombos_categories" );
         emptyTable( "categories_categoryoptions" );
 
+        emptyTable( "patient" );
+
         emptyTable( "organisationunit" );
         emptyTable( "version" );
         emptyTable( "mocksource" );

=== 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-12 07:19:15 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2013-09-19 13:06:14 +0000
@@ -114,7 +114,7 @@
 public abstract class DhisConvenienceTest
 {
     protected static final Log log = LogFactory.getLog( DhisConvenienceTest.class );
-    
+
     protected static final String BASE_UID = "123456789a";
     protected static final String BASE_IN_UID = "inabcdefgh";
     protected static final String BASE_DE_UID = "deabcdefgh";
@@ -124,7 +124,7 @@
     private static final String EXT_TEST_DIR = System.getProperty( "user.home" ) + File.separator + "dhis2_test_dir";
 
     private static Date date;
-    
+
     protected static final double DELTA = 0.01;
 
     // -------------------------------------------------------------------------
@@ -150,13 +150,13 @@
     protected OrganisationUnitGroupService organisationUnitGroupService;
 
     protected AggregatedDataValueService aggregatedDataValueService;
-    
+
     protected AggregatedOrgUnitDataValueService aggregatedOrgUnitDataValueService;
 
     protected PeriodService periodService;
 
     protected ConstantService constantService;
-    
+
     protected ValidationRuleService validationRuleService;
 
     protected ValidationCriteriaService validationCriteriaService;
@@ -172,9 +172,9 @@
     protected ProgramStageService programStageService;
 
     protected DataEntryFormService dataEntryFormService;
-    
+
     protected UserService userService;
-    
+
     protected MessageService messageService;
 
     static
@@ -192,7 +192,7 @@
 
     /**
      * Creates a date.
-     * 
+     *
      * @param year the year.
      * @param month the month.
      * @param day the day of month.
@@ -212,7 +212,7 @@
 
     /**
      * Creates a date.
-     * 
+     *
      * @param day the day of the year.
      * @return a date.
      */
@@ -231,7 +231,7 @@
      * implementation type of the collection in contrast to the native equals
      * 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 reference the reference objects to check against.
      * @return true if the collections are equal, false otherwise.
@@ -304,7 +304,7 @@
      * service; making the test unaware of the implementation and thus
      * re-usable. A weakness is that the field name of the dependency must be
      * assumed.
-     * 
+     *
      * @param targetService the target service.
      * @param fieldName the name of the dependency field in the target service.
      * @param dependency the dependency.
@@ -324,7 +324,7 @@
      * service; making the test unaware of the implementation and thus
      * re-usable. A weakness is that the field name of the dependency must be
      * assumed.
-     * 
+     *
      * @param targetService the target service.
      * @param fieldName the name of the dependency field in the target service.
      * @param dependency the dependency.
@@ -333,9 +333,9 @@
     protected void setDependency( Object targetService, String fieldName, Object dependency, Class<?> clazz )
     {
         try
-        {            
+        {
             targetService = getRealObject( targetService );
-            
+
             String setMethodName = "set" + fieldName.substring( 0, 1 ).toUpperCase()
                 + fieldName.substring( 1, fieldName.length() );
 
@@ -354,7 +354,7 @@
     /**
      * If the given class is advised by Spring AOP it will return the target class,
      * i.e. the advised class. If not the given class is returned unchanged.
-     * 
+     *
      * @param object the object.
      */
     @SuppressWarnings("unchecked")
@@ -365,10 +365,10 @@
         {
             return (T) ((Advised) object).getTargetSource().getTarget();
         }
-        
+
         return object;
     }
-    
+
     // -------------------------------------------------------------------------
     // Create object methods
     // -------------------------------------------------------------------------
@@ -463,7 +463,7 @@
 
         return categoryOptionCombo;
     }
-    
+
     /**
      * @param categoryCombo the category combo.
      * @param categoryOptions the category options.
@@ -472,14 +472,14 @@
     public static DataElementCategoryOptionCombo createCategoryOptionCombo( DataElementCategoryCombo categoryCombo, DataElementCategoryOption... categoryOptions )
     {
         DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
-        
+
         categoryOptionCombo.setCategoryCombo( categoryCombo );
-        
+
         for ( DataElementCategoryOption categoryOption : categoryOptions )
         {
             categoryOptionCombo.getCategoryOptions().add( categoryOption );
         }
-        
+
         return categoryOptionCombo;
     }
 
@@ -682,7 +682,7 @@
 
         return period;
     }
-    
+
     /**
      * @param isoPeriod the ISO period string.
      */
@@ -807,7 +807,7 @@
         expression.setDescription( "Description" + uniqueCharacter );
         expression.setDataElementsInExpression( dataElementsInExpression );
         expression.setOptionCombosInExpression( optionCombosInExpression );
-        
+
         return expression;
     }
 
@@ -836,7 +836,7 @@
 
         return importDataValue;
     }
-    
+
     public static MapLegend createMapLegend( char uniqueCharacter, Double startValue, Double endValue )
     {
         MapLegend legend = new MapLegend();
@@ -883,12 +883,12 @@
 
         UserCredentials credentials = new UserCredentials();
         credentials.setUsername( "username" );
-        
+
         user.setUserCredentials( credentials );
-        
+
         return user;
     }
-    
+
     public static UserGroup createUserGroup( char uniqueCharacter, Set<User> users )
     {
         UserGroup userGroup = new UserGroup();
@@ -927,11 +927,27 @@
     public static Patient createPatient( char uniqueChar, OrganisationUnit organisationUnit )
     {
         Patient patient = new Patient();
+        patient.setAutoFields();
 
         patient.setName( "FirstName" + uniqueChar );
         patient.setGender( Patient.MALE );
         patient.setBirthDate( getDate( 1970, 1, 1 ) );
         patient.setRegistrationDate( new Date() );
+        patient.setOrganisationUnit( organisationUnit );
+
+        return patient;
+    }
+
+    public static Patient createPatient( char uniqueChar, String gender, OrganisationUnit organisationUnit )
+    {
+        Patient patient = new Patient();
+        patient.setAutoFields();
+
+        patient.setName( "FirstName" + uniqueChar );
+        patient.setGender( gender );
+        patient.setBirthDate( getDate( 1970, 1, 1 ) );
+        patient.setRegistrationDate( new Date() );
+        patient.setOrganisationUnit( organisationUnit );
 
         return patient;
     }
@@ -957,7 +973,7 @@
     /**
      * @param uniqueCharacter A unique character to identify the object.
      * @param sql A query statement to retreive record/data from database.
-     * 
+     *
      * @return a sqlView instance
      */
     protected static SqlView createSqlView( char uniqueCharacter, String sql )
@@ -973,7 +989,7 @@
 
     /**
      * @param uniqueCharacter A unique character to identify the object.
-     * 
+     *
      * @return a concept instance
      */
     protected static Concept createConcept( char uniqueCharacter )
@@ -985,23 +1001,23 @@
         return concept;
     }
 
-    
+
     /**
      * @param uniqueCharacter A unique character to identify the object.
      * @param value The value for constant
-     * 
+     *
      * @return a constant instance
      */
     protected static Constant createConstant( char uniqueCharacter, double value )
     {
         Constant constant = new Constant();
-        
+
         constant.setName( "Constant" + uniqueCharacter );
         constant.setValue( value );
-        
+
         return constant;
     }
-    
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -1010,7 +1026,7 @@
      * Injects the externalDir property of LocationManager to
      * user.home/dhis2_test_dir. LocationManager dependency must be retrieved
      * from the context up front.
-     * 
+     *
      * @param locationManager The LocationManager to be injected with the
      *        external directory.
      */