← Back to team overview

dhis2-devs team mailing list archive

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

 

------------------------------------------------------------
revno: 12982
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-11-20 11:12:25 +0700
message:
   Implement unit tests on ProgramStage service methods
added:
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageServiceTest.java
  dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageStoreTest.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/ProgramStageServiceTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageServiceTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageServiceTest.java	2013-11-20 04:12:25 +0000
@@ -0,0 +1,173 @@
+/*
+ * 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.HashSet;
+
+import org.hisp.dhis.DhisSpringTest;
+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 $ ProgramStageServiceTest.java Nov 14, 2013 4:22:27 PM $
+ */
+public class ProgramStageServiceTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private ProgramStageService programStageService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    private Program program;
+
+    private ProgramStage stageA;
+
+    private ProgramStage stageB;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        stageA = new ProgramStage( "A", program );
+        stageA.setUid( "UID-A" );
+
+        stageB = new ProgramStage( "B", program );
+        stageB.setUid( "UID-B" );
+    }
+
+    @Test
+    public void testSaveProgramStage()
+    {
+        int idA = programStageService.saveProgramStage( stageA );
+        int idB = programStageService.saveProgramStage( stageB );
+
+        assertNotNull( programStageService.getProgramStage( idA ) );
+        assertNotNull( programStageService.getProgramStage( idB ) );
+    }
+
+    @Test
+    public void testDeleteProgramStage()
+    {
+        int idA = programStageService.saveProgramStage( stageA );
+        int idB = programStageService.saveProgramStage( stageB );
+
+        assertNotNull( programStageService.getProgramStage( idA ) );
+        assertNotNull( programStageService.getProgramStage( idB ) );
+
+        programStageService.deleteProgramStage( stageA );
+
+        assertNull( programStageService.getProgramStage( idA ) );
+        assertNotNull( programStageService.getProgramStage( idB ) );
+
+        programStageService.deleteProgramStage( stageB );
+
+        assertNull( programStageService.getProgramStage( idA ) );
+        assertNull( programStageService.getProgramStage( idB ) );
+    }
+
+    @Test
+    public void testUpdateProgramStage()
+    {
+        int idA = programStageService.saveProgramStage( stageA );
+
+        assertNotNull( programStageService.getProgramStage( idA ) );
+
+        stageA.setName( "B" );
+        programStageService.updateProgramStage( stageA );
+
+        assertEquals( "B", programStageService.getProgramStage( idA ).getName() );
+    }
+
+    @Test
+    public void testGetProgramStageById()
+    {
+        int idA = programStageService.saveProgramStage( stageA );
+        int idB = programStageService.saveProgramStage( stageB );
+
+        assertEquals( stageA, programStageService.getProgramStage( idA ) );
+        assertEquals( stageB, programStageService.getProgramStage( idB ) );
+    }
+
+    @Test
+    public void testGetProgramStageByUid()
+    {
+        programStageService.saveProgramStage( stageA );
+        programStageService.saveProgramStage( stageB );
+
+        assertEquals( stageA, programStageService.getProgramStage( "UID-A" ) );
+        assertEquals( stageB, programStageService.getProgramStage( "UID-B" ) );
+    }
+
+    @Test
+    public void testGetProgramStageByName()
+    {
+        int idA = programStageService.saveProgramStage( stageA );
+
+        assertNotNull( programStageService.getProgramStage( idA ) );
+        assertNotNull( programStageService.getProgramStageByName( "A" ) );
+    }
+
+    @Test
+    public void testGetProgramStageByNameProgram()
+    {
+        programStageService.saveProgramStage( stageA );
+        programStageService.saveProgramStage( stageB );
+        
+        assertEquals( stageA, programStageService.getProgramStageByName( "A", program ) );
+        assertEquals( stageB, programStageService.getProgramStageByName( "B", program ) );
+    }
+
+    @Test
+    public void testGetAllProgramStages()
+    {
+        programStageService.saveProgramStage( stageA );
+        programStageService.saveProgramStage( stageB );
+
+        assertTrue( equals( programStageService.getAllProgramStages(), stageA, stageB ) );
+    }
+
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageStoreTest.java'
--- dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageStoreTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/test/java/org/hisp/dhis/program/ProgramStageStoreTest.java	2013-11-20 04:12:25 +0000
@@ -0,0 +1,98 @@
+/*
+ * 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 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.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Chau Thu Tran
+ * 
+ * @version $ ProgramStageStoreTest.java Nov 14, 2013 4:22:27 PM $
+ */
+public class ProgramStageStoreTest
+    extends DhisSpringTest
+{
+    @Autowired
+    private ProgramStageStore programStageStore;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
+    private Program program;
+
+    private ProgramStage stageA;
+
+    private ProgramStage stageB;
+
+    @Override
+    public void setUpTest()
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+
+        program = createProgram( 'A', new HashSet<ProgramStage>(), organisationUnit );
+        programService.addProgram( program );
+
+        stageA = new ProgramStage( "A", program );
+        stageA.setProgram( program );
+        stageA.setUid( "UID-A" );
+
+        stageB = new ProgramStage( "B", program );
+        stageA.setProgram( program );
+        stageB.setUid( "UID-B" );
+    }
+
+    @Test
+    public void testGetProgramStageByNameProgram()
+    {
+        programStageStore.save( stageA );
+        programStageStore.save( stageB );
+        
+        Set<ProgramStage> programStages = new HashSet<ProgramStage>();
+        programStages.add( stageA );
+        programStages.add( stageB );
+        program.setProgramStages( programStages );
+        programService.updateProgram( program );
+       
+        assertEquals( stageA, programStageStore.getByNameAndProgram( "A", program ) );
+        assertEquals( stageB, programStageStore.getByNameAndProgram( "B", program ) );
+    }
+
+}
\ No newline at end of file