← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12887: Implement unit tests on patient attribute option service methods.

 

------------------------------------------------------------
revno: 12887
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-11-06 08:47:02 +0700
message:
  Implement unit tests on patient attribute option service methods.
added:
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionStoreTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeOptionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeOptionService.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-api/src/main/java/org/hisp/dhis/patient/PatientAttributeOptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeOptionService.java	2013-11-04 03:13:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeOptionService.java	2013-11-06 01:47:02 +0000
@@ -44,7 +44,7 @@
      * 
      * @return A generated unique id of the added {@link PatientAttributeOption}.
      */
-    void addPatientAttributeOption( PatientAttributeOption option );
+    int addPatientAttributeOption( PatientAttributeOption option );
 
     /**
      * Updates a {@link PatientAttributeOption}.

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeOptionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeOptionService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeOptionService.java	2013-11-06 01:47:02 +0000
@@ -55,9 +55,9 @@
     // Implementation methods
     // -------------------------------------------------------------------------
 
-    public void addPatientAttributeOption( PatientAttributeOption option )
+    public int addPatientAttributeOption( PatientAttributeOption option )
     {
-        patientAttributeOptionStore.save( option );
+        return patientAttributeOptionStore.save( option );
     }
 
     public void deletePatientAttributeOption( PatientAttributeOption option )

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionServiceTest.java	2013-11-06 01:47:02 +0000
@@ -0,0 +1,151 @@
+/*
+ * 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 org.hisp.dhis.DhisSpringTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientAttributeOptionServiceTest.java Nov 5, 2013 4:25:29 PM $
+ */
+public class PatientAttributeOptionServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientAttributeOptionService attributeOptionService;
+
+    @Autowired
+    private PatientAttributeService attributeService;
+
+    private PatientAttributeOption attributeOptionA;
+
+    private PatientAttributeOption attributeOptionB;
+
+    private PatientAttributeOption attributeOptionC;
+
+    private PatientAttribute attributeA;
+
+    private PatientAttribute attributeB;
+
+    @Override
+    public void setUpTest()
+    {
+        attributeA = createPatientAttribute( 'A' );
+        attributeB = createPatientAttribute( 'B' );
+
+        attributeService.savePatientAttribute( attributeA );
+        attributeService.savePatientAttribute( attributeB );
+
+        attributeOptionA = createPatientAttributeOption( 'A', attributeA );
+        attributeOptionB = createPatientAttributeOption( 'B', attributeA );
+        attributeOptionC = createPatientAttributeOption( 'C', attributeB );
+    }
+
+    @Test
+    public void testAddPatientAttributeOption()
+    {
+        int idA = attributeOptionService.addPatientAttributeOption( attributeOptionA );
+        int idB = attributeOptionService.addPatientAttributeOption( attributeOptionB );
+
+        assertNotNull( attributeOptionService.get( idA ) );
+        assertNotNull( attributeOptionService.get( idB ) );
+    }
+
+    @Test
+    public void testDeletePatientAttributeGroup()
+    {
+        int idA = attributeOptionService.addPatientAttributeOption( attributeOptionA );
+        int idB = attributeOptionService.addPatientAttributeOption( attributeOptionB );
+
+        assertNotNull( attributeOptionService.get( idA ) );
+        assertNotNull( attributeOptionService.get( idB ) );
+
+        attributeOptionService.deletePatientAttributeOption( attributeOptionA );
+
+        assertNull( attributeOptionService.get( idA ) );
+        assertNotNull( attributeOptionService.get( idB ) );
+
+        attributeOptionService.deletePatientAttributeOption( attributeOptionB );
+
+        assertNull( attributeOptionService.get( idA ) );
+        assertNull( attributeOptionService.get( idB ) );
+    }
+
+    @Test
+    public void testUpdatePatientAttributeOption()
+    {
+        int idA = attributeOptionService.addPatientAttributeOption( attributeOptionA );
+
+        assertNotNull( attributeOptionService.get( idA ) );
+
+        attributeOptionA.setName( "B" );
+        attributeOptionService.updatePatientAttributeOption( attributeOptionA );
+
+        assertEquals( "B", attributeOptionService.get( idA ).getName() );
+    }
+
+    @Test
+    public void testGetPatientAttributeGroupById()
+    {
+        int idA = attributeOptionService.addPatientAttributeOption( attributeOptionA );
+        int idB = attributeOptionService.addPatientAttributeOption( attributeOptionB );
+
+        assertEquals( attributeOptionA, attributeOptionService.get( idA ) );
+        assertEquals( attributeOptionB, attributeOptionService.get( idB ) );
+    }
+
+    @Test
+    public void testGetPatientAttributeGroupByName()
+    {
+        int idA = attributeOptionService.addPatientAttributeOption( attributeOptionA );
+
+        assertNotNull( attributeOptionService.get( idA ) );
+
+        assertEquals( attributeOptionA, attributeOptionService.get( attributeA, "AttributeOptionA" ) );
+    }
+
+    @Test
+    public void testGetPatientAttributeOptionByAttribute()
+    {
+        attributeOptionService.addPatientAttributeOption( attributeOptionA );
+        attributeOptionService.addPatientAttributeOption( attributeOptionB );
+        attributeOptionService.addPatientAttributeOption( attributeOptionC );
+
+        assertTrue( equals( attributeOptionService.get( attributeA ), attributeOptionA, attributeOptionB ) );
+        assertTrue( equals( attributeOptionService.get( attributeB ), attributeOptionC ) );
+    }
+
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/patient/PatientAttributeOptionStoreTest.java	2013-11-06 01:47:02 +0000
@@ -0,0 +1,97 @@
+/*
+ * 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.assertTrue;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ PatientAttributeOptionStoreTest.java Nov 5, 2013 4:43:12 PM $
+ */
+public class PatientAttributeOptionStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private PatientAttributeOptionStore attributeOptionStore;
+
+    @Autowired
+    private PatientAttributeService attributeService;
+
+    private PatientAttributeOption attributeOptionA;
+
+    private PatientAttributeOption attributeOptionB;
+
+    private PatientAttributeOption attributeOptionC;
+
+    private PatientAttribute attributeA;
+
+    private PatientAttribute attributeB;
+
+    @Override
+    public void setUpTest()
+    {
+        attributeA = createPatientAttribute( 'A' );
+        attributeB = createPatientAttribute( 'B' );
+
+        attributeService.savePatientAttribute( attributeA );
+        attributeService.savePatientAttribute( attributeB );
+
+        attributeOptionA = createPatientAttributeOption( 'A', attributeA );
+        attributeOptionB = createPatientAttributeOption( 'B', attributeA );
+        attributeOptionC = createPatientAttributeOption( 'C', attributeB );
+    }
+
+    @Test
+    public void testGetPatientAttributeGroupByName()
+    {
+        int idA = attributeOptionStore.save( attributeOptionA );
+
+        assertNotNull( attributeOptionStore.get( idA ) );
+
+        assertEquals( attributeOptionA, attributeOptionStore.get( attributeA, "AttributeOptionA" ) );
+    }
+
+    @Test
+    public void testGetPatientAttributeOptionByAttribute()
+    {
+        attributeOptionStore.save( attributeOptionA );
+        attributeOptionStore.save( attributeOptionB );
+        attributeOptionStore.save( attributeOptionC );
+
+        assertTrue( equals( attributeOptionStore.get( attributeA ), attributeOptionA, attributeOptionB ) );
+        assertTrue( equals( attributeOptionStore.get( attributeB ), attributeOptionC ) );
+    }
+
+}
\ No newline at end of file

=== 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-11-05 09:31:47 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2013-11-06 01:47:02 +0000
@@ -1092,6 +1092,19 @@
 
         return patientAttribute;
     }
+    /**
+     * @param uniqueCharacter A unique character to identify the object.
+     * @return PatientAttributeOption
+     */
+    public static PatientAttributeOption createPatientAttributeOption( char uniqueChar, PatientAttribute patientAttribute )
+    {
+        PatientAttributeOption patientAttributeOption = new PatientAttributeOption();
+
+        patientAttributeOption.setName( "AttributeOption" + uniqueChar );
+        patientAttributeOption.setPatientAttribute( patientAttribute );
+
+        return patientAttributeOption;
+    }
 
     /**
      * @param uniqueCharacter A unique character to identify the object.