← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13045: Implement unit tests on PatientTabularReport service methods

 

------------------------------------------------------------
revno: 13045
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-11-28 16:42:33 +0700
message:
  Implement unit tests on PatientTabularReport service methods
added:
  dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportServiceTest.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportStoreTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/CaseAggregateConditionTask.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/TestCaseAggregationConditionAction.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-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientreport/PatientTabularReportService.java	2013-11-28 09:42:33 +0000
@@ -46,7 +46,7 @@
      * 
      * @return A generated unique id of the added {@link PatientTabularReport} .
      */
-    void saveOrUpdate( PatientTabularReport patientTabularReport );
+    int saveOrUpdate( PatientTabularReport patientTabularReport );
 
     /**
      * Returns a {@link patientTabularReport}.

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/DefaultPatientTabularReportService.java	2013-11-28 09:42:33 +0000
@@ -94,9 +94,9 @@
     }
 
     @Override
-    public void saveOrUpdate( PatientTabularReport patientTabularReport )
+    public int saveOrUpdate( PatientTabularReport patientTabularReport )
     {
-        tabularReportStore.save( patientTabularReport );
+        return tabularReportStore.save( patientTabularReport );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/patientreport/hibernate/HibernatePatientTabularReportStore.java	2013-11-28 09:42:33 +0000
@@ -66,18 +66,21 @@
                 result.add( report );
             }
         }
-
-        if( min > result.size() )
-        {
-            min = result.size();
-        }
-        
-        if( max > result.size() )
-        {
-            max = result.size();
-        }
-        
-        return result.subList( min, max );
+        if ( min != null && max != null )
+        {
+
+            if ( min > result.size() )
+            {
+                min = result.size();
+            }
+
+            if ( max > result.size() )
+            {
+                max = result.size();
+            }
+            return result.subList( min, max );
+        }
+        return result;
     }
 
     @Override
@@ -112,7 +115,7 @@
         {
             criteria.add( Restrictions.ilike( "name", "%" + query + "%" ) );
         }
-        
+
         return criteria;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/CaseAggregateConditionTask.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/CaseAggregateConditionTask.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/main/java/org/hisp/dhis/scheduling/CaseAggregateConditionTask.java	2013-11-28 09:42:33 +0000
@@ -37,7 +37,6 @@
 
 import org.hisp.dhis.caseaggregation.CaseAggregateSchedule;
 import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
-import org.hisp.dhis.scheduling.TaskId;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.Clock;

=== added file 'dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportServiceTest.java	2013-11-28 09:42:33 +0000
@@ -0,0 +1,204 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.patientreport;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientTabularReportServiceTest.java Nov 28, 2013 11:21:05 AM $
+ */
+public class PatientTabularReportServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientTabularReportService tabularReportService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private UserService userService;
+
+    private User user;
+
+    private PatientTabularReport tabularReportA;
+
+    private PatientTabularReport tabularReportB;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        Set<OrganisationUnit> orgUnits = new HashSet<OrganisationUnit>();
+        orgUnits.add( organisationUnit );
+
+        user = new User();
+        user.setSurname( "A" );
+        user.setFirstName( "B" );
+        user.setPhoneNumber( "111-222-333" );
+        user.updateOrganisationUnits( orgUnits );
+
+        UserCredentials userCredentials = new UserCredentials();
+        userCredentials.setUser( user );
+        userCredentials.setUsername( "A" );
+        userCredentials.setPassword( "A" );
+        userCredentials.setUser( user );
+        user.setUserCredentials( userCredentials );
+
+        UserAuthorityGroup group = new UserAuthorityGroup();
+        group.setName( "A" );
+        group.setDescription( "A" );
+
+        Collection<String> authorityMember = new ArrayList<String>();
+        authorityMember.add( "ALL" );
+        group.getAuthorities().addAll( authorityMember );
+        userService.addUserAuthorityGroup( group );
+
+        userCredentials.getUserAuthorityGroups().add( group );
+        userService.addUser( user );
+        userService.addUserCredentials( userCredentials );
+
+        tabularReportA = new PatientTabularReport( "A" );
+        tabularReportA.setUid( "UID-A" );
+        tabularReportA.setUser( user );
+        tabularReportB = new PatientTabularReport( "B" );
+        tabularReportB.setUid( "UID-B" );
+        tabularReportB.setUser( user );
+    }
+
+    @Test
+    public void testSaveOrUpdatePatientTabularReport()
+    {
+        int idA = tabularReportService.saveOrUpdate( tabularReportA );
+        int idB = tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertNotNull( tabularReportService.getPatientTabularReport( idA ) );
+        assertNotNull( tabularReportService.getPatientTabularReport( idB ) );
+    }
+
+    @Test
+    public void testDeletePatientTabularReport()
+    {
+        int idA = tabularReportService.saveOrUpdate( tabularReportA );
+        int idB = tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertNotNull( tabularReportService.getPatientTabularReport( idA ) );
+        assertNotNull( tabularReportService.getPatientTabularReport( idB ) );
+
+        tabularReportService.deletePatientTabularReport( tabularReportA );
+
+        assertNull( tabularReportService.getPatientTabularReport( idA ) );
+        assertNotNull( tabularReportService.getPatientTabularReport( idB ) );
+
+        tabularReportService.deletePatientTabularReport( tabularReportB );
+
+        assertNull( tabularReportService.getPatientTabularReport( idA ) );
+        assertNull( tabularReportService.getPatientTabularReport( idB ) );
+    }
+
+    @Test
+    public void testGetPatientTabularReportById()
+    {
+        int idA = tabularReportService.saveOrUpdate( tabularReportA );
+        int idB = tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertEquals( tabularReportA, tabularReportService.getPatientTabularReport( idA ) );
+        assertEquals( tabularReportB, tabularReportService.getPatientTabularReport( idB ) );
+    }
+
+    @Test
+    public void testGetPatientTabularReportByUid()
+    {
+        tabularReportService.saveOrUpdate( tabularReportA );
+        tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertEquals( tabularReportA, tabularReportService.getPatientTabularReportByUid( "UID-A" ) );
+        assertEquals( tabularReportB, tabularReportService.getPatientTabularReportByUid( "UID-B" ) );
+    }
+
+    @Test
+    public void testGetPatientTabularReportByName()
+    {
+        int idA = tabularReportService.saveOrUpdate( tabularReportA );
+
+        assertNotNull( tabularReportService.getPatientTabularReport( idA ) );
+        assertEquals( tabularReportA.getName(), tabularReportService.getPatientTabularReport( "A" )
+            .getName() );
+    }
+
+    @Test
+    public void testGetAllPatientTabularReports()
+    {
+        tabularReportService.saveOrUpdate( tabularReportA );
+        tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertTrue( equals( tabularReportService.getAllTabularReports(), tabularReportA,
+            tabularReportB ) );
+    }
+
+    @Test
+    public void testGetPatientTabularReports()
+    {
+        tabularReportService.saveOrUpdate( tabularReportA );
+        tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertTrue( equals( tabularReportService.getPatientTabularReports( user, "a", null, null ),
+            tabularReportA ) );
+    }
+
+    @Test
+    public void testCountPatientTabularReportList()
+    {
+        tabularReportService.saveOrUpdate( tabularReportA );
+        tabularReportService.saveOrUpdate( tabularReportB );
+
+        assertEquals( 1, tabularReportService.countPatientTabularReportList( user, "a" ) );
+    }
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportStoreTest.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/patientreport/PatientTabularReportStoreTest.java	2013-11-28 09:42:33 +0000
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.patientreport;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientTabularReportServiceTest.java Nov 28, 2013 11:21:05 AM $
+ */
+public class PatientTabularReportStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientTabularReportStore tabularReportStore;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private UserService userService;
+
+    private User user;
+
+    private PatientTabularReport tabularReportA;
+
+    private PatientTabularReport tabularReportB;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        Set<OrganisationUnit> orgUnits = new HashSet<OrganisationUnit>();
+        orgUnits.add( organisationUnit );
+
+        user = new User();
+        user.setSurname( "A" );
+        user.setFirstName( "B" );
+        user.setPhoneNumber( "111-222-333" );
+        user.updateOrganisationUnits( orgUnits );
+
+        UserCredentials userCredentials = new UserCredentials();
+        userCredentials.setUser( user );
+        userCredentials.setUsername( "A" );
+        userCredentials.setPassword( "A" );
+        userCredentials.setUser( user );
+        user.setUserCredentials( userCredentials );
+
+        UserAuthorityGroup group = new UserAuthorityGroup();
+        group.setName( "A" );
+        group.setDescription( "A" );
+
+        Collection<String> authorityMember = new ArrayList<String>();
+        authorityMember.add( "ALL" );
+        group.getAuthorities().addAll( authorityMember );
+        userService.addUserAuthorityGroup( group );
+
+        userCredentials.getUserAuthorityGroups().add( group );
+        userService.addUser( user );
+        userService.addUserCredentials( userCredentials );
+
+        tabularReportA = new PatientTabularReport( "A" );
+        tabularReportA.setUid( "UID-A" );
+        tabularReportA.setUser( user );
+        tabularReportB = new PatientTabularReport( "B" );
+        tabularReportB.setUid( "UID-B" );
+        tabularReportB.setUser( user );
+    }
+
+    @Test
+    public void testGetPatientTabularReports()
+    {
+        tabularReportStore.save( tabularReportA );
+        tabularReportStore.save( tabularReportB );
+
+        assertTrue( equals( tabularReportStore.get( user, "a", null, null ),
+            tabularReportA ) );
+    }
+
+    @Test
+    public void testCountPatientTabularReportList()
+    {
+        tabularReportStore.save( tabularReportA );
+        tabularReportStore.save( tabularReportB );
+
+        assertEquals( 1, tabularReportStore.countList( user, "a" ) );
+    }
+}
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-11-25 07:31:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm	2013-11-28 09:42:33 +0000
@@ -265,7 +265,7 @@
 #end
 
 <tr>
-	<td colspan='3'><span id='message'></td>
+	<td colspan='3'><span id='message'></span></td>
 </tr>
 
 <script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/TestCaseAggregationConditionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/TestCaseAggregationConditionAction.java	2013-11-28 06:19:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/caseaggregation/TestCaseAggregationConditionAction.java	2013-11-28 09:42:33 +0000
@@ -51,7 +51,7 @@
 
     private CaseAggregationConditionService caseAggregationConditionService;
 
-    public void setCaseAggregationConditionService( CaseAggregationConditionService caseAggregationConditionService )
+    public void setCaseAggregationConditionManager( CaseAggregationConditionService caseAggregationConditionService )
     {
         this.caseAggregationConditionService = caseAggregationConditionService;
     }
@@ -109,7 +109,7 @@
             "dataelementname", 0, "optioncomboid", deSumId, orgunitIds, period );
 
         List<Integer> ids = caseAggregationConditionService.executeSQL( sql );
-
+        
         return (ids == null) ? INPUT : SUCCESS;
     }
 }