← Back to team overview

dhis2-devs team mailing list archive

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

 

------------------------------------------------------------
revno: 12903
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-08 14:40:31 +0700
message:
  Implement unit tests on PatientRegistrationForm service methods
added:
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormStoreTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationForm.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeStoreTest.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/patient/PatientRegistrationForm.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationForm.java	2013-10-08 08:47:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientRegistrationForm.java	2013-11-08 07:40:31 +0000
@@ -72,6 +72,11 @@
     {
     }
 
+    public PatientRegistrationForm( DataEntryForm dataEntryForm )
+    {
+        this.dataEntryForm = dataEntryForm;
+    }
+
     public PatientRegistrationForm( Program program, DataEntryForm dataEntryForm )
     {
         this.program = program;

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeStoreTest.java	2013-11-08 03:05:02 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientIdentifierTypeStoreTest.java	2013-11-08 07:40:31 +0000
@@ -89,7 +89,7 @@
         identifierTypeStore.save( identifierTypeA );
         identifierTypeStore.save( identifierTypeB );
         identifierTypeStore.save( identifierTypeC );
-        System.out.println( "\n\n ===\n " + identifierTypeA.getPersonDisplayName() );
+
         Collection<PatientIdentifierType> identifierTypes = identifierTypeStore.getByDisplayed( true );
         assertEquals( 2, identifierTypes.size() );
         assertTrue( equals( identifierTypes, identifierTypeA, identifierTypeB ) );

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormServiceTest.java	2013-11-08 07:40:31 +0000
@@ -0,0 +1,200 @@
+/*
+ * 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.patient;
+
+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.Collection;
+import java.util.HashSet;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientRegistrationFormServiceTest.java Nov 8, 2013 10:07:30 AM $
+ */
+public class PatientRegistrationFormServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientRegistrationFormService patientRegistrationFormService;
+
+    @Autowired
+    private DataEntryFormService dataEntryFormService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    private PatientRegistrationForm patientRegistrationFormA;
+
+    private PatientRegistrationForm patientRegistrationFormB;
+
+    private PatientRegistrationForm patientRegistrationFormC;
+
+    private Program programA;
+
+    private Program programB;
+
+    private DataEntryForm dataEntryForm;
+
+    // -------------------------------------------------------------------------
+    // Fixture
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void setUpTest()
+        throws Exception
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( programA );
+
+        programB = createProgram( 'B', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( programB );
+
+        DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormA );
+
+        DataEntryForm dataEntryFormB = new DataEntryForm( "DataEntryForm-B" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormB );
+
+        DataEntryForm dataEntryFormC = new DataEntryForm( "DataEntryForm-C" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormC );
+
+        patientRegistrationFormA = new PatientRegistrationForm( programA, dataEntryForm );
+        patientRegistrationFormB = new PatientRegistrationForm( programB, dataEntryForm );
+        patientRegistrationFormC = new PatientRegistrationForm( dataEntryForm );
+    }
+
+    @Test
+    public void testSavePatientRegistrationForm()
+    {
+        int idA = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        int idB = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idB ) );
+    }
+
+    @Test
+    public void testDeletePatientRegistrationForm()
+    {
+        int idA = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        int idB = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idB ) );
+
+        patientRegistrationFormService.deletePatientRegistrationForm( patientRegistrationFormA );
+
+        assertNull( patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idB ) );
+
+        patientRegistrationFormService.deletePatientRegistrationForm( patientRegistrationFormB );
+
+        assertNull( patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+        assertNull( patientRegistrationFormService.getPatientRegistrationForm( idB ) );
+    }
+
+    @Test
+    public void testUpdatePatientRegistrationForm()
+    {
+        int idA = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+
+        assertNotNull( patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+
+        patientRegistrationFormA.setName( "B" );
+        patientRegistrationFormService.updatePatientRegistrationForm( patientRegistrationFormA );
+
+        assertEquals( "B", patientRegistrationFormService.getPatientRegistrationForm( idA ).getName() );
+    }
+
+    @Test
+    public void testGetPatientRegistrationFormById()
+    {
+        int idA = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        int idB = patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+
+        assertEquals( patientRegistrationFormA, patientRegistrationFormService.getPatientRegistrationForm( idA ) );
+        assertEquals( patientRegistrationFormB, patientRegistrationFormService.getPatientRegistrationForm( idB ) );
+    }
+
+    @Test
+    public void testGetAllPatientRegistrationForms()
+    {
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+
+        Collection<PatientRegistrationForm> forms = patientRegistrationFormService.getAllPatientRegistrationForms();
+        System.out.println( "\n\n forms : " + forms );
+        assertEquals( 2, forms.size() );
+        assertTrue( forms.contains( patientRegistrationFormA ) );
+        assertTrue( forms.contains( patientRegistrationFormB ) );
+    }
+
+    @Test
+    public void testGetPatientRegistrationFormByProgram()
+    {
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormC );
+
+        PatientRegistrationForm form = patientRegistrationFormService.getPatientRegistrationForm( programA );
+        assertEquals( patientRegistrationFormA, form );
+    }
+
+    @Test
+    public void testGetCommonPatientRegistrationForm()
+    {
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormA );
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormB );
+        patientRegistrationFormService.savePatientRegistrationForm( patientRegistrationFormC );
+
+        PatientRegistrationForm form = patientRegistrationFormService.getCommonPatientRegistrationForm();
+        assertEquals( patientRegistrationFormC, form );
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientRegistrationFormStoreTest.java	2013-11-08 07:40:31 +0000
@@ -0,0 +1,130 @@
+/*
+ * 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.patient;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashSet;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
+import org.hisp.dhis.program.ProgramStage;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ patientRegistrationFormStoreTest.java Nov 8, 2013 10:07:30 AM $
+ */
+public class PatientRegistrationFormStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientRegistrationFormStore patientRegistrationFormStore;
+
+    @Autowired
+    private DataEntryFormService dataEntryFormService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    private PatientRegistrationForm patientRegistrationFormA;
+
+    private PatientRegistrationForm patientRegistrationFormB;
+
+    private PatientRegistrationForm patientRegistrationFormC;
+
+    private Program programA;
+
+    private Program programB;
+
+    private DataEntryForm dataEntryForm;
+
+    // -------------------------------------------------------------------------
+    // Fixture
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void setUpTest()
+        throws Exception
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        programA = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( programA );
+
+        programB = createProgram( 'B', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( programB );
+
+        DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormA );
+
+        DataEntryForm dataEntryFormB = new DataEntryForm( "DataEntryForm-B" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormB );
+
+        DataEntryForm dataEntryFormC = new DataEntryForm( "DataEntryForm-C" );
+        dataEntryFormService.addDataEntryForm( dataEntryFormC );
+
+        patientRegistrationFormA = new PatientRegistrationForm( programA, dataEntryForm );
+        patientRegistrationFormB = new PatientRegistrationForm( programB, dataEntryForm );
+        patientRegistrationFormC = new PatientRegistrationForm( dataEntryForm );
+    }
+
+    @Test
+    public void testGetPatientRegistrationFormByProgram()
+    {
+        patientRegistrationFormStore.save( patientRegistrationFormA );
+        patientRegistrationFormStore.save( patientRegistrationFormB );
+        patientRegistrationFormStore.save( patientRegistrationFormC );
+
+        PatientRegistrationForm form = patientRegistrationFormStore.get( programA );
+        assertEquals( patientRegistrationFormA, form );
+    }
+
+    @Test
+    public void testGetCommonPatientRegistrationForm()
+    {
+        patientRegistrationFormStore.save( patientRegistrationFormA );
+        patientRegistrationFormStore.save( patientRegistrationFormB );
+        patientRegistrationFormStore.save( patientRegistrationFormC );
+
+        PatientRegistrationForm form = patientRegistrationFormStore.getCommonForm();
+        assertEquals( patientRegistrationFormC, form );
+    }
+
+}