← Back to team overview

dhis2-devs team mailing list archive

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

 

------------------------------------------------------------
revno: 12952
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-11-15 11:35:36 +0700
message:
  Implement unit tests on ProgramStageDataElement service methods
added:
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementStoreTest.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 file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementServiceTest.java	2013-11-15 04:35:36 +0000
@@ -0,0 +1,225 @@
+/*
+ * 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.program;
+
+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 java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ProgramStageDataElementServiceTest.java Nov 14, 2013 4:22:27 PM $
+ */
+public class ProgramStageDataElementServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private ProgramStageDataElementService programStageDataElementService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private DataElementService dataElementService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private DataEntryFormService dataEntryFormService;
+
+    @Autowired
+    private ProgramStageService programStageService;
+
+    private OrganisationUnit organisationUnit;
+
+    private ProgramStage stageA;
+
+    private ProgramStage stageB;
+
+    private DataElement dataElementA;
+
+    private DataElement dataElementB;
+
+    private ProgramStageDataElement stageDataElementA;
+
+    private ProgramStageDataElement stageDataElementB;
+
+    private ProgramStageDataElement stageDataElementC;
+
+    private ProgramStageDataElement stageDataElementD;
+
+    @Override
+    public void setUpTest()
+    {
+        organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        stageA = new ProgramStage( "A", program );
+        stageA.setUid( "StageA" );
+        programStageService.saveProgramStage( stageA );
+
+        stageB = new ProgramStage( "B", program );
+        programStageService.saveProgramStage( stageB );
+
+        Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+        programStages.add( stageA );
+        programStages.add( stageB );
+        program.setProgramStages( programStages );
+        programService.updateProgram( program );
+
+        dataElementA = createDataElement( 'A' );
+        dataElementB = createDataElement( 'B' );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+
+        stageDataElementA = new ProgramStageDataElement( stageA, dataElementA, false, 1 );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+
+        stageDataElementB = new ProgramStageDataElement( stageA, dataElementB, false, 2 );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+
+        stageDataElementC = new ProgramStageDataElement( stageB, dataElementA, false, 1 );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+
+        stageDataElementD = new ProgramStageDataElement( stageB, dataElementB, false, 2 );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+    }
+
+    @Test
+    public void testAddProgramStageDataElement()
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+
+        assertNotNull( programStageDataElementService.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementService.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testUpdateProgramStageDataElement()
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+
+        assertNotNull( programStageDataElementService.get( stageA, dataElementA ) );
+
+        stageDataElementA.setCompulsory( true );
+        programStageDataElementService.updateProgramStageDataElement( stageDataElementA );
+
+        assertEquals( true, programStageDataElementService.get( stageA, dataElementA ).isCompulsory() );
+    }
+
+    @Test
+    public void testDeleteProgramStageDataElement()
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+
+        assertNotNull( programStageDataElementService.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementService.get( stageA, dataElementB ) );
+
+        programStageDataElementService.deleteProgramStageDataElement( stageDataElementA );
+
+        assertNull( programStageDataElementService.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementService.get( stageA, dataElementB ) );
+
+        programStageDataElementService.deleteProgramStageDataElement( stageDataElementB );
+
+        assertNull( programStageDataElementService.get( stageA, dataElementA ) );
+        assertNull( programStageDataElementService.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testGetByStageElement()
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+
+        assertNotNull( programStageDataElementService.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementService.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testGetAllProgramStageDataElements()
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+
+        assertTrue( equals( programStageDataElementService.getAllProgramStageDataElements(), stageDataElementA,
+            stageDataElementB ) );
+    }
+
+    @Test
+    public void testGetByStage( )
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementC );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementD );
+
+        Collection<ProgramStageDataElement> stageDataElements = programStageDataElementService.get( stageA );
+        assertTrue( equals( stageDataElements, stageDataElementA, stageDataElementB ) );
+
+        stageDataElements = programStageDataElementService.get( stageB );
+        assertTrue( equals( stageDataElements, stageDataElementC, stageDataElementD ) );
+    }
+
+    @Test
+    public void testGetListDataElementByStage( )
+    {
+        programStageDataElementService.addProgramStageDataElement( stageDataElementA );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementB );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementC );
+        programStageDataElementService.addProgramStageDataElement( stageDataElementD );
+
+        Collection<DataElement> stageDataElements = programStageDataElementService.getListDataElement( stageA );
+        assertTrue( equals( stageDataElements, dataElementA, dataElementB ) );
+
+        stageDataElements = programStageDataElementService.getListDataElement( stageB );
+        assertTrue( equals( stageDataElements, dataElementA, dataElementB ) );
+    }
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageDataElementStoreTest.java	2013-11-15 04:35:36 +0000
@@ -0,0 +1,217 @@
+/*
+ * 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.program;
+
+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 java.util.Set;
+
+import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ProgramStageDataElementServiceTest.java Nov 14, 2013 4:22:27 PM $
+ */
+public class ProgramStageDataElementStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private ProgramStageDataElementStore programStageDataElementStore;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    @Autowired
+    private DataElementService dataElementService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private DataEntryFormService dataEntryFormService;
+
+    @Autowired
+    private ProgramStageService programStageService;
+
+    private OrganisationUnit organisationUnit;
+
+    private ProgramStage stageA;
+
+    private ProgramStage stageB;
+
+    private DataElement dataElementA;
+
+    private DataElement dataElementB;
+
+    private ProgramStageDataElement stageDataElementA;
+
+    private ProgramStageDataElement stageDataElementB;
+
+    private ProgramStageDataElement stageDataElementC;
+
+    private ProgramStageDataElement stageDataElementD;
+
+    @Override
+    public void setUpTest()
+    {
+        organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        Program program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        stageA = new ProgramStage( "A", program );
+        stageA.setUid( "StageA" );
+        programStageService.saveProgramStage( stageA );
+
+        stageB = new ProgramStage( "B", program );
+        programStageService.saveProgramStage( stageB );
+
+        Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+        programStages.add( stageA );
+        programStages.add( stageB );
+        program.setProgramStages( programStages );
+        programService.updateProgram( program );
+
+        dataElementA = createDataElement( 'A' );
+        dataElementB = createDataElement( 'B' );
+
+        dataElementService.addDataElement( dataElementA );
+        dataElementService.addDataElement( dataElementB );
+
+        stageDataElementA = new ProgramStageDataElement( stageA, dataElementA, false, 1 );
+        stageDataElementB = new ProgramStageDataElement( stageA, dataElementB, false, 2 );
+        stageDataElementC = new ProgramStageDataElement( stageB, dataElementA, false, 1 );
+        stageDataElementD = new ProgramStageDataElement( stageB, dataElementB, false, 2 );
+    }
+
+    @Test
+    public void testAddProgramStageDataElement()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testUpdateProgramStageDataElement()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementA ) );
+
+        stageDataElementA.setCompulsory( true );
+        programStageDataElementStore.update( stageDataElementA );
+
+        assertEquals( true, programStageDataElementStore.get( stageA, dataElementA ).isCompulsory() );
+    }
+
+    @Test
+    public void testDeleteProgramStageDataElement()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementB ) );
+
+        programStageDataElementStore.delete( stageDataElementA );
+
+        assertNull( programStageDataElementStore.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementB ) );
+
+        programStageDataElementStore.delete( stageDataElementB );
+
+        assertNull( programStageDataElementStore.get( stageA, dataElementA ) );
+        assertNull( programStageDataElementStore.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testGetByStageElement()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementA ) );
+        assertNotNull( programStageDataElementStore.get( stageA, dataElementB ) );
+    }
+
+    @Test
+    public void testGetAllProgramStageDataElements()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+
+        assertTrue( equals( programStageDataElementStore.getAll(), stageDataElementA, stageDataElementB ) );
+    }
+
+    @Test
+    public void testGetByStage()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+        programStageDataElementStore.save( stageDataElementC );
+        programStageDataElementStore.save( stageDataElementD );
+
+        Collection<ProgramStageDataElement> stageDataElements = programStageDataElementStore.get( stageA );
+        assertTrue( equals( stageDataElements, stageDataElementA, stageDataElementB ) );
+
+        stageDataElements = programStageDataElementStore.get( stageB );
+        assertTrue( equals( stageDataElements, stageDataElementC, stageDataElementD ) );
+    }
+
+    @Test
+    public void testGetListDataElementByStage()
+    {
+        programStageDataElementStore.save( stageDataElementA );
+        programStageDataElementStore.save( stageDataElementB );
+        programStageDataElementStore.save( stageDataElementC );
+        programStageDataElementStore.save( stageDataElementD );
+
+        Collection<DataElement> stageDataElements = programStageDataElementStore.getListDataElement( stageA );
+        assertTrue( equals( stageDataElements, dataElementA, dataElementB ) );
+
+        stageDataElements = programStageDataElementStore.getListDataElement( stageB );
+        assertTrue( equals( stageDataElements, dataElementA, dataElementB ) );
+    }
+}
\ No newline at end of file